예제 #1
0
    def test_find_package(self):
        # Given
        path = os.path.join(_EGGINST_COMMON_DATA, "nose-1.3.0-1.egg")

        # When
        metadata = self.repository.find_package("nose", "1.3.0-1")

        # Then
        self.assertEqual(metadata.key, "nose-1.3.0-1.egg")

        self.assertEqual(metadata.name, "nose")
        self.assertEqual(metadata.version, EnpkgVersion.from_string("1.3.0-1"))

        self.assertEqual(metadata.packages, [])
        self.assertEqual(metadata.python, "2.7")

        self.assertEqual(metadata.available, True)
        self.assertEqual(metadata.store_location,
                         "{0}/".format(path_to_uri(_EGGINST_COMMON_DATA)))

        self.assertEqual(metadata.size, os.path.getsize(path))
        self.assertEqual(metadata.md5, compute_md5(path))

        # Given
        path = os.path.join(_EGGINST_COMMON_DATA, "nose-1.3.0-2.egg")

        # When
        metadata = self.repository.find_package("nose", "1.3.0-2")

        # Then
        self.assertEqual(metadata.key, "nose-1.3.0-2.egg")

        self.assertEqual(metadata.name, "nose")
        self.assertEqual(metadata.version, EnpkgVersion.from_string("1.3.0-2"))
예제 #2
0
    def test_normalize_php_version(self):
        # Given
        version = EnpkgVersion.from_string("10.3-1")
        r_normalized = "10.3.0.0-patch1"

        # When
        normalized = _normalize_php_version(version)

        # Then
        self.assertEqual(normalized, r_normalized)

        # Given
        version = EnpkgVersion.from_string("0.14.1rc1-1")
        r_normalized = "0.14.1.0-patch1"

        # When
        normalized = _normalize_php_version(version)

        # Then
        self.assertEqual(normalized, r_normalized)

        # Given
        version = EnpkgVersion.from_string("2011n-1")
        r_normalized = "2011.14.0.0-patch1"

        # When
        normalized = _normalize_php_version(version)

        # Then
        self.assertEqual(normalized, r_normalized)
예제 #3
0
    def test_find_package(self):
        # Given
        path = os.path.join(_EGGINST_COMMON_DATA, "nose-1.3.0-1.egg")

        # When
        metadata = self.repository.find_package("nose", "1.3.0-1")

        # Then
        self.assertEqual(metadata.key, "nose-1.3.0-1.egg")

        self.assertEqual(metadata.name, "nose")
        self.assertEqual(metadata.version, EnpkgVersion.from_string("1.3.0-1"))

        self.assertEqual(metadata.packages, [])
        self.assertEqual(metadata.python, "2.7")

        self.assertEqual(metadata.available, True)
        self.assertEqual(metadata.store_location,
                         "{0}/".format(path_to_uri(_EGGINST_COMMON_DATA)))

        self.assertEqual(metadata.size, os.path.getsize(path))
        self.assertEqual(metadata.md5, compute_md5(path))

        # Given
        path = os.path.join(_EGGINST_COMMON_DATA, "nose-1.3.0-2.egg")

        # When
        metadata = self.repository.find_package("nose", "1.3.0-2")

        # Then
        self.assertEqual(metadata.key, "nose-1.3.0-2.egg")

        self.assertEqual(metadata.name, "nose")
        self.assertEqual(metadata.version, EnpkgVersion.from_string("1.3.0-2"))
예제 #4
0
    def test_has_package(self):
        # Given
        version = EnpkgVersion.from_string("1.3.0-1")
        available_package = PackageMetadata("nose-1.3.0-1.egg", "nose",
                                            version, [], "2.7")

        version = EnpkgVersion.from_string("1.4.0-1")
        unavailable_package = PackageMetadata("nose-1.4.0-1.egg", "nose",
                                              version, [], "2.7")

        # When/Then
        self.assertTrue(self.repository.has_package(available_package))
        self.assertFalse(self.repository.has_package(unavailable_package))
예제 #5
0
    def test_has_package(self):
        # Given
        version = EnpkgVersion.from_string("1.3.0-1")
        available_package = PackageMetadata("nose-1.3.0-1.egg", "nose",
                                            version, [], "2.7")

        version = EnpkgVersion.from_string("1.4.0-1")
        unavailable_package = PackageMetadata("nose-1.4.0-1.egg", "nose",
                                              version, [], "2.7")

        # When/Then
        self.assertTrue(self.repository.has_package(available_package))
        self.assertFalse(self.repository.has_package(unavailable_package))
