|
1 | 1 | import unittest |
2 | 2 | import os |
3 | | -import contextlib |
4 | 3 | import importlib |
5 | 4 |
|
6 | | -try: |
7 | | - from test.support.warnings_helper import ignore_warnings, check_warnings |
8 | | -except ImportError: |
9 | | - # older Python versions |
10 | | - from test.support import ignore_warnings, check_warnings |
| 5 | +from .compat.py39 import warnings_helper |
11 | 6 |
|
12 | 7 | import importlib_resources as resources |
13 | 8 |
|
@@ -181,32 +176,32 @@ def test_is_resource(self): |
181 | 176 | self.assertTrue(is_resource(self.anchor02, *path_parts)) |
182 | 177 |
|
183 | 178 | def test_contents(self): |
184 | | - with check_warnings((".*contents.*", DeprecationWarning)): |
| 179 | + with warnings_helper.check_warnings((".*contents.*", DeprecationWarning)): |
185 | 180 | c = resources.contents(self.anchor01) |
186 | 181 | self.assertGreaterEqual( |
187 | 182 | set(c), |
188 | 183 | {'utf-8.file', 'utf-16.file', 'binary.file', 'subdirectory'}, |
189 | 184 | ) |
190 | | - with contextlib.ExitStack() as cm: |
191 | | - cm.enter_context(self.assertRaises(OSError)) |
192 | | - cm.enter_context(check_warnings((".*contents.*", DeprecationWarning))) |
193 | | - |
| 185 | + with self.assertRaises(OSError), warnings_helper.check_warnings(( |
| 186 | + ".*contents.*", |
| 187 | + DeprecationWarning, |
| 188 | + )): |
194 | 189 | list(resources.contents(self.anchor01, 'utf-8.file')) |
195 | 190 |
|
196 | 191 | for path_parts in self._gen_resourcetxt_path_parts(): |
197 | | - with contextlib.ExitStack() as cm: |
198 | | - cm.enter_context(self.assertRaises(OSError)) |
199 | | - cm.enter_context(check_warnings((".*contents.*", DeprecationWarning))) |
200 | | - |
| 192 | + with self.assertRaises(OSError), warnings_helper.check_warnings(( |
| 193 | + ".*contents.*", |
| 194 | + DeprecationWarning, |
| 195 | + )): |
201 | 196 | list(resources.contents(self.anchor01, *path_parts)) |
202 | | - with check_warnings((".*contents.*", DeprecationWarning)): |
| 197 | + with warnings_helper.check_warnings((".*contents.*", DeprecationWarning)): |
203 | 198 | c = resources.contents(self.anchor01, 'subdirectory') |
204 | 199 | self.assertGreaterEqual( |
205 | 200 | set(c), |
206 | 201 | {'binary.file'}, |
207 | 202 | ) |
208 | 203 |
|
209 | | - @ignore_warnings(category=DeprecationWarning) |
| 204 | + @warnings_helper.ignore_warnings(category=DeprecationWarning) |
210 | 205 | def test_common_errors(self): |
211 | 206 | for func in ( |
212 | 207 | resources.read_text, |
|
0 commit comments