Skip to content

Commit 21afd61

Browse files
committed
Merge changes to syncronize the 6.4 release with downstream CPython changes.
Ref python/cpython#123028.
2 parents 509cabd + 81ddbef commit 21afd61

File tree

2 files changed

+15
-17
lines changed

2 files changed

+15
-17
lines changed

importlib_resources/tests/compat/py39.py

+3
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

+12-17
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,8 @@
11
import unittest
22
import os
3-
import contextlib
43
import importlib
54

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
116

127
import importlib_resources as resources
138

@@ -181,32 +176,32 @@ def test_is_resource(self):
181176
self.assertTrue(is_resource(self.anchor02, *path_parts))
182177

183178
def test_contents(self):
184-
with check_warnings((".*contents.*", DeprecationWarning)):
179+
with warnings_helper.check_warnings((".*contents.*", DeprecationWarning)):
185180
c = resources.contents(self.anchor01)
186181
self.assertGreaterEqual(
187182
set(c),
188183
{'utf-8.file', 'utf-16.file', 'binary.file', 'subdirectory'},
189184
)
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+
)):
194189
list(resources.contents(self.anchor01, 'utf-8.file'))
195190

196191
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+
)):
201196
list(resources.contents(self.anchor01, *path_parts))
202-
with check_warnings((".*contents.*", DeprecationWarning)):
197+
with warnings_helper.check_warnings((".*contents.*", DeprecationWarning)):
203198
c = resources.contents(self.anchor01, 'subdirectory')
204199
self.assertGreaterEqual(
205200
set(c),
206201
{'binary.file'},
207202
)
208203

209-
@ignore_warnings(category=DeprecationWarning)
204+
@warnings_helper.ignore_warnings(category=DeprecationWarning)
210205
def test_common_errors(self):
211206
for func in (
212207
resources.read_text,

0 commit comments

Comments
 (0)