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_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_search(self, result=_test_result_msg): self.plugin = "none.none" config = Config() config["plugin_dir"] = ["none"] _urlopen = search.urllib.request.urlopen search.urllib.request.urlopen = lambda *a, **kw: BytesIO(b(result)) try: search.SearchCommand(config, self, getLogger()).execute() finally: search.urllib.request.urlopen = _urlopen
def test_search(self, result=_test_result_msg): self.plugin = "none.none" config = Config() config["plugin_dir"] = ["none"] _urlopen = search.urllib.request.urlopen search.urllib.request.urlopen = lambda *a, **kw: BytesIO( b(result) ) try: search.SearchCommand(config, self, getLogger()).execute() finally: search.urllib.request.urlopen = _urlopen
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_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_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_log_getlogger(self): """Testing Logger: getLogger()""" log = drove_log.getLogger() assert drove_log.getLogger() == log