@@ -124,8 +124,42 @@ def test_buffer(self):
124
124
self .assertWarning (buffer ('a' ), w , expected )
125
125
126
126
127
+ class TestStdlibRemovals (unittest .TestCase ):
128
+
129
+ all_platforms = ('audiodev' ,)
130
+
131
+ def check_removal (self , module_name ):
132
+ """Make sure the specified module, when imported, raises a
133
+ DeprecationWarning and specifies itself in the message."""
134
+ original_module = None
135
+ if module_name in sys .modules :
136
+ original_module = sys .modules [module_name ]
137
+ del sys .modules [module_name ]
138
+ try :
139
+ with catch_warning () as w :
140
+ warnings .filterwarnings ("error" , ".+ removed" ,
141
+ DeprecationWarning )
142
+ try :
143
+ __import__ (module_name , level = 0 )
144
+ except DeprecationWarning as exc :
145
+ self .assert_ (module_name in exc .args [0 ])
146
+ else :
147
+ self .fail ("DeprecationWarning not raised for %s" %
148
+ module_name )
149
+ finally :
150
+ if original_module :
151
+ sys .modules [module_name ] = original_module
152
+
153
+
154
+ def test_platform_independent_removals (self ):
155
+ # Make sure that the modules that are available on all platforms raise
156
+ # the proper DeprecationWarning.
157
+ for module_name in self .all_platforms :
158
+ self .check_removal (module_name )
159
+
160
+
127
161
def test_main ():
128
- run_unittest (TestPy3KWarnings )
162
+ run_unittest (TestPy3KWarnings , TestStdlibRemovals )
129
163
130
164
if __name__ == '__main__' :
131
165
test_main ()
0 commit comments