Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit fb36b3f

Browse files
committed
Issue #12618: fix py_compile unit tests to handle different drives on Windows
1 parent 6f16660 commit fb36b3f

1 file changed

Lines changed: 10 additions & 0 deletions

File tree

Lib/test/test_py_compile.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,21 @@ def setUp(self):
1414
self.source_path = os.path.join(self.directory, '_test.py')
1515
self.pyc_path = self.source_path + 'c'
1616
self.cache_path = imp.cache_from_source(self.source_path)
17+
self.cwd_drive = os.path.splitdrive(os.getcwd())[0]
18+
# In these tests we compute relative paths. When using Windows, the
19+
# current working directory path and the 'self.source_path' might be
20+
# on different drives. Therefore we need to switch to the drive where
21+
# the temporary source file lives.
22+
drive = os.path.splitdrive(self.source_path)[0]
23+
if drive:
24+
os.chdir(drive)
1725
with open(self.source_path, 'w') as file:
1826
file.write('x = 123\n')
1927

2028
def tearDown(self):
2129
shutil.rmtree(self.directory)
30+
if self.cwd_drive:
31+
os.chdir(self.cwd_drive)
2232

2333
def test_absolute_path(self):
2434
py_compile.compile(self.source_path, self.pyc_path)

0 commit comments

Comments
 (0)