Ejemplo n.º 1
0
    def test_removed_barrel_not_in_cache(self):
        fake_cache = StringIO(self.__build_fake_cache(2))

        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 = {"match.return_value": True}
        mock_hasher.configure_mock(**hash_attr)

        config = {
            "exists.side_effect": lambda x: {
                "test0.barrel": False
            }.get(x, True)
        }
        with patch("os.path", **config):
            cache = Cache(mock_config, mock_hasher)

        dep1Test = Dependency("Depend0")
        dep1Test.set_version("0.1.2")

        dep2Test = Dependency("Depend1")
        dep2Test.set_version("0.1.2")

        self.assertIn(dep2Test, cache)
        self.assertNotIn(dep1Test, cache)
Ejemplo n.º 2
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))
Ejemplo n.º 3
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)
Ejemplo n.º 4
0
    def test_dependency_ne_with_different_repo(self):
        dep = Dependency("Depend")
        dep.set_version("1.2.3")
        dep.set_repo("owner/Depend")

        dep2 = Dependency("Depend")
        dep2.set_version("1.2.3")
        dep2.set_repo("owner2/Depend")

        self.assertNotEqual(dep, dep2)
Ejemplo n.º 5
0
    def test_dependency_eq_with_other(self):
        dep = Dependency("Depend")
        dep.set_version("1.2.3")
        dep.set_repo("owner/Depend")

        dep2 = Dependency("Depend")
        dep2.set_version("1.2.3")
        dep2.set_repo("owner/Depend")

        self.assertEqual(dep, dep2)
Ejemplo n.º 6
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)
Ejemplo n.º 7
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)
Ejemplo n.º 8
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)
Ejemplo n.º 9
0
    def test_cache_reads_json_cache_file(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 = {"match.return_value": True}
        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.assertTrue(depTest in cache)
Ejemplo n.º 10
0
    def test_dependency_can_get_version(self):
        dep = Dependency("Depend")
        dep.set_version("1.2.3")

        self.assertEqual("1.2.3", str(dep.version))