summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorBrett Cannon <bcannon@gmail.com>2010-08-22 22:11:06 (GMT)
committerBrett Cannon <bcannon@gmail.com>2010-08-22 22:11:06 (GMT)
commit186335bd5cbe839348922aef3661e17247def27b (patch)
tree3369e196f91c862d2ad3f67bbcb45678c20581f8 /Lib
parent0723d2c78d077232d3d019c78e397f5fcb7a159b (diff)
downloadcpython-186335bd5cbe839348922aef3661e17247def27b.zip
cpython-186335bd5cbe839348922aef3661e17247def27b.tar.gz
cpython-186335bd5cbe839348922aef3661e17247def27b.tar.bz2
Make sure that no __pycache__ directory is needlessly left behind when testing
imports with an empty string in sys.path.
Diffstat (limited to 'Lib')
-rw-r--r--Lib/importlib/test/source/test_file_loader.py17
1 files changed, 10 insertions, 7 deletions
diff --git a/Lib/importlib/test/source/test_file_loader.py b/Lib/importlib/test/source/test_file_loader.py
index ce6f5d4..0ffe78d 100644
--- a/Lib/importlib/test/source/test_file_loader.py
+++ b/Lib/importlib/test/source/test_file_loader.py
@@ -8,6 +8,7 @@ import imp
import marshal
import os
import py_compile
+import shutil
import stat
import sys
import unittest
@@ -112,18 +113,20 @@ class SimpleTest(unittest.TestCase):
def test_file_from_empty_string_dir(self):
# Loading a module found from an empty string entry on sys.path should
# 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")
try:
with util.uncache('_temp'):
- loader = _bootstrap._SourceFileLoader('_temp', '_temp.py')
+ loader = _bootstrap._SourceFileLoader('_temp', file_path)
mod = loader.load_module('_temp')
- self.assertEqual('_temp.py', mod.__file__)
- self.assertEqual(imp.cache_from_source('_temp.py'),
+ self.assertEqual(file_path, mod.__file__)
+ self.assertEqual(imp.cache_from_source(file_path),
mod.__cached__)
-
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):
@@ -380,7 +383,7 @@ def test_main():
run_unittest(SimpleTest,
SourceLoaderBadBytecodeTest,
SourcelessLoaderBadBytecodeTest
- )
+ )
if __name__ == '__main__':