예제 #1
0
 def test_package_remove_module(self):
     with temp.directory() as dir:
         p = Package.from_tarballfd(
             BytesIO(b64decode(_test_package_okay_module)), dir,
             upgrade=True
         )
         p.remove()
예제 #2
0
    def test_package_tarball(self):
        self._mock_flag = False
        if hasattr(drove.package.__builtins__, "open"):
            self._mock_orig = drove.package.__builtins__.open
        else:
            self._mock_orig = drove.package.__builtins__["open"]

        # Weird hack to mock __builtins__ function to be compatible
        # between py27 and py3
        def _mock_open(*a, **kw):
            if not self._mock_flag:
                self._mock_flag = True
                return BytesIO(
                    b64decode(_test_package_okay)
                )
            else:
                return self._mock_orig(*a, **kw)

        with temp.directory() as dir:
            if hasattr(drove.package.__builtins__, "open"):
                drove.package.__builtins__.open = _mock_open
            else:
                drove.package.__builtins__["open"] = _mock_open
            try:
                Package.from_tarball("mocked", dir)
            finally:
                if hasattr(drove.package.__builtins__, "open"):
                    drove.package.__builtins__.open = self._mock_orig
                else:
                    drove.package.__builtins__["open"] = self._mock_orig
예제 #3
0
    def test_package_okay(self):
        with temp.directory() as dir:
            p = Package.from_tarballfd(
                BytesIO(b64decode(_test_package_okay_folder)), dir, True
            )

            # Try to reinstall without upgrade
            with self.assertRaises(PackageError):
                Package.from_tarballfd(
                    BytesIO(b64decode(_test_package_okay_folder)), dir
                )

            # Reinstall with upgrade (none to do)
            Package.from_tarballfd(
                BytesIO(b64decode(_test_package_okay_folder)), dir,
                upgrade=True
            )

            # Reinstall with upgrade (reinstall)
            Package.from_tarballfd(
                BytesIO(b64decode(_test_package_okay_upgrade)), dir,
                upgrade=True
            )

            x = repr(p)
            p.remove()
예제 #4
0
 def test_package_url(self):
     with temp.directory() as dir:
         _urlopen = urllib.request.urlopen
         urllib.request.urlopen = lambda *a, **kw: \
             BytesIO(b64decode(_test_package_okay))
         try:
             Package.from_url("http://none", dir)
         finally:
             urllib.request.urlopen = _urlopen
예제 #5
0
 def test_package_nopip(self):
     with temp.directory() as dir:
         with self.assertRaises(PackageError):
             import pip
             del pip.main
             Package.install_requirements.__globals__["pip"] = pip
             Package.from_tarballfd(
                 BytesIO(b64decode(_test_package_okay_deps)), dir
             )
예제 #6
0
    def test_remove_command(self, install_global=False, plugin=__file__):
        self.plugin = TestRemoveCommand._mock_str(plugin)
        self.plugin.endswith = lambda x: True
        self.install_global = install_global
        self.upgrade = True

        with temp.directory() as tmp_dir:
            config = Config()
            config["plugin_dir"] = [tmp_dir]

            with temp.variables({
                    "drove.command.remove.find_package":
                    TestRemoveCommand._mock_find
            }):
                cmd = RemoveCommand(config, self, getLogger())
                assert cmd.__class__.__name__ == "RemoveCommand"
                cmd.execute()
예제 #7
0
    def test_remove_command(self, install_global=False, plugin=__file__):
        self.plugin = TestRemoveCommand._mock_str(plugin)
        self.plugin.endswith = lambda x: True
        self.install_global = install_global
        self.upgrade = True

        with temp.directory() as tmp_dir:
            config = Config()
            config["plugin_dir"] = [tmp_dir]

            with temp.variables({
                "drove.command.remove.find_package":
                   TestRemoveCommand._mock_find
            }):
                cmd = RemoveCommand(config, self, getLogger())
                assert cmd.__class__.__name__ == "RemoveCommand"
                cmd.execute()
예제 #8
0
 def test_temp_directory(self):
     """Testing util.temp.directory: basic behaviour"""
     with temp.directory() as tmp_dir:
         assert os.path.isdir(tmp_dir)
     assert not os.path.isdir(tmp_dir)
예제 #9
0
 def test_temp_directory(self):
     """Testing util.temp.directory: basic behaviour"""
     with temp.directory() as tmp_dir:
         assert os.path.isdir(tmp_dir)
     assert not os.path.isdir(tmp_dir)
예제 #10
0
 def test_package_error(self, pkg=_test_package_none):
     with temp.directory() as dir:
         with self.assertRaises(PackageError):
             Package.from_tarballfd(
                 BytesIO(b64decode(pkg)), dir
             )