summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_importlib/resources/util.py
diff options
context:
space:
mode:
Diffstat (limited to 'Lib/test/test_importlib/resources/util.py')
-rw-r--r--Lib/test/test_importlib/resources/util.py51
1 files changed, 18 insertions, 33 deletions
diff --git a/Lib/test/test_importlib/resources/util.py b/Lib/test/test_importlib/resources/util.py
index dbe6ee8..d4bf3e6 100644
--- a/Lib/test/test_importlib/resources/util.py
+++ b/Lib/test/test_importlib/resources/util.py
@@ -4,11 +4,12 @@ import io
import sys
import types
import pathlib
+import contextlib
from . import data01
-from . import zipdata01
from importlib.resources.abc import ResourceReader
-from test.support import import_helper
+from test.support import import_helper, os_helper
+from . import zip as zip_
from importlib.machinery import ModuleSpec
@@ -141,39 +142,23 @@ class CommonTests(metaclass=abc.ABCMeta):
class ZipSetupBase:
- ZIP_MODULE = None
-
- @classmethod
- def setUpClass(cls):
- data_path = pathlib.Path(cls.ZIP_MODULE.__file__)
- data_dir = data_path.parent
- cls._zip_path = str(data_dir / 'ziptestdata.zip')
- sys.path.append(cls._zip_path)
- cls.data = importlib.import_module('ziptestdata')
-
- @classmethod
- def tearDownClass(cls):
- try:
- sys.path.remove(cls._zip_path)
- except ValueError:
- pass
-
- try:
- del sys.path_importer_cache[cls._zip_path]
- del sys.modules[cls.data.__name__]
- except KeyError:
- pass
-
- try:
- del cls.data
- del cls._zip_path
- except AttributeError:
- pass
+ ZIP_MODULE = 'data01'
def setUp(self):
- modules = import_helper.modules_setup()
- self.addCleanup(import_helper.modules_cleanup, *modules)
+ self.fixtures = contextlib.ExitStack()
+ self.addCleanup(self.fixtures.close)
+
+ self.fixtures.enter_context(import_helper.isolated_modules())
+
+ temp_dir = self.fixtures.enter_context(os_helper.temp_dir())
+ modules = pathlib.Path(temp_dir) / 'zipped modules.zip'
+ src_path = pathlib.Path(__file__).parent.joinpath(self.ZIP_MODULE)
+ self.fixtures.enter_context(
+ import_helper.DirsOnSysPath(str(zip_.make_zip_file(src_path, modules)))
+ )
+
+ self.data = importlib.import_module(self.ZIP_MODULE)
class ZipSetup(ZipSetupBase):
- ZIP_MODULE = zipdata01 # type: ignore
+ pass