summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_pkgutil.py
diff options
context:
space:
mode:
Diffstat (limited to 'Lib/test/test_pkgutil.py')
-rw-r--r--Lib/test/test_pkgutil.py39
1 files changed, 21 insertions, 18 deletions
diff --git a/Lib/test/test_pkgutil.py b/Lib/test/test_pkgutil.py
index 9026270..6fcd726 100644
--- a/Lib/test/test_pkgutil.py
+++ b/Lib/test/test_pkgutil.py
@@ -1,6 +1,6 @@
from pathlib import Path
from test.support.import_helper import unload, CleanImport
-from test.support.warnings_helper import check_warnings
+from test.support.warnings_helper import check_warnings, ignore_warnings
import unittest
import sys
import importlib
@@ -535,25 +535,18 @@ class ImportlibMigrationTests(unittest.TestCase):
# PEP 302 emulation in this module is in the process of being
# deprecated in favour of importlib proper
- def test_get_loader_avoids_emulation(self):
- with check_warnings() as w:
- self.assertIsNotNone(pkgutil.get_loader("sys"))
- self.assertIsNotNone(pkgutil.get_loader("os"))
- self.assertIsNotNone(pkgutil.get_loader("test.support"))
- self.assertEqual(len(w.warnings), 0)
-
@unittest.skipIf(__name__ == '__main__', 'not compatible with __main__')
+ @ignore_warnings(category=DeprecationWarning)
def test_get_loader_handles_missing_loader_attribute(self):
global __loader__
this_loader = __loader__
del __loader__
try:
- with check_warnings() as w:
- self.assertIsNotNone(pkgutil.get_loader(__name__))
- self.assertEqual(len(w.warnings), 0)
+ self.assertIsNotNone(pkgutil.get_loader(__name__))
finally:
__loader__ = this_loader
+ @ignore_warnings(category=DeprecationWarning)
def test_get_loader_handles_missing_spec_attribute(self):
name = 'spam'
mod = type(sys)(name)
@@ -563,6 +556,7 @@ class ImportlibMigrationTests(unittest.TestCase):
loader = pkgutil.get_loader(name)
self.assertIsNone(loader)
+ @ignore_warnings(category=DeprecationWarning)
def test_get_loader_handles_spec_attribute_none(self):
name = 'spam'
mod = type(sys)(name)
@@ -572,6 +566,7 @@ class ImportlibMigrationTests(unittest.TestCase):
loader = pkgutil.get_loader(name)
self.assertIsNone(loader)
+ @ignore_warnings(category=DeprecationWarning)
def test_get_loader_None_in_sys_modules(self):
name = 'totally bogus'
sys.modules[name] = None
@@ -581,18 +576,26 @@ class ImportlibMigrationTests(unittest.TestCase):
del sys.modules[name]
self.assertIsNone(loader)
+ def test_get_loader_is_deprecated(self):
+ with check_warnings(
+ (r".*\bpkgutil.get_loader\b.*", DeprecationWarning),
+ ):
+ res = pkgutil.get_loader("sys")
+ self.assertIsNotNone(res)
+
+ def test_find_loader_is_deprecated(self):
+ with check_warnings(
+ (r".*\bpkgutil.find_loader\b.*", DeprecationWarning),
+ ):
+ res = pkgutil.find_loader("sys")
+ self.assertIsNotNone(res)
+
+ @ignore_warnings(category=DeprecationWarning)
def test_find_loader_missing_module(self):
name = 'totally bogus'
loader = pkgutil.find_loader(name)
self.assertIsNone(loader)
- def test_find_loader_avoids_emulation(self):
- with check_warnings() as w:
- self.assertIsNotNone(pkgutil.find_loader("sys"))
- self.assertIsNotNone(pkgutil.find_loader("os"))
- self.assertIsNotNone(pkgutil.find_loader("test.support"))
- self.assertEqual(len(w.warnings), 0)
-
def test_get_importer_avoids_emulation(self):
# We use an illegal path so *none* of the path hooks should fire
with check_warnings() as w: