diff options
| author | Barry Warsaw <barry@python.org> | 2010-04-17 00:19:56 (GMT) |
|---|---|---|
| committer | Barry Warsaw <barry@python.org> | 2010-04-17 00:19:56 (GMT) |
| commit | 28a691b7fdde1b8abafa4c4a5025e6bfa44f48b9 (patch) | |
| tree | ca0098063694e0f91d1bcd785d0044e96e1bf389 /Lib/test/test_pkgimport.py | |
| parent | 0e59cc3fc347582d8625050de258a2dd6b87f978 (diff) | |
| download | cpython-28a691b7fdde1b8abafa4c4a5025e6bfa44f48b9.zip cpython-28a691b7fdde1b8abafa4c4a5025e6bfa44f48b9.tar.gz cpython-28a691b7fdde1b8abafa4c4a5025e6bfa44f48b9.tar.bz2 | |
PEP 3147
Diffstat (limited to 'Lib/test/test_pkgimport.py')
| -rw-r--r-- | Lib/test/test_pkgimport.py | 28 |
1 files changed, 15 insertions, 13 deletions
diff --git a/Lib/test/test_pkgimport.py b/Lib/test/test_pkgimport.py index a9a475c..eab66fb 100644 --- a/Lib/test/test_pkgimport.py +++ b/Lib/test/test_pkgimport.py @@ -1,5 +1,12 @@ -import os, sys, string, random, tempfile, unittest - +import os +import sys +import shutil +import string +import random +import tempfile +import unittest + +from imp import cache_from_source from test.support import run_unittest class TestImport(unittest.TestCase): @@ -26,22 +33,17 @@ class TestImport(unittest.TestCase): self.module_path = os.path.join(self.package_dir, 'foo.py') def tearDown(self): - for file in os.listdir(self.package_dir): - os.remove(os.path.join(self.package_dir, file)) - os.rmdir(self.package_dir) - os.rmdir(self.test_dir) + shutil.rmtree(self.test_dir) self.assertNotEqual(sys.path.count(self.test_dir), 0) sys.path.remove(self.test_dir) self.remove_modules() def rewrite_file(self, contents): - for extension in "co": - compiled_path = self.module_path + extension - if os.path.exists(compiled_path): - os.remove(compiled_path) - f = open(self.module_path, 'w') - f.write(contents) - f.close() + compiled_path = cache_from_source(self.module_path) + if os.path.exists(compiled_path): + os.remove(compiled_path) + with open(self.module_path, 'w') as f: + f.write(contents) def test_package_import__semantics(self): |
