Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 638ce07

Browse files
committed
Move code from test_importhooks into test_zipimport.
1 parent f15ffe0 commit 638ce07

1 file changed

Lines changed: 25 additions & 1 deletion

File tree

Lib/test/test_zipimport.py

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
import unittest
88

99
from test import support
10-
from test.test_importhooks import ImportHooksBaseTestCase, test_src, test_co
1110

1211
from zipfile import ZipFile, ZipInfo, ZIP_STORED, ZIP_DEFLATED
1312

@@ -17,6 +16,14 @@
1716
import inspect
1817
import io
1918
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")
2027
raise_src = 'def do_raise(): raise TypeError\n'
2128

2229
def make_pyc(co, mtime, size):
@@ -46,6 +53,23 @@ def module_path_to_dotted_name(path):
4653
pyc_ext = ('.pyc' if __debug__ else '.pyo')
4754

4855

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+
4973
class UncompressedZipImportTestCase(ImportHooksBaseTestCase):
5074

5175
compression = ZIP_STORED

0 commit comments

Comments
 (0)