예제 #6
0
    def test_normalize_php_version_constraint(self):
        # Given
        version = EnpkgVersion.from_string("10.3-1")
        r_normalized = "10.3.0.0-patch1"

        # When
        normalized = _normalize_php_version(version)

        # Then
        self.assertEqual(normalized, r_normalized)

        # Given
        version = EnpkgVersion.from_string("10.3")
        r_normalized = "10.3.0.0"
예제 #7
0
    def test_sorted_insertion(self):
        # Given
        eggs = ["nose-1.3.0-1.egg", "nose-1.2.1-1.egg"]
        repository = Repository()

        # When
        for egg in eggs:
            path = os.path.join(_EGGINST_COMMON_DATA, egg)
            package = RemotePackageMetadata.from_egg(path)
            repository.add_package(package)

        # Then
        self.assertEqual([m.version
                          for m in repository._name_to_packages["nose"]],
                         [EnpkgVersion.from_string("1.2.1-1"),
                          EnpkgVersion.from_string("1.3.0-1")])
예제 #8
0
    def test_iter_packages(self):
        # Given
        eggs = ["nose-1.3.0-1.egg", "nose-1.2.1-1.egg"]
        repository = Repository()
        for egg in eggs:
            path = os.path.join(_EGGINST_COMMON_DATA, egg)
            package = RepositoryPackageMetadata.from_egg(path)
            repository.add_package(package)

        # When
        metadata = list(repository.iter_packages())

        # Then
        self.assertEqual(len(metadata), 2)
        self.assertEqual(set(m.version for m in metadata),
                         set([EnpkgVersion.from_string("1.2.1-1"),
                              EnpkgVersion.from_string("1.3.0-1")]))
예제 #9
0
    def test_find_packages_with_version(self):
        # Given/When
        metadata = list(self.repository.find_packages("nose", "1.3.0-1"))

        # Then
        self.assertEqual(len(metadata), 1)

        self.assertEqual(metadata[0].version,
                         EnpkgVersion.from_string("1.3.0-1"))
예제 #10
0
    def test_find_packages_with_version(self):
        # Given/When
        metadata = list(self.repository.find_packages("nose", "1.3.0-1"))

        # Then
        self.assertEqual(len(metadata), 1)

        self.assertEqual(metadata[0].version,
                         EnpkgVersion.from_string("1.3.0-1"))
예제 #11
0
    def test_casing(self):
        # Given
        version = EnpkgVersion.from_string("10.3-1")

        # When
        metadata = PackageMetadata("MKL-10.3-1.egg", "mkl", version, [],
                                   "2.7")
        # Then
        self.assertEqual(metadata.name, "mkl")
        self.assertEqual(metadata._egg_name, "MKL")
예제 #12
0
    def test_from_egg(self):
        # Given
        path = os.path.join(_EGGINST_COMMON_DATA, "nose-1.3.0-1.egg")

        # When
        metadata = PackageMetadata.from_egg(path)

        # Then
        self.assertEqual(metadata.name, "nose")
        self.assertEqual(metadata.version, EnpkgVersion.from_string("1.3.0-1"))
예제 #13
0
    def test_fix_php_version(self):
        # Given
        version = EnpkgVersion.from_string("1.0-1")
        r_fixed_version = "1.0-1"

        # When
        fixed = _fix_php_version(version)

        # Then
        self.assertEqual(fixed, r_fixed_version)
예제 #14
0
    def test_from_egg(self):
        # Given
        path = os.path.join(_EGGINST_COMMON_DATA, "nose-1.3.0-1.egg")

        # When
        metadata = PackageMetadata.from_egg(path)

        # Then
        self.assertEqual(metadata.name, "nose")
        self.assertEqual(metadata.version, EnpkgVersion.from_string("1.3.0-1"))
예제 #15
0
    def test_from_pretty_string(self):
        # Given
        pretty_string = "numpy 1.8.1-1; depends (MKL ~= 10.3)"

        # When
        metadata = PackageMetadata._from_pretty_string(pretty_string)

        # Then
        self.assertEqual(metadata.name, "numpy")
        self.assertEqual(metadata.version, EnpkgVersion.from_string("1.8.1-1"))
        self.assertEqual(metadata.dependencies, frozenset(("MKL 10.3",)))
