Commit 186335bd authored by Brett Cannon's avatar Brett Cannon

Make sure that no __pycache__ directory is needlessly left behind when testing

imports with an empty string in sys.path.
parent 0723d2c7
...@@ -8,6 +8,7 @@ import imp ...@@ -8,6 +8,7 @@ import imp
import marshal import marshal
import os import os
import py_compile import py_compile
import shutil
import stat import stat
import sys import sys
import unittest import unittest
...@@ -112,18 +113,20 @@ class SimpleTest(unittest.TestCase): ...@@ -112,18 +113,20 @@ class SimpleTest(unittest.TestCase):
def test_file_from_empty_string_dir(self): def test_file_from_empty_string_dir(self):
# Loading a module found from an empty string entry on sys.path should # Loading a module found from an empty string entry on sys.path should
# not only work, but keep all attributes relative. # not only work, but keep all attributes relative.
with open('_temp.py', 'w') as file: file_path = '_temp.py'
with open(file_path, 'w') as file:
file.write("# test file for importlib") file.write("# test file for importlib")
try: try:
with util.uncache('_temp'): with util.uncache('_temp'):
loader = _bootstrap._SourceFileLoader('_temp', '_temp.py') loader = _bootstrap._SourceFileLoader('_temp', file_path)
mod = loader.load_module('_temp') mod = loader.load_module('_temp')
self.assertEqual('_temp.py', mod.__file__) self.assertEqual(file_path, mod.__file__)
self.assertEqual(imp.cache_from_source('_temp.py'), self.assertEqual(imp.cache_from_source(file_path),
mod.__cached__) mod.__cached__)
finally: finally:
os.unlink('_temp.py') os.unlink(file_path)
pycache = os.path.dirname(imp.cache_from_source(file_path))
shutil.rmtree(pycache)
class BadBytecodeTest(unittest.TestCase): class BadBytecodeTest(unittest.TestCase):
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment