|
2 | 2 | import os
|
3 | 3 | import contextlib
|
4 | 4 |
|
5 |
| -try: |
6 |
| - from test.support.warnings_helper import ignore_warnings, check_warnings |
7 |
| -except ImportError: |
8 |
| - # older Python versions |
9 |
| - from test.support import ignore_warnings, check_warnings |
| 5 | +from .compat.py39 import warnings_helper |
10 | 6 |
|
11 | 7 | import importlib_resources as resources
|
12 | 8 |
|
@@ -169,32 +165,36 @@ def test_is_resource(self):
|
169 | 165 | self.assertTrue(is_resource(self.anchor02, *path_parts))
|
170 | 166 |
|
171 | 167 | def test_contents(self):
|
172 |
| - with check_warnings((".*contents.*", DeprecationWarning)): |
| 168 | + with warnings_helper.check_warnings((".*contents.*", DeprecationWarning)): |
173 | 169 | c = resources.contents(self.anchor01)
|
174 | 170 | self.assertGreaterEqual(
|
175 | 171 | set(c),
|
176 | 172 | {'utf-8.file', 'utf-16.file', 'binary.file', 'subdirectory'},
|
177 | 173 | )
|
178 | 174 | with contextlib.ExitStack() as cm:
|
179 | 175 | cm.enter_context(self.assertRaises(OSError))
|
180 |
| - cm.enter_context(check_warnings((".*contents.*", DeprecationWarning))) |
| 176 | + cm.enter_context( |
| 177 | + warnings_helper.check_warnings((".*contents.*", DeprecationWarning)) |
| 178 | + ) |
181 | 179 |
|
182 | 180 | list(resources.contents(self.anchor01, 'utf-8.file'))
|
183 | 181 |
|
184 | 182 | for path_parts in self._gen_resourcetxt_path_parts():
|
185 | 183 | with contextlib.ExitStack() as cm:
|
186 | 184 | cm.enter_context(self.assertRaises(OSError))
|
187 |
| - cm.enter_context(check_warnings((".*contents.*", DeprecationWarning))) |
| 185 | + cm.enter_context( |
| 186 | + warnings_helper.check_warnings((".*contents.*", DeprecationWarning)) |
| 187 | + ) |
188 | 188 |
|
189 | 189 | list(resources.contents(self.anchor01, *path_parts))
|
190 |
| - with check_warnings((".*contents.*", DeprecationWarning)): |
| 190 | + with warnings_helper.check_warnings((".*contents.*", DeprecationWarning)): |
191 | 191 | c = resources.contents(self.anchor01, 'subdirectory')
|
192 | 192 | self.assertGreaterEqual(
|
193 | 193 | set(c),
|
194 | 194 | {'binary.file'},
|
195 | 195 | )
|
196 | 196 |
|
197 |
| - @ignore_warnings(category=DeprecationWarning) |
| 197 | + @warnings_helper.ignore_warnings(category=DeprecationWarning) |
198 | 198 | def test_common_errors(self):
|
199 | 199 | for func in (
|
200 | 200 | resources.read_text,
|
|
0 commit comments