Issue #16993: shutil.which() now preserves the case of the path and extension

on Windows.
This commit is contained in:
Serhiy Storchaka 2013-01-21 15:00:27 +02:00
parent 85da624ebe
commit 014791f848
4 changed files with 15 additions and 9 deletions

View file

@ -1269,12 +1269,13 @@ class TestShutil(unittest.TestCase):
class TestWhich(unittest.TestCase):
def setUp(self):
self.temp_dir = tempfile.mkdtemp()
self.temp_dir = tempfile.mkdtemp(prefix="Tmp")
self.addCleanup(shutil.rmtree, self.temp_dir, True)
# Give the temp_file an ".exe" suffix for all.
# It's needed on Windows and not harmful on other platforms.
self.temp_file = tempfile.NamedTemporaryFile(dir=self.temp_dir,
suffix=".exe")
prefix="Tmp",
suffix=".Exe")
os.chmod(self.temp_file.name, stat.S_IXUSR)
self.addCleanup(self.temp_file.close)
self.dir, self.file = os.path.split(self.temp_file.name)
@ -1317,7 +1318,7 @@ class TestWhich(unittest.TestCase):
# Ask for the file without the ".exe" extension, then ensure that
# it gets found properly with the extension.
rv = shutil.which(self.temp_file.name[:-4], path=self.dir)
self.assertEqual(self.temp_file.name, rv)
self.assertEqual(rv, self.temp_file.name[:-4] + ".exe")
class TestMove(unittest.TestCase):