|
10 | 10 | import os.path
|
11 | 11 | import tempfile
|
12 | 12 | import shutil
|
| 13 | +import warnings |
13 | 14 | import zipfile
|
14 | 15 |
|
15 | 16 | # Note: pkgutil.walk_packages is currently tested in test_runpy. This is
|
@@ -549,22 +550,26 @@ def test_loader_deprecated(self):
|
549 | 550 | with self.check_deprecated():
|
550 | 551 | pkgutil.ImpLoader("", "", "", "")
|
551 | 552 |
|
552 |
| - def test_get_loader_avoids_emulation(self): |
553 |
| - with check_warnings() as w: |
554 |
| - self.assertIsNotNone(pkgutil.get_loader("sys")) |
555 |
| - self.assertIsNotNone(pkgutil.get_loader("os")) |
556 |
| - self.assertIsNotNone(pkgutil.get_loader("test.support")) |
557 |
| - self.assertEqual(len(w.warnings), 0) |
| 553 | + def test_get_loader_is_deprecated(self): |
| 554 | + for module in ["sys", "os", "test.support"]: |
| 555 | + with check_warnings(( |
| 556 | + "`pkgutil.get_loader` is deprecated since Python 3.12; " |
| 557 | + "this function is slated for removal in Python 3.14, " |
| 558 | + "use `importlib.util.find_spec` instead", |
| 559 | + DeprecationWarning, |
| 560 | + )): |
| 561 | + res = pkgutil.get_loader(module) |
| 562 | + self.assertIsNotNone(res) |
558 | 563 |
|
559 | 564 | @unittest.skipIf(__name__ == '__main__', 'not compatible with __main__')
|
560 | 565 | def test_get_loader_handles_missing_loader_attribute(self):
|
561 | 566 | global __loader__
|
562 | 567 | this_loader = __loader__
|
563 | 568 | del __loader__
|
564 | 569 | try:
|
565 |
| - with check_warnings() as w: |
| 570 | + with warnings.catch_warnings(): |
| 571 | + warnings.simplefilter('ignore', DeprecationWarning) |
566 | 572 | self.assertIsNotNone(pkgutil.get_loader(__name__))
|
567 |
| - self.assertEqual(len(w.warnings), 0) |
568 | 573 | finally:
|
569 | 574 | __loader__ = this_loader
|
570 | 575 |
|
@@ -600,12 +605,16 @@ def test_find_loader_missing_module(self):
|
600 | 605 | loader = pkgutil.find_loader(name)
|
601 | 606 | self.assertIsNone(loader)
|
602 | 607 |
|
603 |
| - def test_find_loader_avoids_emulation(self): |
604 |
| - with check_warnings() as w: |
605 |
| - self.assertIsNotNone(pkgutil.find_loader("sys")) |
606 |
| - self.assertIsNotNone(pkgutil.find_loader("os")) |
607 |
| - self.assertIsNotNone(pkgutil.find_loader("test.support")) |
608 |
| - self.assertEqual(len(w.warnings), 0) |
| 608 | + def test_find_loader_is_deprecated(self): |
| 609 | + for module in ["sys", "os", "test.support"]: |
| 610 | + with check_warnings(( |
| 611 | + "`pkgutil.find_loader` is deprecated since Python 3.12; " |
| 612 | + "this function is slated for removal in Python 3.14, " |
| 613 | + "use `importlib.util.find_spec` instead", |
| 614 | + DeprecationWarning, |
| 615 | + )): |
| 616 | + res = pkgutil.find_loader(module) |
| 617 | + self.assertIsNotNone(res) |
609 | 618 |
|
610 | 619 | def test_get_importer_avoids_emulation(self):
|
611 | 620 | # We use an illegal path so *none* of the path hooks should fire
|
|
0 commit comments