Search in sources :

Example 1 with ProjectStub

use of org.python.pydev.shared_core.resource_stubs.ProjectStub in project Pydev by fabioz.

the class Flake8AnalysisTest method setUp.

@Override
protected void setUp() throws Exception {
    super.setUp();
    tempDir = FileUtils.getTempFileAt(new File("."), "data_flake8_analysis");
    tempDir.mkdirs();
    ProjectStub project = new ProjectStub(tempDir, new PythonNature());
    file = new FileStub(project, new File("snippet.py"));
}
Also used : ProjectStub(org.python.pydev.shared_core.resource_stubs.ProjectStub) PythonNature(org.python.pydev.plugin.nature.PythonNature) FileStub(org.python.pydev.shared_core.resource_stubs.FileStub) File(java.io.File)

Example 2 with ProjectStub

use of org.python.pydev.shared_core.resource_stubs.ProjectStub in project Pydev by fabioz.

the class ScopedPreferencesTest method testProjectSettingsScopedPreferences.

public void testProjectSettingsScopedPreferences() throws Exception {
    IScopedPreferences iScopedPreferences = ScopedPreferences.get("my.test2");
    File eclipsePrefs = new File(baseDir, ".eclipse");
    File projectDir = new File(baseDir, "project");
    File projectDirSettings = new File(projectDir, ".settings");
    File projectDirYAMLFile = new File(projectDirSettings, "my.test2.yaml");
    eclipsePrefs.mkdirs();
    projectDir.mkdirs();
    projectDirSettings.mkdirs();
    FileUtils.writeStrToFile("", projectDirYAMLFile);
    assertTrue(eclipsePrefs.exists());
    File userSettingsYamlFile = new File(eclipsePrefs, "my.test2.yaml");
    assertTrue(!userSettingsYamlFile.exists());
    final IProject project = new ProjectStub(projectDir, null);
    Map<String, Object> saveData = new HashMap<String, Object>();
    saveData.put("foo", 1);
    iScopedPreferences.saveToProjectSettings(saveData, project);
    assertTrue(!userSettingsYamlFile.exists());
    assertEquals("foo: 1\n", FileUtils.getFileContents(projectDirYAMLFile));
    IAdaptable adaptable = new IAdaptable() {

        @Override
        public <T> T getAdapter(Class<T> adapter) {
            if (IProject.class == adapter) {
                return (T) project;
            }
            return null;
        }
    };
    IEclipsePreferences pluginPreferenceStore = new InMemoryEclipsePreferences();
    IEclipsePreferences defaultPreferenceStore = new InMemoryEclipsePreferences();
    assertEquals(1, iScopedPreferences.getInt(pluginPreferenceStore, defaultPreferenceStore, "foo", adaptable));
    saveData = new HashMap<String, Object>();
    saveData.put("bar", 2);
    waitABit();
    iScopedPreferences.saveToProjectSettings(saveData, project);
    waitABit();
    assertEquals("bar: 2\nfoo: 1\n", FileUtils.getFileContents(projectDirYAMLFile));
    assertEquals(2, iScopedPreferences.getInt(pluginPreferenceStore, defaultPreferenceStore, "bar", adaptable));
    FileUtils.writeStrToFile("bar: 1\nfoo: 1\n", projectDirYAMLFile);
    assertEquals(1, iScopedPreferences.getInt(pluginPreferenceStore, defaultPreferenceStore, "bar", adaptable));
    waitABit();
    FileUtils.writeStrToFile("foo: 1\n", projectDirYAMLFile);
    waitABit();
    // default in NullPrefsStore
    assertEquals(0, iScopedPreferences.getInt(pluginPreferenceStore, defaultPreferenceStore, "bar", adaptable));
    pluginPreferenceStore.putInt("bar", 2);
    // default in NullPrefsStore
    assertEquals(2, iScopedPreferences.getInt(pluginPreferenceStore, defaultPreferenceStore, "bar", adaptable));
}
Also used : IAdaptable(org.eclipse.core.runtime.IAdaptable) ProjectStub(org.python.pydev.shared_core.resource_stubs.ProjectStub) HashMap(java.util.HashMap) IEclipsePreferences(org.eclipse.core.runtime.preferences.IEclipsePreferences) IProject(org.eclipse.core.resources.IProject) File(java.io.File)

Example 3 with ProjectStub

use of org.python.pydev.shared_core.resource_stubs.ProjectStub in project Pydev by fabioz.

the class MypyAnalysisTest method setUp.

