[Python-checkins] cpython (3.2): Issue #12618: fix py_compile unit tests to handle different drives on Windows

meador.inge python-checkins at python.org
Sat Nov 26 19:01:22 CET 2011


http://hg.python.org/cpython/rev/7097d52cacee
changeset:   73759:7097d52cacee
branch:      3.2
parent:      73754:2be3a2e63683
user:        Meador Inge <meadori at gmail.com>
date:        Sat Nov 26 11:37:02 2011 -0600
summary:
  Issue #12618: fix py_compile unit tests to handle different drives on Windows

files:
  Lib/test/test_py_compile.py |  10 ++++++++++
  1 files changed, 10 insertions(+), 0 deletions(-)


diff --git a/Lib/test/test_py_compile.py b/Lib/test/test_py_compile.py
--- a/Lib/test/test_py_compile.py
+++ b/Lib/test/test_py_compile.py
@@ -14,11 +14,21 @@
         self.source_path = os.path.join(self.directory, '_test.py')
         self.pyc_path = self.source_path + 'c'
         self.cache_path = imp.cache_from_source(self.source_path)
+        self.cwd_drive = os.path.splitdrive(os.getcwd())[0]
+        # In these tests we compute relative paths.  When using Windows, the
+        # current working directory path and the 'self.source_path' might be
+        # on different drives.  Therefore we need to switch to the drive where
+        # the temporary source file lives.
+        drive = os.path.splitdrive(self.source_path)[0]
+        if drive:
+            os.chdir(drive)
         with open(self.source_path, 'w') as file:
             file.write('x = 123\n')
 
     def tearDown(self):
         shutil.rmtree(self.directory)
+        if self.cwd_drive:
+            os.chdir(self.cwd_drive)
 
     def test_absolute_path(self):
         py_compile.compile(self.source_path, self.pyc_path)

-- 
Repository URL: http://hg.python.org/cpython


More information about the Python-checkins mailing list