use of org.python.pydev.plugin.nature.PythonNature in project Pydev by fabioz.
the class PythonModelProviderTest method testAddSourceFolderToSourceFolder.
public void testAddSourceFolderToSourceFolder() throws Exception {
final HashSet<String> pythonPathSet = new HashSet<String>();
pythonPathSet.add(TestDependent.TEST_PYSRC_NAVIGATOR_LOC + "projroot/source");
String source2Folder = TestDependent.TEST_PYSRC_NAVIGATOR_LOC + "projroot/source2";
File f = new File(source2Folder);
if (f.exists()) {
f.delete();
}
// still not created!
pythonPathSet.add(source2Folder);
PythonNature nature = createNature(pythonPathSet);
project = new ProjectStub(new File(TestDependent.TEST_PYSRC_NAVIGATOR_LOC + "projroot"), nature, false);
provider = new PythonModelProvider();
Object[] children1 = provider.getChildren(project);
assertEquals(1, children1.length);
assertTrue(children1[0] instanceof PythonSourceFolder);
Set set = new HashSet();
f.mkdir();
try {
FolderStub source2FolderFile = new FolderStub(project, f);
set.add(source2FolderFile);
provider.interceptAdd(new PipelinedShapeModification(project, set));
assertEquals(1, set.size());
assertTrue(set.iterator().next() instanceof PythonSourceFolder);
} finally {
f.delete();
}
}
use of org.python.pydev.plugin.nature.PythonNature in project Pydev by fabioz.
the class PythonModelProviderTest method testNullElements.
public void testNullElements() throws Exception {
final HashSet<String> pythonPathSet = new HashSet<String>();
// root is the source
pythonPathSet.add(TestDependent.TEST_PYSRC_NAVIGATOR_LOC + "projroot");
PythonNature nature = createNature(pythonPathSet);
WorkspaceRootStub workspaceRootStub = new WorkspaceRootStub();
project = new ProjectStub(new File(TestDependent.TEST_PYSRC_NAVIGATOR_LOC + "projroot"), nature);
workspaceRootStub.addChild(project);
project.setParent(workspaceRootStub);
provider = new PythonModelProvider();
HashSet<Object> currentChildren = new HashSet<Object>();
currentChildren.add(project);
currentChildren.add(null);
provider.getPipelinedChildren(workspaceRootStub, currentChildren);
assertEquals(1, currentChildren.size());
PythonProjectSourceFolder projectSourceFolder = (PythonProjectSourceFolder) currentChildren.iterator().next();
currentChildren = new HashSet<Object>();
currentChildren.add(null);
currentChildren.add(null);
provider.getPipelinedChildren(projectSourceFolder, currentChildren);
assertEquals(1, currentChildren.size());
}
use of org.python.pydev.plugin.nature.PythonNature in project Pydev by fabioz.
the class PythonModelProviderTest method testProjectIsRoot.
/**
* Test if setting the project root as a source folder will return an object from the python model.
*/
public void testProjectIsRoot() throws Exception {
String pythonpathLoc = TestDependent.TEST_PYSRC_NAVIGATOR_LOC + "projroot";
final HashSet<String> pythonPathSet = new HashSet<String>();
pythonPathSet.add(pythonpathLoc);
PythonNature nature = createNature(pythonPathSet);
WorkspaceRootStub workspaceRootStub = new WorkspaceRootStub();
project = new ProjectStub(new File(pythonpathLoc), nature);
provider = new PythonModelProvider();
workspaceRootStub.addChild(project);
workspaceRootStub.addChild(null);
workspaceRootStub.addChild("other");
project.setParent(workspaceRootStub);
Object[] children1 = provider.getChildren(workspaceRootStub);
assertEquals(2, children1.length);
int stringsFound = 0;
int projectSourceFoldersFound = 0;
for (Object c : children1) {
if (c instanceof String) {
stringsFound += 1;
} else if (c instanceof PythonProjectSourceFolder) {
projectSourceFoldersFound += 1;
} else {
fail("Expecting source folder or string. Received: " + c.getClass().getName());
}
}
assertEquals(1, stringsFound);
assertEquals(1, projectSourceFoldersFound);
// now, let's go and change the pythonpath location to a folder within the project and see if it changes...
pythonPathSet.clear();
pythonPathSet.add(TestDependent.TEST_PYSRC_NAVIGATOR_LOC + "projroot/source/python");
IResource refreshObject = provider.internalDoNotifyPythonPathRebuilt(project, new ArrayList<String>(pythonPathSet));
assertTrue("Expecting the refresh object to be the root and not the project", refreshObject instanceof IWorkspaceRoot);
children1 = provider.getChildren(workspaceRootStub);
assertEquals(2, children1.length);
stringsFound = 0;
int projectsFound = 0;
for (Object c : children1) {
if (c instanceof String) {
stringsFound += 1;
} else if (c instanceof IProject) {
projectsFound += 1;
} else {
fail("Expecting source folder or string. Received: " + c.getClass().getName());
}
}
assertEquals(1, stringsFound);
assertEquals(1, projectsFound);
// set to be the root again
pythonPathSet.clear();
pythonPathSet.add(TestDependent.TEST_PYSRC_NAVIGATOR_LOC + "projroot");
refreshObject = provider.internalDoNotifyPythonPathRebuilt(project, new ArrayList<String>(pythonPathSet));
assertTrue("Expecting the refresh object to be the root and not the project", refreshObject instanceof IWorkspaceRoot);
}
use of org.python.pydev.plugin.nature.PythonNature in project Pydev by fabioz.
the class PythonModelProviderTest method createNature.
/**
* Creates a nature that has the given set as its underlying pythonpath paths. The reference
* is kept inside as a reference, so, changing that reference will affect the pythonpath
* that is set in the nature.
*/
private PythonNature createNature(final HashSet<String> pythonPathSet) {
PythonNature nature = new PythonNature() {
@Override
public IPythonPathNature getPythonPathNature() {
HashSet<String> hashSet = new HashSet<>();
IPath base = Path.fromOSString(TestDependent.TEST_PYSRC_NAVIGATOR_LOC);
for (String s : pythonPathSet) {
if (s.equals("invalid")) {
hashSet.add(s);
} else {
IPath p = Path.fromOSString(s);
Assert.isTrue(FileUtils.isPrefixOf(base, p), "Expected: " + base + " to be prefix of: " + p);
hashSet.add(p.makeRelativeTo(base).toString());
}
}
return new PythonPathNatureStub(hashSet);
}
};
return nature;
}
use of org.python.pydev.plugin.nature.PythonNature in project Pydev by fabioz.
the class PythonModelProviderTest method testInterceptAdd.
/**
* Test if intercepting an add deep within the pythonpath structure will correctly return an object
* from the python model.
*/
public void testInterceptAdd() throws Exception {
PythonNature nature = createNature(TestDependent.TEST_PYSRC_NAVIGATOR_LOC + "projroot/source/python");
project = new ProjectStub(new File(TestDependent.TEST_PYSRC_NAVIGATOR_LOC + "projroot"), nature);
file = new FileStub(project, new File(TestDependent.TEST_PYSRC_NAVIGATOR_LOC + "projroot/source/python/pack1/pack2/mod2.py"));
provider = new PythonModelProvider();
HashSet<Object> files = new HashSet<Object>();
files.add(file);
files.add(null);
files.add("string");
provider.interceptAdd(new PipelinedShapeModification(file.getParent(), files));
assertEquals(2, files.size());
for (Object wrappedResource : files) {
assertTrue((wrappedResource instanceof IWrappedResource && ((IWrappedResource) wrappedResource).getActualObject() == file) || wrappedResource.equals("string"));
}
}
Aggregations