예제 #16
0
    def test_iter_packages(self):
        # Given
        eggs = ["nose-1.3.0-1.egg", "nose-1.2.1-1.egg"]
        repository = Repository()
        for egg in eggs:
            path = os.path.join(_EGGINST_COMMON_DATA, egg)
            package = RepositoryPackageMetadata.from_egg(path)
            repository.add_package(package)

        # When
        metadata = list(repository.iter_packages())

        # Then
        self.assertEqual(len(metadata), 2)
        self.assertEqual(
            set(m.version for m in metadata),
            set([
                EnpkgVersion.from_string("1.2.1-1"),
                EnpkgVersion.from_string("1.3.0-1")
            ]))
예제 #17
0
    def test_repr(self):
        # Given
        version = EnpkgVersion.from_string("1.3.0-1")
        metadata = PackageMetadata("nose-1.3.0-1.egg", "nose", version, [],
                                   "2.7")

        # When
        r = repr(metadata)

        # Then
        self.assertEqual(r, "PackageMetadata('nose-1.3.0-1', key='nose-1.3.0-1.egg')")
예제 #18
0
    def test_repr(self):
        # Given
        version = EnpkgVersion.from_string("1.3.0-1")
        metadata = PackageMetadata("nose-1.3.0-1.egg", "nose", version, [],
                                   "2.7")

        # When
        r = repr(metadata)

        # Then
        self.assertEqual(
            r, "PackageMetadata('nose-1.3.0-1', key='nose-1.3.0-1.egg')")
예제 #19
0
    def test_from_egg(self):
        # Given
        path = os.path.join(_EGGINST_COMMON_DATA, "nose-1.3.0-1.egg")
        repository_info = FSRepositoryInfo(path_to_uri(os.path.dirname(path)))

        # When
        metadata = RemotePackageMetadata.from_egg(path, repository_info)

        # Then
        self.assertEqual(metadata.name, "nose")
        self.assertEqual(metadata.version, EnpkgVersion.from_string("1.3.0-1"))
        self.assertEqual(metadata.source_url, path_to_uri(path))
예제 #20
0
    def test_from_egg(self):
        # Given
        path = os.path.join(_EGGINST_COMMON_DATA, "nose-1.3.0-1.egg")

        # When
        metadata = RepositoryPackageMetadata.from_egg(path)

        # Then
        self.assertEqual(metadata.name, "nose")
        self.assertEqual(metadata.version, EnpkgVersion.from_string("1.3.0-1"))
        self.assertEqual(metadata.store_location,
                         "{0}/".format(path_to_uri(_EGGINST_COMMON_DATA)))
        self.assertEqual(metadata.source_url, path_to_uri(path))
예제 #21
0
    def test_from_egg(self):
        # Given
        path = os.path.join(_EGGINST_COMMON_DATA, "nose-1.3.0-1.egg")

        # When
        metadata = RepositoryPackageMetadata.from_egg(path)

        # Then
        self.assertEqual(metadata.name, "nose")
        self.assertEqual(metadata.version, EnpkgVersion.from_string("1.3.0-1"))
        self.assertEqual(metadata.store_location,
                         "{0}/".format(path_to_uri(_EGGINST_COMMON_DATA)))
        self.assertEqual(metadata.source_url, path_to_uri(path))
예제 #22
0
    def test_from_pretty_string(self):
        # Given
        pretty_string = "numpy 1.8.1-1; depends (MKL ~= 10.3)"
        repository_info = BroodRepositoryInfo("https://acme.com", "acme/looney")

        # When
        metadata = RepositoryPackageMetadata._from_pretty_string(
            pretty_string, repository_info
        )

        # Then
        self.assertEqual(metadata.name, "numpy")
        self.assertEqual(metadata.version, EnpkgVersion.from_string("1.8.1-1"))
        self.assertEqual(metadata.repository_info, repository_info)
        self.assertEqual(metadata.dependencies, frozenset(("MKL 10.3",)))
