|
1 | 1 | import sys |
2 | 2 | import unittest |
3 | 3 |
|
4 | | -from contextlib import ExitStack |
| 4 | +from . import fixtures |
5 | 5 | from importlib_metadata import ( |
6 | 6 | PackageNotFoundError, |
7 | 7 | distribution, |
|
11 | 11 | version, |
12 | 12 | ) |
13 | 13 |
|
14 | | -try: |
15 | | - from importlib import resources |
16 | 14 |
|
17 | | - getattr(resources, 'files') |
18 | | - getattr(resources, 'as_file') |
19 | | -except (ImportError, AttributeError): |
20 | | - import importlib_resources as resources # type: ignore |
21 | | - |
22 | | - |
23 | | -class TestZip(unittest.TestCase): |
24 | | - root = 'tests.data' |
25 | | - |
26 | | - def _fixture_on_path(self, filename): |
27 | | - pkg_file = resources.files(self.root).joinpath(filename) |
28 | | - file = self.resources.enter_context(resources.as_file(pkg_file)) |
29 | | - assert file.name.startswith('example-'), file.name |
30 | | - sys.path.insert(0, str(file)) |
31 | | - self.resources.callback(sys.path.pop, 0) |
32 | | - |
33 | | - def setUp(self): |
34 | | - # Find the path to the example-*.whl so we can add it to the front of |
35 | | - # sys.path, where we'll then try to find the metadata thereof. |
36 | | - self.resources = ExitStack() |
37 | | - self.addCleanup(self.resources.close) |
38 | | - self._fixture_on_path('example-21.12-py3-none-any.whl') |
| 15 | +class TestZip(fixtures.ZipFixtures, unittest.TestCase): |
| 16 | + zip_name = 'example-21.12-py3-none-any.whl' |
39 | 17 |
|
40 | 18 | def test_zip_version(self): |
41 | 19 | self.assertEqual(version('example'), '21.12') |
@@ -68,12 +46,7 @@ def test_one_distribution(self): |
68 | 46 |
|
69 | 47 |
|
70 | 48 | class TestEgg(TestZip): |
71 | | - def setUp(self): |
72 | | - # Find the path to the example-*.egg so we can add it to the front of |
73 | | - # sys.path, where we'll then try to find the metadata thereof. |
74 | | - self.resources = ExitStack() |
75 | | - self.addCleanup(self.resources.close) |
76 | | - self._fixture_on_path('example-21.12-py3.6.egg') |
| 49 | + zip_name = 'example-21.12-py3.6.egg' |
77 | 50 |
|
78 | 51 | def test_files(self): |
79 | 52 | for file in files('example'): |
|
0 commit comments