示例#1
0
    def test_temp_variable(self):
        """Testing util.temp.variables: basic behaviour"""
        with temp.variables({"sys.argv": ['test_value']}):
            assert sys.argv[0] == 'test_value'
        assert sys.argv[0] != 'test_value'

        with temp.variables({"sys.stdout": self._mock_flush}):
            assert sys.stdout == self._mock_flush

        with self.assertRaises(ValueError):
            with temp.variables({"fail": None}):
                pass
示例#2
0
    def test_temp_variable(self):
        """Testing util.temp.variables: basic behaviour"""
        with temp.variables({"sys.argv": ['test_value']}):
            assert sys.argv[0] == 'test_value'
        assert sys.argv[0] != 'test_value'

        with temp.variables({"sys.stdout": self._mock_flush}):
            assert sys.stdout == self._mock_flush

        with self.assertRaises(ValueError):
            with temp.variables({"fail": None}):
                pass
示例#3
0
    def test_install_command_repo(self):
        with self.assertRaises(PackageError):
            self.test_install_command(False, "invalid://")

        self.plugin = TestInstallCommand._mock_str("none.none")
        self.plugin.endswith = lambda x: True
        self.install_global = False
        self.upgrade = True

        config = Config()
        config["plugin_dir"] = ["none"]
        import drove.package
        with temp.variables({
            "drove.package.Package.from_repo":
                staticmethod(lambda *a, **kw: self)
        }):
            cmd = InstallCommand(config, self, getLogger())
            assert cmd.__class__.__name__ == "InstallCommand"
            cmd.execute()

        _urlopen = package.urllib.request.urlopen
        package.urllib.request.urlopen = lambda *a, **kw: BytesIO(
            b(_test_result_msg)
        )
        package.Package.from_url = staticmethod(
            lambda *a, **kw: package.Package(
                "none", "none",
                "12345678", "", "")
        )
        self.test_install_command(False, "none")
示例#4
0
    def test_tester(self):
        """Testing util.tester.run_tests: basic behaviour"""

        with temp.variables({"sys.stderr": open(os.devnull, 'a')}):
            #  We need to fake stderr because sometimes coverage.py
            #  puts an error in stderr when tests are collected by
            #  tester. This only happened when test into test.
            tester.run_tests(os.path.dirname(__file__))
示例#5
0
    def test_tester(self):
        """Testing util.tester.run_tests: basic behaviour"""

        with temp.variables({"sys.stderr": open(os.devnull, 'a')}):
            #  We need to fake stderr because sometimes coverage.py
            #  puts an error in stderr when tests are collected by
            #  tester. This only happened when test into test.
            tester.run_tests(os.path.dirname(__file__))
示例#6
0
    def test_install_fromurl(self):
        self.plugin = "http://none"
        self.install_global = False
        self.upgrade = False

        config = Config()
        config["plugin_dir"] = ["none"]

        with temp.variables({
            "drove.package.Package.from_url":
                staticmethod(lambda *a, **kw: self)
        }):
            cmd = InstallCommand(config, self, getLogger())
            assert cmd.__class__.__name__ == "InstallCommand"
            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_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()
示例#9
0
    def test_install_command(self, install_global=False, plugin=__file__):
        self.plugin = TestInstallCommand._mock_str(plugin)
        self.plugin.endswith = lambda x: True
        self.install_global = install_global
        self.upgrade = True

        config = Config()
        config["plugin_dir"] = ["none"]

        import drove.package
        with temp.variables({
            "drove.package.Package.from_tarballfd":
                staticmethod(lambda *a, **kw: self)
        }):
            cmd = InstallCommand(config, self, getLogger())
            assert cmd.__class__.__name__ == "InstallCommand"
            cmd.execute()
示例#10
0
 def test_package_find(self):
     with temp.variables({
         "glob.glob": lambda *a,**k:["d.version"]
     }):
         find_package(None, None)