예제 #23
0
    def test_repr(self):
        # Given
        version = EnpkgVersion.from_string("1.3.0-1")
        repository_info = BroodRepositoryInfo("http://acme.com", "remote")
        package = RepositoryPackageMetadata.from_package(
            PackageMetadata("nose-1.3.0-1.egg", "nose", version, [], "2.7"),
            repository_info,
        )
        r_repr = ("RepositoryPackageMetadata('nose-1.3.0-1', "
                  "repo=BroodRepository(<http://acme.com>, <remote>)")

        # When
        r = repr(package)

        # Then
        self.assertEqual(r, r_repr)
예제 #24
0
    def test_sorted_packages_invalid(self):
        # Given
        entries = [
            dummy_installed_package_factory("numpy", "1.6.1", 1),
            dummy_installed_package_factory("numpy", "1.8k", 2),
        ]
        repository = Repository()
        for entry in entries:
            repository.add_package(entry)

        # When
        packages = repository.find_sorted_packages("numpy")

        # Then
        self.assertEqual(len(packages), 2)
        assertCountEqual(
            self, [p.version for p in packages],
            [EnpkgVersion.from_string(v) for v in ("1.6.1-1", "1.8k-2")])
예제 #25
0
    def test_sorted_packages_invalid(self):
        # Given
        entries = [
            dummy_installed_package_factory("numpy", "1.6.1", 1),
            dummy_installed_package_factory("numpy", "1.8k", 2),
        ]
        repository = Repository()
        for entry in entries:
            repository.add_package(entry)

        # When
        packages = repository.find_sorted_packages("numpy")

        # Then
        self.assertEqual(len(packages), 2)
        assertCountEqual(self, [p.version for p in packages],
                         [EnpkgVersion.from_string(v)
                          for v in ("1.6.1-1", "1.8k-2")])
예제 #26
0
    def find_package(self, name, version):
        """Search for the first match of a package with the given name and
        version.

        Parameters
        ----------
        name : str
            The package name to look for.
        version : str
            The full version string to look for (e.g. '1.8.0-1').

        Returns
        -------
        package : RemotePackageMetadata
            The corresponding metadata.
        """
        version = EnpkgVersion.from_string(version)
        candidates = self._name_to_packages.get(name, [])
        for candidate in candidates:
            if candidate.version == version:
                return candidate
        raise NoSuchPackage("Package '{0}-{1}' not found".format(name,
                                                                 version))
예제 #27
0
    def test_s3index_data(self):
        # Given
        md5 = "c68bb183ae1ab47b6d67ca584957c83c"
        r_s3index_data = {
            "available": True,
            "build": 1,
            "md5": md5,
            "mtime": 0.0,
            "name": "nose",
            "packages": [],
            "product": "free",
            "python": "2.7",
            "size": 1,
            "type": "egg",
            "version": "1.3.0",
        }
        version = EnpkgVersion.from_string("1.3.0-1")
        metadata = RepositoryPackageMetadata("nose-1.3.0-1.egg", "nose",
                                             version, [], "2.7", 1, md5, 0.0,
                                             "free", True, "")

        # When/Then
        self.assertEqual(metadata.s3index_data, r_s3index_data)
예제 #28
0
    def find_package(self, name, version):
        """Search for the first match of a package with the given name and
        version.

        Parameters
        ----------
        name : str
            The package name to look for.
        version : str
            The full version string to look for (e.g. '1.8.0-1').

        Returns
        -------
        package : RepositoryPackageMetadata
            The corresponding metadata.
        """
        version = EnpkgVersion.from_string(version)
        candidates = self._name_to_packages.get(name, [])
        for candidate in candidates:
            if candidate.version == version:
                return candidate
        raise NoSuchPackage("Package '{0}-{1}' not found".format(name,
                                                                 version))
예제 #29
0
    def test_s3index_data(self):
        # Given
        md5 = "c68bb183ae1ab47b6d67ca584957c83c"
        r_s3index_data = {
            "available": True,
            "build": 1,
            "md5": md5,
            "mtime": 0.0,
            "name": "nose",
            "packages": [],
            "product": "free",
            "python": "2.7",
            "size": 1,
            "type": "egg",
            "version": "1.3.0",

        }
        version = EnpkgVersion.from_string("1.3.0-1")
        metadata = RemotePackageMetadata("nose-1.3.0-1.egg", "nose",
                                         version, [], "2.7", 1, md5,
                                         0.0, "free", True, "")

        # When/Then
        self.assertEqual(metadata.s3index_data, r_s3index_data)