@Override
protected void setUp() throws Exception {
    super.setUp();
    tempDir = FileUtils.getTempFileAt(new File("."), "data_mypy_analysis");
    tempDir.mkdirs();
    ProjectStub project = new ProjectStub(tempDir, null);
    file = new FileStub(project, new File(tempDir, "snippet.py"));
}
Also used : ProjectStub(org.python.pydev.shared_core.resource_stubs.ProjectStub) FileStub(org.python.pydev.shared_core.resource_stubs.FileStub) File(java.io.File)

Example 4 with ProjectStub

use of org.python.pydev.shared_core.resource_stubs.ProjectStub in project Pydev by fabioz.

the class PyLintAnalysisTest method testMarkersInfoOutput.

/**
 * Verify markers are created with correct line number and text
 *  when supplied simulated PyLint input and output.
 *
 * @throws UnableToFindExecutableException
 * @throws MisconfigurationException
 * @throws PythonNatureWithoutProjectException
 */
public void testMarkersInfoOutput() throws UnableToFindExecutableException, MisconfigurationException, PythonNatureWithoutProjectException {
    ProjectStub project = new ProjectStub(tempDir, null);
    FileStub file = new FileStub(project, new File(tempDir, "file.py"));
    IDocument document = new Document("" + "import string\n" + "\n" + "shift = 3\n" + "choice = input(\"would you like to encode or decode?\")\n" + "word = input(\"Please enter text\")\n" + "letters = string.ascii_letters + string.punctuation + string.digits\n" + "encoded = ''\n" + "if choice == \"encode\":\n" + "    for letter in word:\n" + "        if letter == ' ':\n" + "            encoded = encoded + ' '\n" + "        else:\n" + "            x = letters.index(letter) + shift\n" + "            encoded=encoded + letters[x]\n" + "if choice == \"decode\":\n" + "    for letter in word:\n" + "        if letter == ' ':\n" + "            encoded = encoded + ' '\n" + "        else:\n" + "            x = letters.index(letter) - shift\n" + "            encoded = encoded + letters[x]\n" + "print(encoded)\n" + "print(\"This line is really long\")" + " # This comment is part of the long line, going over the 100 char limit");
    PyLintAnalysis pyLintAnalysis = new PyLintAnalysis(file, document, null, new NullProgressMonitor(), null);
    String output = "PyLint: The stdout of the command line is:\n" + " ************* Module snippet\n" + "C: 14,19: (bad-whitespace) Exactly one space required around assignment\n" + "            encoded=encoded + letters[x]\n" + "\n" + "                   ^\n" + "C: 17,25: (trailing-whitespace) Trailing whitespace\n" + "W: 22, 0: (unnecessary-semicolon) Unnecessary semicolon\n" + "C: 23, 0: (line-too-long) Line too long (106/100)\n" + "C: 23, 0: (missing-final-newline) Final newline missing\n" + "C:  1, 0: (missing-module-docstring) Missing module docstring\n" + "C:  3, 0: (invalid-name) Constant name \"shift\" doesn't conform to UPPER_CASE naming style\n" + "C:  7, 0: (invalid-name) Constant name \"encoded\" doesn't conform to UPPER_CASE naming style\n" + "C: 11,12: (invalid-name) Constant name \"encoded\" doesn't conform to UPPER_CASE naming style\n" + "\n" + "------------------------------------------------------------------\n" + "\n" + "Your code has been rated at 5.50/10 (previous run: 5.26/10, +0.00)\n";
    PydevPrefs.getEclipsePreferences().putInt(PyLintPreferences.SEVERITY_WARNINGS, IMarker.SEVERITY_ERROR);
    PydevPrefs.getEclipsePreferences().putInt(PyLintPreferences.SEVERITY_CODING_STANDARD, IMarker.SEVERITY_ERROR);
    PydevPrefs.getEclipsePreferences().putInt(PyLintPreferences.SEVERITY_REFACTOR, IMarker.SEVERITY_ERROR);
    pyLintAnalysis.afterRunProcess(output, "No config file found, using default configuration\n", null);
    List<MarkerInfo> markers = pyLintAnalysis.getMarkers(file);
    for (MarkerInfo marker : markers) {
        assertEquals(marker.lineStart, marker.lineEnd);
    }
    assertEquals(9, markers.size());
    assertMarkerEquals(0, 13, "bad-whitespace", "Exactly one space required around assignment", markers);
    assertMarkerEquals(1, 16, "trailing-whitespace", "Trailing whitespace", markers);
    assertMarkerEquals(2, 21, "unnecessary-semicolon", "Unnecessary semicolon", markers);
    assertMarkerEquals(3, 22, "line-too-long", "Line too long (106/100)", markers);
    assertMarkerEquals(4, 22, "missing-final-newline", "Final newline missing", markers);
    assertMarkerEquals(5, 0, "missing-module-docstring", "Missing module docstring", markers);
    assertMarkerEquals(6, 2, "invalid-name", "Constant name \"shift\" doesn't conform to UPPER_CASE naming style", markers);
    assertMarkerEquals(7, 6, "invalid-name", "Constant name \"encoded\" doesn't conform to UPPER_CASE naming style", markers);
    assertMarkerEquals(8, 10, "invalid-name", "Constant name \"encoded\" doesn't conform to UPPER_CASE naming style", markers);
}
Also used : MarkerInfo(org.python.pydev.shared_core.markers.PyMarkerUtils.MarkerInfo) NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) ProjectStub(org.python.pydev.shared_core.resource_stubs.ProjectStub) FileStub(org.python.pydev.shared_core.resource_stubs.FileStub) Document(org.eclipse.jface.text.Document) IDocument(org.eclipse.jface.text.IDocument) File(java.io.File) IDocument(org.eclipse.jface.text.IDocument)

