|
1 | 1 | import unittest
|
2 | 2 | import os
|
| 3 | +import contextlib |
3 | 4 |
|
4 |
| -from test.support.warnings_helper import ignore_warnings, check_warnings |
| 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 | 10 |
|
6 | 11 | import importlib_resources as resources
|
7 | 12 |
|
@@ -158,16 +163,17 @@ def test_contents(self):
|
158 | 163 | set(c),
|
159 | 164 | {'utf-8.file', 'utf-16.file', 'binary.file', 'subdirectory'},
|
160 | 165 | )
|
161 |
| - with ( |
162 |
| - self.assertRaises(OSError), |
163 |
| - check_warnings((".*contents.*", DeprecationWarning)), |
164 |
| - ): |
| 166 | + with contextlib.ExitStack() as cm: |
| 167 | + cm.enter_context(self.assertRaises(OSError)) |
| 168 | + cm.enter_context(check_warnings((".*contents.*", DeprecationWarning))) |
| 169 | + |
165 | 170 | list(resources.contents(self.anchor01, 'utf-8.file'))
|
| 171 | + |
166 | 172 | for path_parts in self._gen_resourcetxt_path_parts():
|
167 |
| - with ( |
168 |
| - self.assertRaises(OSError), |
169 |
| - check_warnings((".*contents.*", DeprecationWarning)), |
170 |
| - ): |
| 173 | + with contextlib.ExitStack() as cm: |
| 174 | + cm.enter_context(self.assertRaises(OSError)) |
| 175 | + cm.enter_context(check_warnings((".*contents.*", DeprecationWarning))) |
| 176 | + |
171 | 177 | list(resources.contents(self.anchor01, *path_parts))
|
172 | 178 | with check_warnings((".*contents.*", DeprecationWarning)):
|
173 | 179 | c = resources.contents(self.anchor01, 'subdirectory')
|
|
0 commit comments