Skip to content

Commit 27494dd

Browse files
authored
gh-121604: fix warnings in test_importlib.test_abc and test_importlib.test_windows (GH-128904)
1 parent 211f413 commit 27494dd

File tree

2 files changed

+49
-8
lines changed

2 files changed

+49
-8
lines changed

Lib/test/test_importlib/test_abc.py

+22-4
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,15 @@ class ResourceLoaderDefaultsTests(ABCTestHarness):
226226
SPLIT = make_abc_subclasses(ResourceLoader)
227227

228228
def test_get_data(self):
229-
with self.assertRaises(IOError):
229+
with (
230+
self.assertRaises(IOError),
231+
self.assertWarnsRegex(
232+
DeprecationWarning,
233+
r"importlib\.abc\.ResourceLoader is deprecated in favour of "
234+
r"supporting resource loading through importlib\.resources"
235+
r"\.abc\.TraversableResources.",
236+
),
237+
):
230238
self.ins.get_data('/some/path')
231239

232240

@@ -927,9 +935,19 @@ def get_filename(self, fullname):
927935

928936
def path_stats(self, path):
929937
return {'mtime': 1}
930-
931-
loader = DummySourceLoader()
932-
with self.assertWarns(DeprecationWarning):
938+
with self.assertWarnsRegex(
939+
DeprecationWarning,
940+
r"importlib\.abc\.ResourceLoader is deprecated in favour of "
941+
r"supporting resource loading through importlib\.resources"
942+
r"\.abc\.TraversableResources.",
943+
):
944+
loader = DummySourceLoader()
945+
946+
with self.assertWarnsRegex(
947+
DeprecationWarning,
948+
r"SourceLoader\.path_mtime is deprecated in favour of "
949+
r"SourceLoader\.path_stats\(\)\."
950+
):
933951
loader.path_mtime('foo.py')
934952

935953

Lib/test/test_importlib/test_windows.py

+27-4
Original file line numberDiff line numberDiff line change
@@ -91,23 +91,46 @@ class WindowsRegistryFinderTests:
9191
test_module = "spamham{}".format(os.getpid())
9292

9393
def test_find_spec_missing(self):
94-
spec = self.machinery.WindowsRegistryFinder.find_spec('spam')
94+
with self.assertWarnsRegex(
95+
DeprecationWarning,
96+
r"importlib\.machinery\.WindowsRegistryFinder is deprecated; "
97+
r"use site configuration instead\. Future versions of Python may "
98+
r"not enable this finder by default\."
99+
):
100+
spec = self.machinery.WindowsRegistryFinder.find_spec('spam')
95101
self.assertIsNone(spec)
96102

97103
def test_module_found(self):
98104
with setup_module(self.machinery, self.test_module):
99-
spec = self.machinery.WindowsRegistryFinder.find_spec(self.test_module)
105+
with self.assertWarnsRegex(
106+
DeprecationWarning,
107+
r"importlib\.machinery\.WindowsRegistryFinder is deprecated; "
108+
r"use site configuration instead\. Future versions of Python may "
109+
r"not enable this finder by default\."
110+
):
111+
spec = self.machinery.WindowsRegistryFinder.find_spec(self.test_module)
100112
self.assertIsNotNone(spec)
101113

102114
def test_module_not_found(self):
103115
with setup_module(self.machinery, self.test_module, path="."):
104-
spec = self.machinery.WindowsRegistryFinder.find_spec(self.test_module)
116+
with self.assertWarnsRegex(
117+
DeprecationWarning,
118+
r"importlib\.machinery\.WindowsRegistryFinder is deprecated; "
119+
r"use site configuration instead\. Future versions of Python may "
120+
r"not enable this finder by default\."
121+
):
122+
spec = self.machinery.WindowsRegistryFinder.find_spec(self.test_module)
105123
self.assertIsNone(spec)
106124

107125
def test_raises_deprecation_warning(self):
108126
# WindowsRegistryFinder is not meant to be instantiated, so the
109127
# deprecation warning is raised in the 'find_spec' method instead.
110-
with self.assertWarns(DeprecationWarning):
128+
with self.assertWarnsRegex(
129+
DeprecationWarning,
130+
r"importlib\.machinery\.WindowsRegistryFinder is deprecated; "
131+
r"use site configuration instead\. Future versions of Python may "
132+
r"not enable this finder by default\."
133+
):
111134
self.machinery.WindowsRegistryFinder.find_spec('spam')
112135

113136
(Frozen_WindowsRegistryFinderTests,

0 commit comments

Comments
 (0)