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"));
}
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));
}
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"));
}
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);
}
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());
}
Aggregations