1+ from warnings import catch_warnings
12from .. import abc
23from .. import util
34
78import sys
89import types
910import unittest
11+ import warnings
1012import importlib .util
1113import importlib
1214from test .support .script_helper import assert_python_failure
@@ -20,14 +22,18 @@ def setUp(self):
2022 util .EXTENSIONS .file_path )
2123
2224 def load_module (self , fullname ):
23- return self .loader .load_module (fullname )
25+ with warnings .catch_warnings ():
26+ warnings .simplefilter ("ignore" , DeprecationWarning )
27+ return self .loader .load_module (fullname )
2428
2529 def test_load_module_API (self ):
2630 # Test the default argument for load_module().
27- self .loader .load_module ()
28- self .loader .load_module (None )
29- with self .assertRaises (ImportError ):
30- self .load_module ('XXX' )
31+ with warnings .catch_warnings ():
32+ warnings .simplefilter ("ignore" , DeprecationWarning )
33+ self .loader .load_module ()
34+ self .loader .load_module (None )
35+ with self .assertRaises (ImportError ):
36+ self .load_module ('XXX' )
3137
3238 def test_equality (self ):
3339 other = self .machinery .ExtensionFileLoader (util .EXTENSIONS .name ,
@@ -94,6 +100,21 @@ def setUp(self):
94100 self .loader = self .machinery .ExtensionFileLoader (
95101 self .name , self .spec .origin )
96102
103+ def load_module (self ):
104+ '''Load the module from the test extension'''
105+ with warnings .catch_warnings ():
106+ warnings .simplefilter ("ignore" , DeprecationWarning )
107+ return self .loader .load_module (self .name )
108+
109+ def load_module_by_name (self , fullname ):
110+ '''Load a module from the test extension by name'''
111+ origin = self .spec .origin
112+ loader = self .machinery .ExtensionFileLoader (fullname , origin )
113+ spec = importlib .util .spec_from_loader (fullname , loader )
114+ module = importlib .util .module_from_spec (spec )
115+ loader .exec_module (module )
116+ return module
117+
97118 # No extension module as __init__ available for testing.
98119 test_package = None
99120
@@ -157,19 +178,6 @@ def test_try_registration(self):
157178 with self .assertRaises (SystemError ):
158179 module .call_state_registration_func (2 )
159180
160- def load_module (self ):
161- '''Load the module from the test extension'''
162- return self .loader .load_module (self .name )
163-
164- def load_module_by_name (self , fullname ):
165- '''Load a module from the test extension by name'''
166- origin = self .spec .origin
167- loader = self .machinery .ExtensionFileLoader (fullname , origin )
168- spec = importlib .util .spec_from_loader (fullname , loader )
169- module = importlib .util .module_from_spec (spec )
170- loader .exec_module (module )
171- return module
172-
173181 def test_load_submodule (self ):
174182 '''Test loading a simulated submodule'''
175183 module = self .load_module_by_name ('pkg.' + self .name )
0 commit comments