Exemplo n.º 1
0
    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")
Exemplo n.º 2
0
    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)
Exemplo n.º 3
0
    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)
Exemplo n.º 4
0
    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)
Exemplo n.º 5
0
    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)
Exemplo n.º 6
0
    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)
Exemplo n.º 7
0
    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)
Exemplo n.º 8
0
    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)
Exemplo n.º 9
0
    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)