Пример #1
0
    def test_can_overwrite_dependency(self):
        fake_cache = StringIO(self.__build_fake_cache())

        mock_config = Mock(Config)
        attr = {"open_file.side_effect": lambda name, mode, cb: cb(fake_cache)}
        mock_config.configure_mock(**attr)

        mock_hasher = Mock(FileHasher)
        hash_attr = {"hash_file.return_value": "0123"}
        mock_hasher.configure_mock(**hash_attr)

        config = {"exists.return_value": True}
        with patch("os.path", **config):
            cache = Cache(mock_config, mock_hasher)

        depTest = Dependency("Depend")
        depTest.set_version("0.1.2")
        self.assertIn(depTest, cache)
        self.assertNotEqual("test3.barrel",
                            cache.get_barrel_for_package(depTest))

        depTest.set_barrel_name("test3.barrel")
        cache.add_dependency(depTest)

        self.assertEqual("test3.barrel", cache.get_barrel_for_package(depTest))
Пример #2
0
    def __initialize_dependency(self, package_name: str) -> None:
        new_dep = Dependency(package_name)
        new_dep.set_version(self.manifest.get_required_version(package_name))
        new_dep.set_repo(self.packages.get_repo_for_package(package_name))

        if new_dep in self.__cache:
            new_dep.set_barrel_name(
                self.__cache.get_barrel_for_package(new_dep))

        self.__add_dependency(new_dep)
Пример #3
0
    def test_dependency_eq_with_different_barrel_name(self):
        dep = Dependency("Depend")
        dep.set_version("1.2.3")
        dep.set_repo("owner/Depend")
        dep.set_barrel_name("x.barrel")

        dep2 = Dependency("Depend")
        dep2.set_version("1.2.3")
        dep2.set_repo("owner/Depend")
        dep.set_barrel_name("y.barrel")

        self.assertEqual(dep, dep2)
Пример #4
0
    def test_cache_initializes_empty_if_cache_doesnt_exist(self):
        mock_config = Mock(Config)
        config = {"exists.return_value": False}
        with patch("os.path", **config):
            cache = Cache(mock_config)

        self.assertIsNotNone(cache)

        depTest = Dependency("Depend2")
        depTest.set_version("0.1.2")
        depTest.set_barrel_name("test.barrel")
        self.assertNotIn(depTest, cache)
Пример #5
0
    def test_can_add_dependency(self):
        mock_config = Mock(Config)

        mock_hasher = Mock(FileHasher)
        hash_attr = {"hash_file.return_value": "0123"}
        mock_hasher.configure_mock(**hash_attr)

        config = {"exists.return_value": False}
        with patch("os.path", **config):
            cache = Cache(mock_config, mock_hasher)

        depTest = Dependency("Depend2")
        depTest.set_version("0.1.2")
        depTest.set_barrel_name("test.barrel")

        cache.add_dependency(depTest)
        self.assertIn(depTest, cache)
Пример #6
0
    def __download_dependency_assets(self, dep: Dependency) -> None:
        try:
            asset = self.__downloader.download_barrel(dep)
            logging.info(
                "Downloaded barrel {barrel} from release {tag}".format(
                    barrel=asset.name, tag=asset.version))
        except Error as e:
            logging.error(
                "Failed to download barrel for {dep}:{version} - {msg}".format(
                    dep=dep.package_name, version=dep.version, msg=e.message))
            return

        barrel_name = os.path.join(self.__project.config.barrel_dir,
                                   asset.name)
        self.__project.config.open_file(barrel_name, "wb",
                                        lambda f: f.write(asset.content))
        dep.set_barrel_name(barrel_name)
Пример #7
0
    def test_dependency_can_get_barrel_name(self):
        dep = Dependency("Depend")
        dep.set_barrel_name("x.barrel")

        self.assertEqual("x.barrel", dep.barrel_name)