Example 5 with ProjectStub

use of org.python.pydev.shared_core.resource_stubs.ProjectStub in project Pydev by fabioz.

the class PyRenameResourceChangeTest method testRenameResource.

public void testRenameResource() throws Exception {
    ProjectStub project = new ProjectStub(tempDir, new PythonNatureStub());
    File dirFile = new File(tempDir, "dir");
    dirFile.mkdirs();
    File file = new File(dirFile, "file.py");
    file.createNewFile();
    FolderStub folderStub = new FolderStub(project, dirFile);
    FileStub fileStub = new FileStub(project, file);
    String tempName = tempDir.getName();
    IContainer container;
    container = PyRenameResourceChange.getDestination(fileStub, "dir.file", "foo.bar.now", null);
    assertEquals(new Path(tempName + "/foo/bar"), container.getFullPath());
    container = PyRenameResourceChange.getDestination(fileStub, "dir.file", "foo", null);
    assertEquals(new Path(tempName), container.getFullPath());
    container = PyRenameResourceChange.getDestination(fileStub, "dir.file", "my.foo", null);
    assertEquals(new Path(tempName + "/my"), container.getFullPath());
    container = PyRenameResourceChange.getDestination(fileStub, "dir.file", "dir.foo", null);
    assertEquals(new Path(tempName + "/dir"), container.getFullPath());
    container = PyRenameResourceChange.getDestination(fileStub, "dir.file", "dir", null);
    assertEquals(new Path(tempName + ""), container.getFullPath());
    container = PyRenameResourceChange.getDestination(fileStub, "dir.file", "dir.file.now", null);
    assertEquals(new Path(tempName + "/dir/file"), container.getFullPath());
}
Also used : Path(org.eclipse.core.runtime.Path) ProjectStub(org.python.pydev.shared_core.resource_stubs.ProjectStub) FileStub(org.python.pydev.shared_core.resource_stubs.FileStub) FolderStub(org.python.pydev.shared_core.resource_stubs.FolderStub) IContainer(org.eclipse.core.resources.IContainer) File(java.io.File) PythonNatureStub(org.python.pydev.parser.PythonNatureStub)

Aggregations

File (java.io.File)5 ProjectStub (org.python.pydev.shared_core.resource_stubs.ProjectStub)5 FileStub (org.python.pydev.shared_core.resource_stubs.FileStub)4 HashMap (java.util.HashMap)1 IContainer (org.eclipse.core.resources.IContainer)1 IProject (org.eclipse.core.resources.IProject)1 IAdaptable (org.eclipse.core.runtime.IAdaptable)1 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)1 Path (org.eclipse.core.runtime.Path)1 IEclipsePreferences (org.eclipse.core.runtime.preferences.IEclipsePreferences)1 Document (org.eclipse.jface.text.Document)1 IDocument (org.eclipse.jface.text.IDocument)1 PythonNatureStub (org.python.pydev.parser.PythonNatureStub)1 PythonNature (org.python.pydev.plugin.nature.PythonNature)1 MarkerInfo (org.python.pydev.shared_core.markers.PyMarkerUtils.MarkerInfo)1 FolderStub (org.python.pydev.shared_core.resource_stubs.FolderStub)1