def test_remove(): pm = PackageManager(repo=Repository(), installer=Installer(), overwrite=False, console=Console(exit_on_error=False)) pkg = Package(name="test_package", version="1.0.0", type="SOURCE") filename = resource_filename(__name__, "data/test_package-1.0.0.zip") pm.upload(pkg, filename) pm.list_items() == [Package.repo_name(pkg, filename)] assert pm.remove(pkg, interactive=False) pm.list_items() == [] #expecting cache to be updated pm.list_items(from_cache=True) == [] #removing second time assert not pm.remove(pkg, interactive=False) #removing non existing assert not pm.remove(Package("some", "1.0.0"), interactive=False)
def handle_(config, data): with Console(verbose=config.get("verbose", False), exit_on_error=True) as c: repo = init_repository(c, config["repository"]) pkg_mgr = PackageManager(repo, console=c) for syntax in data["packages"]: pkg = pkg_mgr.search(syntax) ok = pkg is not None if ok: ok = pkg_mgr.remove(pkg, interactive=not data["non_interactive"]) if ok: c.badge("removed", "success")
def test_remove_with_repo_error(): repo = Repository() def problem(x): raise Exception() repo.delete = problem pm = PackageManager(repo=repo, installer=Installer(), overwrite=False, console=Console(exit_on_error=False)) pkg = Package(name="test_package", version="1.0.0", type="SOURCE") filename = resource_filename(__name__, "data/test_package-1.0.0.zip") pm.upload(pkg, filename) assert not pm.remove(pkg, interactive=False)