def test_has_package(self): packages = [self.numpy_1_6_1, self.numpy_1_7_0, self.scipy_0_11_0] repo = Repository(packages=packages) self.assertTrue(repo.has_package(self.numpy_1_6_1)) self.assertTrue(repo.has_package_name("numpy")) self.assertFalse(repo.has_package_name("floupi"))
def test_has_package(self): packages = [numpy_1_6_1, numpy_1_7_0, scipy_0_11_0] repo = Repository(packages) self.assertTrue(repo.has_package(numpy_1_6_1)) self.assertTrue(repo.has_package_name("numpy")) self.assertFalse(repo.has_package_name("floupi") is None)
def test_find_package(self): packages = [self.numpy_1_6_1, self.numpy_1_7_0, self.scipy_0_11_0] repo = Repository(packages=packages) self.assertTrue(repo.find_package("numpy", V("1.6.1"))) self.assertTrue(repo.find_package("numpy", V("1.7.0"))) self.assertTrue(repo.find_package("numpy", V("1.7.1")) is None)
def test_cmp_by_priority_prefer_installed_multi_repositories(self): """ Check packages from multiple repositories are sorted accordingt to repository priority. """ numpy_1_6_0 = P("numpy-1.6.0") numpy_1_6_1 = P("numpy-1.6.1") numpy_1_7_0 = P("numpy-1.7.0") i_numpy_1_6_0 = P("numpy-1.6.0") remote_repository = Repository([numpy_1_7_0, numpy_1_6_1, numpy_1_6_0], "remote") installed_repository = Repository([i_numpy_1_6_0], "installed") r_sorted_packages = [ i_numpy_1_6_0, numpy_1_7_0, numpy_1_6_1, numpy_1_6_0 ] pool = Pool([installed_repository, remote_repository]) pool.set_repository_order("installed", "remote") policy = DefaultPolicy() queue = [numpy_1_7_0, i_numpy_1_6_0, numpy_1_6_0, numpy_1_6_1] def _cmp(a, b): return policy.cmp_by_priority_prefer_installed(pool, {}, a, b) self.assertEqual(r_sorted_packages, sorted_with_cmp(queue, cmp=_cmp))
def test_simple_construction(self): repo = Repository() self.assertEqual(repo.list_packages(), []) r_packages = [self.numpy_1_6_1, self.numpy_1_7_0, self.scipy_0_11_0] repo = Repository(packages=r_packages) packages = set(repo.iter_packages()) self.assertEqual(packages, set(r_packages))
def test_add_package(self): packages = [numpy_1_6_1, numpy_1_7_0, scipy_0_11_0] repo = Repository() for package in packages: repo.add_package(package) self.assertTrue(repo.has_package(numpy_1_6_1)) self.assertTrue(repo.has_package_name("numpy"))
def test_add_repository(self): """Ensures we do not add the same package twice.""" repo1 = Repository([self.mkl_10_1_0, self.mkl_10_2_0]) pool = Pool() pool.add_repository(repo1) repo2 = Repository([P(str(self.mkl_10_1_0))]) pool.add_repository(repo2) self.assertEqual(len(pool.what_provides(R("mkl"))), 3)
def test_no_install(self): """Ensure the most up-to-date version is installed when directly installed.""" repo = Repository([mkl_10_1_0, mkl_10_2_0, mkl_10_3_0, mkl_11_0_0]) pool = Pool() pool.add_repository(repo) installed_repo = Repository() operations = solve(pool, R("mkl"), installed_repo, policy) self.assertEqual(operations, [Install(mkl_11_0_0)])
def test_simple_provided(self): r_operations = [Install(nomkl_numpy_1_7_0), Install(scipy_0_11_0)] repo = Repository([mkl_11_0_0, scipy_0_11_0, nomkl_numpy_1_7_0]) pool = Pool() pool.add_repository(repo) installed_repo = Repository() operations = solve(pool, R("scipy"), installed_repo, policy) self.assertEqual(operations, r_operations)
def test_simple(self): """Numpy depends on MKL, one version of NumPy only.""" repo = Repository([mkl_10_2_0, mkl_10_3_0, mkl_11_0_0, numpy_1_6_0]) pool = Pool() pool.add_repository(repo) installed_repo = Repository() operations = solve(pool, R("numpy"), installed_repo, policy) self.assertEqual(operations, [Install(mkl_11_0_0), Install(numpy_1_6_0)])
def test_dependency_already_provided_but_older(self): """Numpy depends on MKL, older MKL already installed.""" repo = Repository([mkl_10_2_0, mkl_10_3_0, mkl_11_0_0, numpy_1_6_0, numpy_1_7_0]) pool = Pool() pool.add_repository(repo) installed_repo = Repository([mkl_10_3_0]) operations = solve(pool, R("numpy"), installed_repo, policy) self.assertEqual(operations, [Install(numpy_1_7_0)])
def test_simple2(self): """Numpy depends on MKL, ensure we install the most up-to-date version.""" repo = Repository([mkl_10_2_0, mkl_10_3_0, mkl_11_0_0, numpy_1_6_0, numpy_1_7_0]) pool = Pool() pool.add_repository(repo) installed_repo = Repository() operations = solve(pool, R("numpy"), installed_repo, policy) self.assertEqual(operations, [Install(mkl_11_0_0), Install(numpy_1_7_0)])
def test_already_installed_but_not_satisfied(self): """Ensure we update to the most recent version when the requirement is not already satisfied.""" repo = Repository([mkl_10_1_0, mkl_10_2_0, mkl_10_3_0, mkl_11_0_0]) pool = Pool() pool.add_repository(repo) installed_repo = Repository() installed_repo.add_package(mkl_10_2_0) operations = solve(pool, R("mkl >= 10.3.0"), installed_repo, policy) self.assertEqual(operations, [Update(mkl_10_2_0, mkl_11_0_0)])
def test_already_satisfied(self): """Ensure we don't install a more recent version when the requirement is already satisfied.""" repo = Repository([mkl_10_1_0, mkl_10_2_0, mkl_10_3_0, mkl_11_0_0]) pool = Pool() pool.add_repository(repo) installed_repo = Repository() installed_repo.add_package(mkl_10_2_0) operations = solve(pool, R("mkl"), installed_repo, policy) self.assertEqual(operations, [])
def test_what_provides_simple(self): repo1 = Repository([numpy_1_6_0, numpy_1_7_0]) pool = Pool() pool.add_repository(repo1) self.assertEqual(set(pool.what_provides(R("numpy"))), set([numpy_1_6_0, numpy_1_7_0])) self.assertEqual(pool.what_provides(R("numpy >= 1.6.1")), [numpy_1_7_0]) repo1 = Repository([nomkl_numpy_1_7_0]) pool = Pool() pool.add_repository(repo1) self.assertEqual(pool.what_provides(R("numpy")), [nomkl_numpy_1_7_0])
def from_data(cls, remote_packages, installed_packages, request_jobs): remote_repository = Repository( packages=[P(p.package_string) for p in remote_packages]) installed_repository = Repository( packages=[P(p.package_string) for p in installed_packages]) pool = Pool([remote_repository, installed_repository]) request = Request(pool) for name, requirement_string in request_jobs: getattr(request, name)(R(requirement_string)) return cls(remote_repository=remote_repository, installed_repository=installed_repository, pool=pool, request=request)
def test_from_packages_simple(self): mkl = P("mkl-10.1.0") numpy = P("numpy-1.7.0; depends (MKL >= 10.1.0)") scipy = P("scipy-0.12.0; depends (numpy >= 1.7.0)") remote_repository = [mkl, numpy, scipy] i_mkl = P("mkl-10.1.0") installed_repository = [i_mkl] pool = Pool([Repository(remote_repository), Repository(installed_repository)]) rule = PackageRule.from_packages(pool, [mkl, i_mkl], "job_install", "numpy") self.assertEqual(rule.enabled, True) self.assertEqual(rule.literals, [mkl.id, i_mkl.id]) self.assertEqual(rule.reason, "job_install")
def test_priority_simple(self): paid_repo = Repository([ self.mkl_10_1_0, self.mkl_10_2_0, self.mkl_10_3_0, self.mkl_11_0_0, self.numpy_1_6_0, self.numpy_1_7_0, ], name="paid") free_repo = Repository([self.nomkl_numpy_1_7_0], "free") pool = Pool([paid_repo, free_repo]) pool.set_repository_order("free", before="paid") self.assertEqual(pool.repository_priority(paid_repo), 0) self.assertEqual(pool.repository_priority(free_repo), -1)
def test_what_provides_direct_only(self): repo1 = Repository([self.nomkl_numpy_1_7_0]) pool = Pool() pool.add_repository(repo1) self.assertEqual(set(pool.what_provides(R("numpy"))), set([self.nomkl_numpy_1_7_0]))
def test_simple(self): r_operations = [Install(mkl_11_0_0), Install(numpy_1_7_0), Install(scipy_0_12_0)] repo = Repository([mkl_10_3_0, mkl_11_0_0, numpy_1_6_0, numpy_1_6_1, numpy_1_7_0, scipy_0_12_0]) pool = Pool() pool.add_repository(repo) installed_repo = Repository() req = R("scipy") operations = solve(pool, req, installed_repo, policy) self.assertEqual(operations, r_operations)
def test_multiple_provided_names_single_install_provide(self): # Installed requirement has 1 one provide, but multiple provides for # the same name are available in the pool repo = Repository([ mkl_10_1_0, mkl_10_2_0, mkl_10_3_0, mkl_11_0_0, numpy_1_6_1, numpy_1_7_0 ]) pool = Pool() pool.add_repository(repo) r_rules = set() r_rules.add(PackageRule.from_string("numpy-1.7.0", pool)) r_rules.add( PackageRule.from_string("-numpy-1.7.0 | -numpy-1.6.1", pool)) r_rules.add( PackageRule.from_string( "-numpy-1.7.0 | mkl-10.1.0 | mkl-10.2.0 | mkl-10.3.0 | mkl-11.0.0", pool)) r_rules.add(PackageRule.from_string("-mkl-10.1.0 | -mkl-10.2.0", pool)) r_rules.add(PackageRule.from_string("-mkl-10.1.0 | -mkl-10.3.0", pool)) r_rules.add(PackageRule.from_string("-mkl-10.1.0 | -mkl-11.0.0", pool)) r_rules.add(PackageRule.from_string("-mkl-10.2.0 | -mkl-10.3.0", pool)) r_rules.add(PackageRule.from_string("-mkl-10.2.0 | -mkl-11.0.0", pool)) r_rules.add(PackageRule.from_string("-mkl-10.3.0 | -mkl-11.0.0", pool)) self.assertEqual(r_rules, set(create_install_rules(pool, R("numpy == 1.7.0"))))
def setUp(self): repo = Repository( [mkl_10_1_0, mkl_10_2_0, mkl_10_3_0, mkl_11_0_0, numpy_1_6_0]) pool = Pool() pool.add_repository(repo) self.pool = pool
def setUp(self): self.mkl_10_1_0 = P("mkl-10.1.0") self.mkl_10_2_0 = P("mkl-10.2.0") self.mkl_10_3_0 = P("mkl-10.3.0") self.mkl_11_0_0 = P("mkl-11.0.0") self.numpy_1_6_0 = P("numpy-1.6.0; depends (mkl)") self.numpy_1_6_1 = P("numpy-1.6.1; depends (mkl)") self.numpy_1_7_0 = P("numpy-1.7.0; depends (mkl)") self.nomkl_numpy_1_6_0 = P( "nomkl_numpy-1.6.0; provides(numpy == 1.6.0)") self.nomkl_numpy_1_6_1 = P( "nomkl_numpy-1.6.1; provides(numpy == 1.6.1)") self.nomkl_numpy_1_7_0 = P( "nomkl_numpy-1.7.0; provides(numpy == 1.7.0)") self.mkl_numpy_1_6_1 = P( "mkl_numpy-1.6.1; provides(numpy == 1.6.1); depends (mkl)") self.mkl_numpy_1_7_0 = P( "mkl_numpy-1.7.0; provides(numpy == 1.7.0); depends (mkl)") self.scipy_0_11_0 = P("scipy-0.11.0; depends (numpy >= 1.4.0)") self.scipy_0_12_0 = P("scipy-0.12.0; depends (numpy >= 1.4.0)") self.matplotlib_1_2_0 = P("matplotlib-1.2.0; depends (numpy >= 1.6.0)") repo = Repository([ self.mkl_10_1_0, self.mkl_10_2_0, self.mkl_10_3_0, self.mkl_11_0_0, self.numpy_1_6_0 ]) pool = Pool() pool.add_repository(repo) self.pool = pool
def test_multiple_install_provides(self): # Installed requirement has > 1 one provide repo = Repository([ mkl_10_1_0, mkl_10_2_0, mkl_10_3_0, mkl_11_0_0, numpy_1_6_1, numpy_1_7_0 ]) pool = Pool() pool.add_repository(repo) r_rules = set() r_rules.add(PackageRule.from_string("numpy-1.7.0 | numpy-1.6.1", pool)) r_rules.add( PackageRule.from_string("-numpy-1.7.0 | -numpy-1.6.1", pool)) r_rules.add( PackageRule.from_string( "-numpy-1.7.0 | mkl-10.1.0 | mkl-10.2.0 | mkl-10.3.0 | mkl-11.0.0", pool)) r_rules.add( PackageRule.from_string( "-numpy-1.6.1 | mkl-10.1.0 | mkl-10.2.0 | mkl-10.3.0 | mkl-11.0.0", pool)) r_rules.add(PackageRule.from_string("-mkl-10.1.0 | -mkl-10.2.0", pool)) r_rules.add(PackageRule.from_string("-mkl-10.1.0 | -mkl-10.3.0", pool)) r_rules.add(PackageRule.from_string("-mkl-10.1.0 | -mkl-11.0.0", pool)) r_rules.add(PackageRule.from_string("-mkl-10.2.0 | -mkl-10.3.0", pool)) r_rules.add(PackageRule.from_string("-mkl-10.2.0 | -mkl-11.0.0", pool)) r_rules.add(PackageRule.from_string("-mkl-10.3.0 | -mkl-11.0.0", pool)) self.assertEqual(r_rules, set(create_install_rules(pool, R("numpy"))))
def test_set_repository(self): package = PackageInfo(name="numpy", version=V("1.3.0")) package.repository = Repository() def set_repository(): package.repository = Repository() self.assertRaises(ValueError, set_repository)
def test_what_provides_replaces(self): scikit_learn = P("scikit_learn-0.12.0") sklearn = P("sklearn-0.13.0; replaces (scikit_learn==0.12.0)") pool = Pool([Repository([scikit_learn, sklearn])]) self.assertEqual(set(pool.what_provides(R("sklearn"))), set([sklearn])) self.assertEqual(set(pool.what_provides(R("scikit_learn"))), set([sklearn, scikit_learn]))
def test_simple2(self): repo = Repository([mkl_10_1_0, mkl_10_2_0]) pool = Pool([repo]) self.assertEqual(mkl_10_1_0, pool.package_by_id(mkl_10_1_0.id)) self.assertEqual(mkl_10_2_0, pool.package_by_id(mkl_10_2_0.id)) self.assertRaises(MissingPackageInPool, lambda: pool.package_by_id(mkl_10_3_0.id))
def test_priority_not_registered(self): repo = Repository() pool = Pool() self.assertRaises(DepSolverError, lambda: pool.repository_priority(repo)) self.assertRaises(DepSolverError, lambda: pool.set_repository_order(repo, "dummy"))
def test_simple_fulfilled_installed(self): """Ensure the policy returns the installed version first if it fulfills the requirement, even if higher versions are available.""" mkl_10_4_0 = P("mkl-10.4.0") remote_repository = Repository([self.mkl_10_3_0, self.mkl_11_0_0]) installed_repository = Repository([mkl_10_4_0]) pool = Pool([installed_repository, remote_repository]) policy = DefaultPolicy() queue = [p.id for p in [mkl_10_4_0, self.mkl_10_3_0, self.mkl_11_0_0]] candidates = policy.select_preferred_packages(pool, {}, queue) self.assertEqual(list(candidates), [self.mkl_11_0_0.id]) candidates = policy.prefered_package_ids(pool, {mkl_10_4_0.id: True}, queue) self.assertEqual(list(candidates), [mkl_10_4_0.id, self.mkl_11_0_0.id])
def test_package_by_id_simple(self): repo = Repository([self.mkl_10_1_0, self.mkl_10_2_0]) pool = Pool() pool.add_repository(repo) self.assertEqual(self.mkl_10_1_0, pool.package_by_id(self.mkl_10_1_0.id)) self.assertEqual(self.mkl_10_2_0, pool.package_by_id(self.mkl_10_2_0.id))
def test_simple(self): """Ensure the policy returns the highest version across a set of packages with the same name.""" pool = Pool([Repository([self.mkl_10_3_0, self.mkl_11_0_0])]) policy = DefaultPolicy() queue = [self.mkl_10_3_0.id, self.mkl_11_0_0.id] candidates = policy.select_preferred_packages(pool, {}, queue) self.assertEqual(list(candidates), [self.mkl_11_0_0.id])
def test_priority_no_name(self): paid_repo = Repository([ self.mkl_10_1_0, self.mkl_10_2_0, self.mkl_10_3_0, self.mkl_11_0_0, self.numpy_1_7_0, ], name="paid") free_repo = Repository([self.nomkl_numpy_1_7_0], "free") another_repo = Repository([self.numpy_1_6_1], "another_repo") another_repo_wo_name = Repository([self.numpy_1_6_0]) pool = Pool([paid_repo, free_repo, another_repo, another_repo_wo_name]) pool.set_repository_order("free", before="paid") self.assertEqual(pool.repository_priority(paid_repo), 0) self.assertEqual(pool.repository_priority(free_repo), -1) self.assertEqual(pool.repository_priority(another_repo), -1) self.assertEqual(pool.repository_priority(another_repo_wo_name), -1)
def test_simple(self): r_id = [1, 2] repo1 = Repository(packages=[self.mkl_10_1_0, self.mkl_10_2_0]) pool = Pool() pool.add_repository(repo1) self.assertEqual(self.mkl_10_1_0.id, r_id[0]) self.assertEqual(self.mkl_10_2_0.id, r_id[1]) self.assertRaises(MissingPackageInfoInPool, lambda: pool.package_by_id(self.mkl_10_3_0.id))
def test_add_package_twice(self): repo = Repository([self.numpy_1_6_1]) self.assertRaises(ValueError, lambda: repo.add_package(self.numpy_1_6_1))