Skip to content

Commit fb44cbf

Browse files
committed
Extract compatibility import for warnings helper.
1 parent 31de3ca commit fb44cbf

File tree

2 files changed

+13
-10
lines changed

2 files changed

+13
-10
lines changed

importlib_resources/tests/compat/py39.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,6 @@
88
'modules_setup', 'modules_cleanup', 'DirsOnSysPath'
99
)
1010
os_helper = try_import('os_helper') or from_test_support('temp_dir')
11+
warnings_helper = try_import('warnings_helper') or from_test_support(
12+
'ignore_warnings', 'check_warnings'
13+
)

importlib_resources/tests/test_functional.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,7 @@
22
import os
33
import contextlib
44

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
106

117
import importlib_resources as resources
128

@@ -169,32 +165,36 @@ def test_is_resource(self):
169165
self.assertTrue(is_resource(self.anchor02, *path_parts))
170166

171167
def test_contents(self):
172-
with check_warnings((".*contents.*", DeprecationWarning)):
168+
with warnings_helper.check_warnings((".*contents.*", DeprecationWarning)):
173169
c = resources.contents(self.anchor01)
174170
self.assertGreaterEqual(
175171
set(c),
176172
{'utf-8.file', 'utf-16.file', 'binary.file', 'subdirectory'},
177173
)
178174
with contextlib.ExitStack() as cm:
179175
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+
)
181179

182180
list(resources.contents(self.anchor01, 'utf-8.file'))
183181

184182
for path_parts in self._gen_resourcetxt_path_parts():
185183
with contextlib.ExitStack() as cm:
186184
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+
)
188188

189189
list(resources.contents(self.anchor01, *path_parts))
190-
with check_warnings((".*contents.*", DeprecationWarning)):
190+
with warnings_helper.check_warnings((".*contents.*", DeprecationWarning)):
191191
c = resources.contents(self.anchor01, 'subdirectory')
192192
self.assertGreaterEqual(
193193
set(c),
194194
{'binary.file'},
195195
)
196196

197-
@ignore_warnings(category=DeprecationWarning)
197+
@warnings_helper.ignore_warnings(category=DeprecationWarning)
198198
def test_common_errors(self):
199199
for func in (
200200
resources.read_text,

0 commit comments

Comments
 (0)