Skip to content

Commit

Permalink
Merge changes to syncronize the 6.4 release with downstream CPython c…
Browse files Browse the repository at this point in the history
…hanges.

Ref python/cpython#123028.
  • Loading branch information
jaraco committed Aug 14, 2024
2 parents 509cabd + 81ddbef commit 21afd61
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 17 deletions.
3 changes: 3 additions & 0 deletions importlib_resources/tests/compat/py39.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,6 @@
'modules_setup', 'modules_cleanup', 'DirsOnSysPath'
)
os_helper = try_import('os_helper') or from_test_support('temp_dir')
warnings_helper = try_import('warnings_helper') or from_test_support(
'ignore_warnings', 'check_warnings'
)
29 changes: 12 additions & 17 deletions importlib_resources/tests/test_functional.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,8 @@
import unittest
import os
import contextlib
import importlib

try:
from test.support.warnings_helper import ignore_warnings, check_warnings
except ImportError:
# older Python versions
from test.support import ignore_warnings, check_warnings
from .compat.py39 import warnings_helper

import importlib_resources as resources

Expand Down Expand Up @@ -181,32 +176,32 @@ def test_is_resource(self):
self.assertTrue(is_resource(self.anchor02, *path_parts))

def test_contents(self):
with check_warnings((".*contents.*", DeprecationWarning)):
with warnings_helper.check_warnings((".*contents.*", DeprecationWarning)):
c = resources.contents(self.anchor01)
self.assertGreaterEqual(
set(c),
{'utf-8.file', 'utf-16.file', 'binary.file', 'subdirectory'},
)
with contextlib.ExitStack() as cm:
cm.enter_context(self.assertRaises(OSError))
cm.enter_context(check_warnings((".*contents.*", DeprecationWarning)))

with self.assertRaises(OSError), warnings_helper.check_warnings((
".*contents.*",
DeprecationWarning,
)):
list(resources.contents(self.anchor01, 'utf-8.file'))

for path_parts in self._gen_resourcetxt_path_parts():
with contextlib.ExitStack() as cm:
cm.enter_context(self.assertRaises(OSError))
cm.enter_context(check_warnings((".*contents.*", DeprecationWarning)))

with self.assertRaises(OSError), warnings_helper.check_warnings((
".*contents.*",
DeprecationWarning,
)):
list(resources.contents(self.anchor01, *path_parts))
with check_warnings((".*contents.*", DeprecationWarning)):
with warnings_helper.check_warnings((".*contents.*", DeprecationWarning)):
c = resources.contents(self.anchor01, 'subdirectory')
self.assertGreaterEqual(
set(c),
{'binary.file'},
)

@ignore_warnings(category=DeprecationWarning)
@warnings_helper.ignore_warnings(category=DeprecationWarning)
def test_common_errors(self):
for func in (
resources.read_text,
Expand Down

0 comments on commit 21afd61

Please sign in to comment.