コード例 #1
0
    def test_envvars(self):
        """
        Executable.envvars gives a copy of the originally provided env vars.
        """
        exe = Executable("my-exe", {"SPAM": "eggs"})
        exe.envvars["SPAM"] = "ham"

        self.assertEqual(exe.envvars, {"SPAM": "eggs"})
コード例 #2
0
 def test_missing_filename(self):
     """
     Executable() fails if filename is None or empty.
     """
     with self.assertRaises(ValueError):
         Executable(None)
     with self.assertRaises(ValueError):
         Executable("")
コード例 #3
0
ファイル: test__utils.py プロジェクト: juju/txjuju
    def test_find_not_on_PATH_relative(self):
        """
        Executable.find() fails if the executable is not under $PATH.
        """
        filename = self._write_executable("script")
        os.environ["PATH"] = "/not/the/dir/we/want"

        with self.assertRaises(ExecutableNotFoundError):
            Executable.find("script")
コード例 #4
0
ファイル: test__utils.py プロジェクト: juju/txjuju
    def test_run_executable_does_not_exist(self):
        """
        Executable.run_out() fails if the executable does not exist.
        """
        filename = self._resolve_executable("does-not-exist")
        exe = Executable(filename)

        with self.assertRaises(ExecutableNotFoundError):
            exe.run_out()
コード例 #5
0
    def test_resolve_args(self):
        """
        Executable.resolve_args() returns the args list that may
        be passed to subprocess.*().
        """
        exe = Executable("my-exe", {"SPAM": "eggs"})
        args = exe.resolve_args("x", "-y", "z")

        self.assertEqual(args, ["my-exe", "x", "-y", "z"])
コード例 #6
0
ファイル: test__utils.py プロジェクト: juju/txjuju
    def test_find_does_not_exist(self):
        """
        Executable.find() fails if the executable does not exist,
        even if an absolute filename is provided (an absolute filename
        makes $PATH irrelevant).
        """
        filename = self._resolve_executable("does-not-exist")

        with self.assertRaises(ExecutableNotFoundError):
            Executable.find(filename)
コード例 #7
0
    def test_run_out(self):
        """
        Executable.run_out() runs the command and returns stdout.
        """
        filename = self._write_executable("script")
        self.assertTrue(os.path.exists(filename))
        exe = Executable(filename, {"SPAM": "eggs"})
        out = exe.run_out("x", "-y", "z")

        self.assertTrue(out.startswith("x -y z\n"))
        self.assertIn("SPAM=eggs\n", out)
コード例 #8
0
    def test_run(self):
        """
        Executable.run() runs the command and returns nothing.
        """
        filename = self._write_executable("script")
        exe = Executable(filename, {"SPAM": "eggs"})
        with tempfile.NamedTemporaryFile() as outfile:
            exe.run("x", "-y", "z", stdout=outfile)
            outfile.seek(0)
            out = outfile.read()

        self.assertTrue(out.startswith("x -y z\n"))
        self.assertIn("SPAM=eggs\n", out)
コード例 #9
0
ファイル: test__utils.py プロジェクト: juju/txjuju
    def test_find_no_envvars_PATH_not_on_os_environs_PATH_relative(self):
        """
        Executable.find() fails if the filename is relative and
        the executable is not found under $PATH in envvars nor in
        os.environ.
        """
        filename = self._write_executable("script")
        os.environ["PATH"] = "/not/the/dir/we/want"
        envvars = {
            "SPAM": "eggs",
        }

        with self.assertRaises(ExecutableNotFoundError):
            Executable.find("script", envvars)
コード例 #10
0
ファイル: test__utils.py プロジェクト: juju/txjuju
    def test_find_not_on_envvars_PATH(self):
        """
        Executable.find() fails for a relative filename if envvars
        is provided and has $PATH set, but the executable is not
        located under it, even if it *is* findable under
        os.environ["PATH"].
        """
        filename = self._write_executable("script")
        os.environ["PATH"] = os.path.dirname(filename)
        envvars = {
            "PATH": "/not/the/dir/we/want",
            "SPAM": "eggs",
        }

        with self.assertRaises(ExecutableNotFoundError):
            Executable.find("script", envvars)
コード例 #11
0
    def test_conversion(self):
        """
        Executable() converts the args to str.
        """
        exe = Executable(u"my-exe", [(u"SPAM", u"eggs"), ("ham", "")])

        self.assertEqual(exe.filename, "my-exe")
        self.assertEqual(exe.envvars, {"SPAM": "eggs"})
コード例 #12
0
    def test_minimal(self):
        """
        Executable() works with minimal arguments.
        """
        exe = Executable("my-exe")

        self.assertEqual(exe.filename, "my-exe")
        self.assertIsNone(exe.envvars)
