def test_from_loose_string(self): r_version = Version(1, 2, 0) version = Version.from_loose_string("1.2") self.assertEqual(r_version, version) r_version = Version(1, 0, 0) version = Version.from_loose_string("1") r_version = Version(1, 2, 0, build=BuildVersion.from_string("123")) version = Version.from_loose_string("1.2+123") self.assertEqual(r_version, version) r_version = Version(1, 2, 0, pre_release=PreReleaseVersion.from_string("123")) version = Version.from_loose_string("1.2-123") self.assertEqual(r_version, version) r_version = Version(1, 2, 0, PreReleaseVersion.from_string("123"), BuildVersion.from_string("456")) version = Version.from_loose_string("1.2-123+456") self.assertEqual(r_version, version)
def test_invalid_arguments(self): self.assertRaises(Exception, lambda: Version("a", 2, 0)) self.assertRaises(Exception, lambda: Version(1, "a", 0)) self.assertRaises(Exception, lambda: Version(1, 2, "a")) self.assertRaises(Exception, lambda: Version(1, 2, 0, pre_release="alpha")) self.assertRaises(Exception, lambda: Version(1, 2, 0, build="build.1")) self.assertRaises(Exception, lambda: V("1.2.a"))
def _parse_name_version_part(name_version, loose): parts = name_version.strip().split("-", 1) if len(parts) < 2: raise ValueError("Invalid package string %s" % name_version) else: name, version_string = parts if loose: version = Version.from_loose_string(version_string) else: version = V(version_string) return name, version
def from_string(cls, literal_string, pool): if literal_string.startswith("-"): is_not = True _, name, version = literal_string.split("-", 2) else: is_not = False name, version = literal_string.split("-") package = Package(name, Version.from_string(version)) if not pool.has_package(package): raise MissingPackageInPool(package) if is_not: return PackageNot(package.id, pool) else: return PackageLiteral(package.id, pool)
def find_package(self, name, version): """Find the package with the given name and version (exact match). Parameters ---------- name: str Name of the package(s) to look for version: str Name of the package(s) to look for Returns ------- package: Package or None The package if found, None otherwise. """ package = Package(name, Version.from_string(version)) return self._id_to_package.get(package.unique_name, None)
def test_construction_simple(self): r_v = V("1.2.0") v = Version(1, 2, 0) self.assertEqual(v.__dict__, r_v.__dict__)
import unittest from depsolver.package \ import \ Package from depsolver.repository \ import \ Repository from depsolver.version \ import \ Version numpy_1_6_1 = Package("numpy", Version.from_string("1.6.1")) numpy_1_7_0 = Package("numpy", Version.from_string("1.7.0")) scipy_0_11_0 = Package("scipy", Version.from_string("0.11.0")) class TestRepository(unittest.TestCase): def test_simple_construction(self): repo = Repository() self.assertEqual(repo.list_packages(), []) r_packages = [numpy_1_6_1, numpy_1_7_0, scipy_0_11_0] repo = Repository(r_packages) packages = set(repo.iter_packages()) self.assertEqual(packages, set(r_packages)) def test_has_package(self): packages = [numpy_1_6_1, numpy_1_7_0, scipy_0_11_0]
import unittest from depsolver.package \ import \ Package from depsolver.repository \ import \ Repository from depsolver.version \ import \ Version numpy_1_6_1 = Package("numpy", Version.from_string("1.6.1")) numpy_1_7_0 = Package("numpy", Version.from_string("1.7.0")) scipy_0_11_0 = Package("scipy", Version.from_string("0.11.0")) class TestRepository(unittest.TestCase): def test_simple_construction(self): repo = Repository() self.assertEqual(repo.list_packages(), []) r_packages = [numpy_1_6_1, numpy_1_7_0, scipy_0_11_0] repo = Repository(r_packages) packages = set(repo.iter_packages()) self.assertEqual(packages, set(r_packages)) def test_has_package(self): packages = [numpy_1_6_1, numpy_1_7_0, scipy_0_11_0] repo = Repository(packages)