| 53 | class PyCompileTestsBase: |
| 54 | |
| 55 | def setUp(self): |
| 56 | self.directory = tempfile.mkdtemp(dir=os.getcwd()) |
| 57 | self.source_path = os.path.join(self.directory, '_test.py') |
| 58 | self.pyc_path = self.source_path + 'c' |
| 59 | try: |
| 60 | self.cache_path = importlib.util.cache_from_source(self.source_path) |
| 61 | except NotImplementedError: |
| 62 | self.cache_path = None |
| 63 | self.cwd_drive = os.path.splitdrive(os.getcwd())[0] |
| 64 | # In these tests we compute relative paths. When using Windows, the |
| 65 | # current working directory path and the 'self.source_path' might be |
| 66 | # on different drives. Therefore we need to switch to the drive where |
| 67 | # the temporary source file lives. |
| 68 | drive = os.path.splitdrive(self.source_path)[0] |
| 69 | if drive: |
| 70 | os.chdir(drive) |
| 71 | with open(self.source_path, 'w') as file: |
| 72 | file.write('x = 123\n') |
| 73 | |
| 74 | def tearDown(self): |
| 75 | shutil.rmtree(self.directory) |