https://github.com/python/cpython/commit/27494dd9ad6032c29e273cd7f45c204c00d6512c
commit: 27494dd9ad6032c29e273cd7f45c204c00d6512c
branch: main
author: Thomas Grainger <[email protected]>
committer: brettcannon <[email protected]>
date: 2025-01-16T13:29:16-08:00
summary:

gh-121604: fix warnings in test_importlib.test_abc and 
test_importlib.test_windows (GH-128904)

files:
M Lib/test/test_importlib/test_abc.py
M Lib/test/test_importlib/test_windows.py

diff --git a/Lib/test/test_importlib/test_abc.py 
b/Lib/test/test_importlib/test_abc.py
index 00af2dd712425a..92a77e079e57e7 100644
--- a/Lib/test/test_importlib/test_abc.py
+++ b/Lib/test/test_importlib/test_abc.py
@@ -226,7 +226,15 @@ class ResourceLoaderDefaultsTests(ABCTestHarness):
     SPLIT = make_abc_subclasses(ResourceLoader)
 
     def test_get_data(self):
-        with self.assertRaises(IOError):
+        with (
+            self.assertRaises(IOError),
+            self.assertWarnsRegex(
+                DeprecationWarning,
+                r"importlib\.abc\.ResourceLoader is deprecated in favour of "
+                r"supporting resource loading through importlib\.resources"
+                r"\.abc\.TraversableResources.",
+            ),
+        ):
             self.ins.get_data('/some/path')
 
 
@@ -927,9 +935,19 @@ def get_filename(self, fullname):
 
             def path_stats(self, path):
                 return {'mtime': 1}
-
-        loader = DummySourceLoader()
-        with self.assertWarns(DeprecationWarning):
+        with self.assertWarnsRegex(
+            DeprecationWarning,
+            r"importlib\.abc\.ResourceLoader is deprecated in favour of "
+            r"supporting resource loading through importlib\.resources"
+            r"\.abc\.TraversableResources.",
+        ):
+            loader = DummySourceLoader()
+
+        with self.assertWarnsRegex(
+            DeprecationWarning,
+            r"SourceLoader\.path_mtime is deprecated in favour of "
+            r"SourceLoader\.path_stats\(\)\."
+        ):
             loader.path_mtime('foo.py')
 
 
diff --git a/Lib/test/test_importlib/test_windows.py 
b/Lib/test/test_importlib/test_windows.py
index f32680bdbeb9e3..bef4fb46f859a4 100644
--- a/Lib/test/test_importlib/test_windows.py
+++ b/Lib/test/test_importlib/test_windows.py
@@ -91,23 +91,46 @@ class WindowsRegistryFinderTests:
     test_module = "spamham{}".format(os.getpid())
 
     def test_find_spec_missing(self):
-        spec = self.machinery.WindowsRegistryFinder.find_spec('spam')
+        with self.assertWarnsRegex(
+            DeprecationWarning,
+            r"importlib\.machinery\.WindowsRegistryFinder is deprecated; "
+            r"use site configuration instead\. Future versions of Python may "
+            r"not enable this finder by default\."
+        ):
+            spec = self.machinery.WindowsRegistryFinder.find_spec('spam')
         self.assertIsNone(spec)
 
     def test_module_found(self):
         with setup_module(self.machinery, self.test_module):
-            spec = 
self.machinery.WindowsRegistryFinder.find_spec(self.test_module)
+            with self.assertWarnsRegex(
+                DeprecationWarning,
+                r"importlib\.machinery\.WindowsRegistryFinder is deprecated; "
+                r"use site configuration instead\. Future versions of Python 
may "
+                r"not enable this finder by default\."
+            ):
+                spec = 
self.machinery.WindowsRegistryFinder.find_spec(self.test_module)
             self.assertIsNotNone(spec)
 
     def test_module_not_found(self):
         with setup_module(self.machinery, self.test_module, path="."):
-            spec = 
self.machinery.WindowsRegistryFinder.find_spec(self.test_module)
+            with self.assertWarnsRegex(
+                DeprecationWarning,
+                r"importlib\.machinery\.WindowsRegistryFinder is deprecated; "
+                r"use site configuration instead\. Future versions of Python 
may "
+                r"not enable this finder by default\."
+            ):
+                spec = 
self.machinery.WindowsRegistryFinder.find_spec(self.test_module)
             self.assertIsNone(spec)
 
     def test_raises_deprecation_warning(self):
         # WindowsRegistryFinder is not meant to be instantiated, so the
         # deprecation warning is raised in the 'find_spec' method instead.
-        with self.assertWarns(DeprecationWarning):
+        with self.assertWarnsRegex(
+            DeprecationWarning,
+            r"importlib\.machinery\.WindowsRegistryFinder is deprecated; "
+            r"use site configuration instead\. Future versions of Python may "
+            r"not enable this finder by default\."
+        ):
             self.machinery.WindowsRegistryFinder.find_spec('spam')
 
 (Frozen_WindowsRegistryFinderTests,

_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-checkins.python.org/
Member address: [email protected]

Reply via email to