|
7 | 7 | import unittest |
8 | 8 |
|
9 | 9 | from test import support |
10 | | -from test.test_importhooks import ImportHooksBaseTestCase, test_src, test_co |
11 | 10 |
|
12 | 11 | from zipfile import ZipFile, ZipInfo, ZIP_STORED, ZIP_DEFLATED |
13 | 12 |
|
|
17 | 16 | import inspect |
18 | 17 | import io |
19 | 18 | from traceback import extract_tb, extract_stack, print_tb |
| 19 | + |
| 20 | +test_src = """\ |
| 21 | +def get_name(): |
| 22 | + return __name__ |
| 23 | +def get_file(): |
| 24 | + return __file__ |
| 25 | +""" |
| 26 | +test_co = compile(test_src, "<???>", "exec") |
20 | 27 | raise_src = 'def do_raise(): raise TypeError\n' |
21 | 28 |
|
22 | 29 | def make_pyc(co, mtime, size): |
@@ -46,6 +53,23 @@ def module_path_to_dotted_name(path): |
46 | 53 | pyc_ext = ('.pyc' if __debug__ else '.pyo') |
47 | 54 |
|
48 | 55 |
|
| 56 | +class ImportHooksBaseTestCase(unittest.TestCase): |
| 57 | + |
| 58 | + def setUp(self): |
| 59 | + self.path = sys.path[:] |
| 60 | + self.meta_path = sys.meta_path[:] |
| 61 | + self.path_hooks = sys.path_hooks[:] |
| 62 | + sys.path_importer_cache.clear() |
| 63 | + self.modules_before = support.modules_setup() |
| 64 | + |
| 65 | + def tearDown(self): |
| 66 | + sys.path[:] = self.path |
| 67 | + sys.meta_path[:] = self.meta_path |
| 68 | + sys.path_hooks[:] = self.path_hooks |
| 69 | + sys.path_importer_cache.clear() |
| 70 | + support.modules_cleanup(*self.modules_before) |
| 71 | + |
| 72 | + |
49 | 73 | class UncompressedZipImportTestCase(ImportHooksBaseTestCase): |
50 | 74 |
|
51 | 75 | compression = ZIP_STORED |
|
0 commit comments