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;
}