コード例 #13
0
    def test_full(self):
        """
        Executable() works when provided all arguments.
        """
        exe = Executable("my-exe", {"SPAM": "eggs"})

        self.assertEqual(exe.filename, "my-exe")
        self.assertEqual(exe.envvars, {"SPAM": "eggs"})
コード例 #14
0
ファイル: test__utils.py プロジェクト: juju/txjuju
    def test_find_not_on_PATH_absolute(self):
        """
        Executable.find() succeeds if unfindable but absolute filename.
        """
        filename = self._write_executable("script")
        os.environ["PATH"] = "/dir/does/not/exist"
        exe = Executable.find(filename)

        self.assertEqual(exe.filename, filename)
コード例 #15
0
ファイル: test__utils.py プロジェクト: juju/txjuju
    def test_find_on_os_environs_PATH(self):
        """
        Executable.find() succeeds if the executable exists and
        is located under os.environ["PATH"]
        """
        filename = self._write_executable("script")
        os.environ["PATH"] = os.path.dirname(filename)
        exe = Executable.find("script")

        self.assertEqual(exe.filename, filename)
        self.assertIsNone(exe.envvars)
コード例 #16
0
ファイル: test__utils.py プロジェクト: juju/txjuju
    def test_find_no_envvars_PATH_but_on_os_environs_PATH(self):
        """
        Executable.find() succeeds if the provided envvars does not
        have $PATH set, but os.environ does and the executable is
        located under it.
        """
        filename = self._write_executable("script")
        os.environ["PATH"] = os.path.dirname(filename)
        envvars = {
            "SPAM": "eggs",
        }
        exe = Executable.find("script", envvars)

        self.assertEqual(exe.filename, filename)
        self.assertEqual(exe.envvars, envvars)
コード例 #17
0
ファイル: test__utils.py プロジェクト: juju/txjuju
    def test_find_no_envvars_PATH_not_on_os_environs_PATH_absolute(self):
        """
        Executable.find() succeeds if the filename is absolute, even
        if envars is provided without $PATH and the executable is not
        located under os.environ["PATH"].
        """
        filename = self._write_executable("script")
        os.environ["PATH"] = "/not/the/dir/we/want"
        envvars = {
            "SPAM": "eggs",
        }
        exe = Executable.find(filename, envvars)

        self.assertEqual(exe.filename, filename)
        self.assertEqual(exe.envvars, envvars)
コード例 #18
0
ファイル: test__utils.py プロジェクト: juju/txjuju
    def test_find_on_envvars_PATH(self):
        """
        Executable.find() succeeds if envvars has $PATH set and the
        executable is locatd under it.  os.environ["PATH"] is ignored.
        """
        filename = self._write_executable("script")
        os.environ["PATH"] = "/not/the/dir/we/want"
        envvars = {
            "PATH": self.dirname,
            "SPAM": "eggs",
        }
        exe = Executable.find("script", envvars)

        self.assertEqual(exe.filename, filename)
        self.assertEqual(exe.envvars, envvars)
コード例 #19
0
ファイル: test_fakejuju.py プロジェクト: simpoir/fake-juju
    def test_cli_full(self):
        """FakeJuju.cli() works correctly when given all args."""
        juju = FakeJuju("/fake-juju", "1.25.6", "/x")
        cli = juju.cli("/y", {"SPAM": "eggs"})

        self.assertEqual(
            cli._exe,
            Executable(
                "/fake-juju", {
                    "SPAM": "eggs",
                    "FAKE_JUJU_DATA_DIR": "/x",
                    "FAKE_JUJU_FAILURES": "/x/juju-failures",
                    "FAKE_JUJU_LOGS_DIR": "/x",
                    "JUJU_HOME": "/y",
                }),
        )
コード例 #20
0
ファイル: test_fakejuju.py プロジェクト: simpoir/fake-juju
    def test_cli_minimal(self):
        """FakeJuju.cli() works correctly when given minimal args."""
        juju = FakeJuju("/fake-juju", "1.25.6", "/x")
        cli = juju.cli("/y")

        self.assertEqual(
            cli._exe,
            Executable(
                "/fake-juju",
                dict(
                    os.environ, **{
                        "FAKE_JUJU_DATA_DIR": "/x",
                        "FAKE_JUJU_FAILURES": "/x/juju-failures",
                        "FAKE_JUJU_LOGS_DIR": "/x",
                        "JUJU_HOME": "/y",
                    })),
        )
コード例 #21
0
ファイル: test__utils.py プロジェクト: juju/txjuju
 def test_relative_filename(self):
     """
     Executable() fails if filename is None or empty.
     """
     with self.assertRaises(ValueError):
         Executable("x/y/z")