def test_config_hierarchy(self): """Testing Config: hierarchy""" c = Config() c["value"] = "lowlevel" c["plugin.one.value"] = "value" c["plugin.one.othervalue"] = "other" c["plugin.two"] = "second" assert c.get_childs("plugin") == {"one", "two"} assert c.get_childs("plugin.one") == {"value", "othervalue"} assert c.get("plugin.one.value") == "value" assert c.get("plugin.two.value") == "lowlevel"
def test_install_command_repo(self): with self.assertRaises(PackageError): self.test_install_command(False, "invalid://") self.plugin = TestInstallCommand._mock_str("none.none") self.plugin.endswith = lambda x: True self.install_global = False self.upgrade = True config = Config() config["plugin_dir"] = ["none"] import drove.package with temp.variables({ "drove.package.Package.from_repo": staticmethod(lambda *a, **kw: self) }): cmd = InstallCommand(config, self, getLogger()) assert cmd.__class__.__name__ == "InstallCommand" cmd.execute() _urlopen = package.urllib.request.urlopen package.urllib.request.urlopen = lambda *a, **kw: BytesIO( b(_test_result_msg) ) package.Package.from_url = staticmethod( lambda *a, **kw: package.Package( "none", "none", "12345678", "", "") ) self.test_install_command(False, "none")
def test_remove_command_error(self, plugin_name="author.plugin"): self.plugin = plugin_name self.install_global = False config = Config() config["plugin_dir"] = None with self.assertRaises(CommandError): RemoveCommand(config, self, getLogger()).execute()
def test_log_plugin(self): config = Config() channel = Channel() channel.subscribe("internal.log") channel.publish(Value("test", 0)) kls = log.LogPlugin(config, channel) kls.plugin_name = "internal.log" kls.write(channel)
def test_install_noplugindir(self): config = Config() self.plugin = "none" self.install_global = False self.upgrade = False with self.assertRaises(CommandError): cmd = InstallCommand(config, self, getLogger()) cmd.execute()
def test_list_command(self, config=None): if config is None: config = Config() config["plugin_dir"] = [ os.path.join(os.path.dirname(drove.__file__), "plugins") ] cmd = ListCommand(config, None, getLogger()) assert cmd.__class__.__name__ == "ListCommand" cmd.execute()
def test_install_filenotarball(self): config = Config() config["plugin_dir"] = os.path.dirname(__file__) self.plugin = __file__ self.install_global = False self.upgrade = False with self.assertRaises(CommandError): cmd = InstallCommand(config, self, getLogger()) cmd.execute()
def test_install_fromurl(self): self.plugin = "http://none" self.install_global = False self.upgrade = False config = Config() config["plugin_dir"] = ["none"] with temp.variables({ "drove.package.Package.from_url": staticmethod(lambda *a, **kw: self) }): cmd = InstallCommand(config, self, getLogger()) assert cmd.__class__.__name__ == "InstallCommand" cmd.execute()
def test_install_command(self, install_global=False, plugin=__file__): self.plugin = TestInstallCommand._mock_str(plugin) self.plugin.endswith = lambda x: True self.install_global = install_global self.upgrade = True config = Config() config["plugin_dir"] = ["none"] import drove.package with temp.variables({ "drove.package.Package.from_tarballfd": staticmethod(lambda *a, **kw: self) }): cmd = InstallCommand(config, self, getLogger()) assert cmd.__class__.__name__ == "InstallCommand" cmd.execute()
def test_remove_command(self, install_global=False, plugin=__file__): self.plugin = TestRemoveCommand._mock_str(plugin) self.plugin.endswith = lambda x: True self.install_global = install_global self.upgrade = True with temp.directory() as tmp_dir: config = Config() config["plugin_dir"] = [tmp_dir] with temp.variables({ "drove.command.remove.find_package": TestRemoveCommand._mock_find }): cmd = RemoveCommand(config, self, getLogger()) assert cmd.__class__.__name__ == "RemoveCommand" cmd.execute()
def test_config_notfound(self): """Testing Config: value not found""" c = Config() with self.assertRaises(ConfigError): c.get("notfound")
def test_config_default(self): """Testing Config: get with default""" c = Config() assert c.get("none", "value") == "value"
def test_config_include(self): """Testing Config: include""" c = Config(os.devnull) c["include"] = self.config_file c.reload() assert c.get("plugin_dir", False)
def test_list_command_missing_config(self): with self.assertRaises(CommandError): self.test_list_command(Config())