コード例 #1
0
 def test_relative_cmd(self):
     # When given the relative path with a directory part to an executable
     # that exists, it should be returned.
     base_dir, tail_dir = os.path.split(self.dir)
     relpath = os.path.join(tail_dir, self.file)
     with change_cwd(path=base_dir):
         rv = which(relpath, path=self.temp_dir)
         self.assertEqual(rv, relpath)
     # But it shouldn't be searched in PATH directories (issue #16957).
     with change_cwd(path=self.dir):
         rv = which(relpath, path=base_dir)
         self.assertIsNone(rv)
コード例 #2
0
 def test_non_matching_mode(self):
     # Set the file read-only and ask for writeable files.
     os.chmod(self.temp_file.name, stat.S_IREAD)
     if os.access(self.temp_file.name, os.W_OK):
         self.skipTest("can't set the file read-only")
     rv = which(self.file, path=self.dir, mode=os.W_OK)
     self.assertIsNone(rv)
コード例 #3
0
 def test_cwd(self):
     # Issue #16957
     base_dir = os.path.dirname(self.dir)
     with change_cwd(path=self.dir):
         rv = which(self.file, path=base_dir)
         if sys.platform == "win32":
             # Windows: current directory implicitly on PATH
             self.assertEqual(rv, os.path.join(os.curdir, self.file))
         else:
             # Other platforms: shouldn't match in the current directory.
             self.assertIsNone(rv)
コード例 #4
0
 def test_empty_path_no_PATH(self):
     with EnvironmentVarGuard() as env:
         env.pop("PATH", None)
         rv = which(self.file)
         self.assertIsNone(rv)
コード例 #5
0
 def test_empty_path(self):
     with change_cwd(path=self.dir):
         with EnvironmentVarGuard() as env:
             env["PATH"] = self.dir
             rv = which(self.file, path="")
             self.assertIsNone(rv)
コード例 #6
0
 def test_environ_path(self):
     with EnvironmentVarGuard() as env:
         env["PATH"] = self.dir
         rv = which(self.file)
         self.assertEqual(rv, self.temp_file.name)
コード例 #7
0
 def test_pathext_checking(self):
     # Ask for the file without the ".exe" extension, then ensure that
     # it gets found properly with the extension.
     rv = which(self.file[:-4], path=self.dir)
     self.assertEqual(rv, self.temp_file.name[:-4] + ".EXE")
コード例 #8
0
 def test_nonexistent_file(self):
     # Return None when no matching executable file is found on the path.
     rv = which("foo.exe", path=self.dir)
     self.assertIsNone(rv)
コード例 #9
0
 def test_relative_path(self):
     base_dir, tail_dir = os.path.split(self.dir)
     with change_cwd(path=base_dir):
         rv = which(self.file, path=tail_dir)
         self.assertEqual(rv, os.path.join(tail_dir, self.file))
コード例 #10
0
 def test_absolute_cmd(self):
     # When given the fully qualified path to an executable that exists,
     # it should be returned.
     rv = which(self.temp_file.name, path=self.temp_dir)
     self.assertEqual(rv, self.temp_file.name)
コード例 #11
0
 def test_basic(self):
     # Given an EXE in a directory, it should be returned.
     rv = which(self.file, path=self.dir)
     self.assertEqual(rv, self.temp_file.name)