assertEquals(1 + 1, modulesManager2.getRefencingManagersInvolved(false).length);
assertEquals(2 + 1, modulesManager2.getRefencingManagersInvolved(true).length);
}
public void testLoad() throws Exception {
SystemModulesManager manager = new SystemModulesManager(null);
manager.addModule(new ModulesKey("bar", new File("bar.py")));
manager.addModule(new ModulesKey("foo", new File("foo.py")));
manager.addModule(new ModulesKey("empty", null));
manager.addModule(new ModulesKeyForZip("zip", new File("zip.zip"), "path", true));
PythonPathHelper pythonPathHelper = manager.getPythonPathHelper();
pythonPathHelper.setPythonPath("rara|boo");
assertEquals(Arrays.asList("rara", "boo"), manager.getPythonPathHelper().getPythonpath());
File f = new File("modules_manager_testing.temporary_dir");
try {
FileUtils.deleteDirectoryTree(f);
} catch (Exception e1) {
//ignore
}
try {
manager.saveToFile(f);
SystemModulesManager loaded = new SystemModulesManager(null);
SystemModulesManager.loadFromFile(loaded, f);
ModulesKey[] onlyDirectModules = loaded.getOnlyDirectModules();
boolean found = false;
for (ModulesKey modulesKey : onlyDirectModules) {
if (modulesKey.name.equals("zip")) {
ModulesKeyForZip z = (ModulesKeyForZip) modulesKey;
assertEquals(z.zipModulePath, "path");
assertEquals(z.file, new File("zip.zip"));
assertEquals(z.isFile, true);
found = true;
}
}
if (!found) {
fail("Did not find ModulesKeyForZip.");
}
Set<String> set = new HashSet<String>();
set.add("bar");
set.add("foo");
set.add("empty");
set.add("zip");
assertEquals(set, loaded.getAllModuleNames(true, ""));
assertEquals(Arrays.asList("rara", "boo"), loaded.getPythonPathHelper().getPythonpath());
} finally {
FileUtils.deleteDirectoryTree(f);
}
}