PageRenderTime 192ms CodeModel.GetById 112ms app.highlight 71ms RepoModel.GetById 1ms app.codeStats 0ms

/Lib/test/test_warnings.py

http://unladen-swallow.googlecode.com/
Python | 670 lines | 635 code | 26 blank | 9 comment | 11 complexity | 4e5cf5d9c6c69eeeaf6f531be3be1151 MD5 | raw file
  1from contextlib import contextmanager
  2import linecache
  3import os
  4import StringIO
  5import sys
  6import unittest
  7from test import test_support
  8
  9import warning_tests
 10
 11import warnings as original_warnings
 12
 13sys.modules['_warnings'] = 0
 14del sys.modules['warnings']
 15
 16import warnings as py_warnings
 17
 18del sys.modules['_warnings']
 19del sys.modules['warnings']
 20
 21import warnings as c_warnings
 22
 23sys.modules['warnings'] = original_warnings
 24
 25
 26@contextmanager
 27def warnings_state(module):
 28    """Use a specific warnings implementation in warning_tests."""
 29    global __warningregistry__
 30    for to_clear in (sys, warning_tests):
 31        try:
 32            to_clear.__warningregistry__.clear()
 33        except AttributeError:
 34            pass
 35    try:
 36        __warningregistry__.clear()
 37    except NameError:
 38        pass
 39    original_warnings = warning_tests.warnings
 40    try:
 41        warning_tests.warnings = module
 42        yield
 43    finally:
 44        warning_tests.warnings = original_warnings
 45
 46
 47class BaseTest(unittest.TestCase):
 48
 49    """Basic bookkeeping required for testing."""
 50
 51    def setUp(self):
 52        # The __warningregistry__ needs to be in a pristine state for tests
 53        # to work properly.
 54        if '__warningregistry__' in globals():
 55            del globals()['__warningregistry__']
 56        if hasattr(warning_tests, '__warningregistry__'):
 57            del warning_tests.__warningregistry__
 58        if hasattr(sys, '__warningregistry__'):
 59            del sys.__warningregistry__
 60        # The 'warnings' module must be explicitly set so that the proper
 61        # interaction between _warnings and 'warnings' can be controlled.
 62        sys.modules['warnings'] = self.module
 63        super(BaseTest, self).setUp()
 64
 65    def tearDown(self):
 66        sys.modules['warnings'] = original_warnings
 67        super(BaseTest, self).tearDown()
 68
 69
 70class FilterTests(object):
 71
 72    """Testing the filtering functionality."""
 73
 74    def test_error(self):
 75        with original_warnings.catch_warnings(module=self.module) as w:
 76            self.module.resetwarnings()
 77            self.module.filterwarnings("error", category=UserWarning)
 78            self.assertRaises(UserWarning, self.module.warn,
 79                                "FilterTests.test_error")
 80
 81    def test_ignore(self):
 82        with original_warnings.catch_warnings(record=True,
 83                module=self.module) as w:
 84            self.module.resetwarnings()
 85            self.module.filterwarnings("ignore", category=UserWarning)
 86            self.module.warn("FilterTests.test_ignore", UserWarning)
 87            self.assertEquals(len(w), 0)
 88
 89    def test_always(self):
 90        with original_warnings.catch_warnings(record=True,
 91                module=self.module) as w:
 92            self.module.resetwarnings()
 93            self.module.filterwarnings("always", category=UserWarning)
 94            message = "FilterTests.test_always"
 95            self.module.warn(message, UserWarning)
 96            self.assert_(message, w[-1].message)
 97            self.module.warn(message, UserWarning)
 98            self.assert_(w[-1].message, message)
 99
100    def test_default(self):
101        with original_warnings.catch_warnings(record=True,
102                module=self.module) as w:
103            self.module.resetwarnings()
104            self.module.filterwarnings("default", category=UserWarning)
105            message = UserWarning("FilterTests.test_default")
106            for x in xrange(2):
107                self.module.warn(message, UserWarning)
108                if x == 0:
109                    self.assertEquals(w[-1].message, message)
110                    del w[:]
111                elif x == 1:
112                    self.assertEquals(len(w), 0)
113                else:
114                    raise ValueError("loop variant unhandled")
115
116    def test_module(self):
117        with original_warnings.catch_warnings(record=True,
118                module=self.module) as w:
119            self.module.resetwarnings()
120            self.module.filterwarnings("module", category=UserWarning)
121            message = UserWarning("FilterTests.test_module")
122            self.module.warn(message, UserWarning)
123            self.assertEquals(w[-1].message, message)
124            del w[:]
125            self.module.warn(message, UserWarning)
126            self.assertEquals(len(w), 0)
127
128    def test_once(self):
129        with original_warnings.catch_warnings(record=True,
130                module=self.module) as w:
131            self.module.resetwarnings()
132            self.module.filterwarnings("once", category=UserWarning)
133            message = UserWarning("FilterTests.test_once")
134            self.module.warn_explicit(message, UserWarning, "test_warnings.py",
135                                    42)
136            self.assertEquals(w[-1].message, message)
137            del w[:]
138            self.module.warn_explicit(message, UserWarning, "test_warnings.py",
139                                    13)
140            self.assertEquals(len(w), 0)
141            self.module.warn_explicit(message, UserWarning, "test_warnings2.py",
142                                    42)
143            self.assertEquals(len(w), 0)
144
145    def test_inheritance(self):
146        with original_warnings.catch_warnings(module=self.module) as w:
147            self.module.resetwarnings()
148            self.module.filterwarnings("error", category=Warning)
149            self.assertRaises(UserWarning, self.module.warn,
150                                "FilterTests.test_inheritance", UserWarning)
151
152    def test_ordering(self):
153        with original_warnings.catch_warnings(record=True,
154                module=self.module) as w:
155            self.module.resetwarnings()
156            self.module.filterwarnings("ignore", category=UserWarning)
157            self.module.filterwarnings("error", category=UserWarning,
158                                        append=True)
159            del w[:]
160            try:
161                self.module.warn("FilterTests.test_ordering", UserWarning)
162            except UserWarning:
163                self.fail("order handling for actions failed")
164            self.assertEquals(len(w), 0)
165
166    def test_filterwarnings(self):
167        # Test filterwarnings().
168        # Implicitly also tests resetwarnings().
169        with original_warnings.catch_warnings(record=True,
170                module=self.module) as w:
171            self.module.filterwarnings("error", "", Warning, "", 0)
172            self.assertRaises(UserWarning, self.module.warn, 'convert to error')
173
174            self.module.resetwarnings()
175            text = 'handle normally'
176            self.module.warn(text)
177            self.assertEqual(str(w[-1].message), text)
178            self.assert_(w[-1].category is UserWarning)
179
180            self.module.filterwarnings("ignore", "", Warning, "", 0)
181            text = 'filtered out'
182            self.module.warn(text)
183            self.assertNotEqual(str(w[-1].message), text)
184
185            self.module.resetwarnings()
186            self.module.filterwarnings("error", "hex*", Warning, "", 0)
187            self.assertRaises(UserWarning, self.module.warn, 'hex/oct')
188            text = 'nonmatching text'
189            self.module.warn(text)
190            self.assertEqual(str(w[-1].message), text)
191            self.assert_(w[-1].category is UserWarning)
192
193class CFilterTests(BaseTest, FilterTests):
194    module = c_warnings
195
196class PyFilterTests(BaseTest, FilterTests):
197    module = py_warnings
198
199
200class WarnTests(unittest.TestCase):
201
202    """Test warnings.warn() and warnings.warn_explicit()."""
203
204    def test_message(self):
205        with original_warnings.catch_warnings(record=True,
206                module=self.module) as w:
207            for i in range(4):
208                text = 'multi %d' %i  # Different text on each call.
209                self.module.warn(text)
210                self.assertEqual(str(w[-1].message), text)
211                self.assert_(w[-1].category is UserWarning)
212
213    def test_filename(self):
214        with warnings_state(self.module):
215            with original_warnings.catch_warnings(record=True,
216                    module=self.module) as w:
217                warning_tests.inner("spam1")
218                self.assertEqual(os.path.basename(w[-1].filename),
219                                    "warning_tests.py")
220                warning_tests.outer("spam2")
221                self.assertEqual(os.path.basename(w[-1].filename),
222                                    "warning_tests.py")
223
224    def test_stacklevel(self):
225        # Test stacklevel argument
226        # make sure all messages are different, so the warning won't be skipped
227        with warnings_state(self.module):
228            with original_warnings.catch_warnings(record=True,
229                    module=self.module) as w:
230                warning_tests.inner("spam3", stacklevel=1)
231                self.assertEqual(os.path.basename(w[-1].filename),
232                                    "warning_tests.py")
233                warning_tests.outer("spam4", stacklevel=1)
234                self.assertEqual(os.path.basename(w[-1].filename),
235                                    "warning_tests.py")
236
237                warning_tests.inner("spam5", stacklevel=2)
238                self.assertEqual(os.path.basename(w[-1].filename),
239                                    "test_warnings.py")
240                warning_tests.outer("spam6", stacklevel=2)
241                self.assertEqual(os.path.basename(w[-1].filename),
242                                    "warning_tests.py")
243                warning_tests.outer("spam6.5", stacklevel=3)
244                self.assertEqual(os.path.basename(w[-1].filename),
245                                    "test_warnings.py")
246
247                warning_tests.inner("spam7", stacklevel=9999)
248                self.assertEqual(os.path.basename(w[-1].filename),
249                                    "sys")
250
251    def test_missing_filename_not_main(self):
252        # If __file__ is not specified and __main__ is not the module name,
253        # then __file__ should be set to the module name.
254        filename = warning_tests.__file__
255        try:
256            del warning_tests.__file__
257            with warnings_state(self.module):
258                with original_warnings.catch_warnings(record=True,
259                        module=self.module) as w:
260                    warning_tests.inner("spam8", stacklevel=1)
261                    self.assertEqual(w[-1].filename, warning_tests.__name__)
262        finally:
263            warning_tests.__file__ = filename
264
265    def test_missing_filename_main_with_argv(self):
266        # If __file__ is not specified and the caller is __main__ and sys.argv
267        # exists, then use sys.argv[0] as the file.
268        if not hasattr(sys, 'argv'):
269            return
270        filename = warning_tests.__file__
271        module_name = warning_tests.__name__
272        try:
273            del warning_tests.__file__
274            warning_tests.__name__ = '__main__'
275            with warnings_state(self.module):
276                with original_warnings.catch_warnings(record=True,
277                        module=self.module) as w:
278                    warning_tests.inner('spam9', stacklevel=1)
279                    self.assertEqual(w[-1].filename, sys.argv[0])
280        finally:
281            warning_tests.__file__ = filename
282            warning_tests.__name__ = module_name
283
284    def test_missing_filename_main_without_argv(self):
285        # If __file__ is not specified, the caller is __main__, and sys.argv
286        # is not set, then '__main__' is the file name.
287        filename = warning_tests.__file__
288        module_name = warning_tests.__name__
289        argv = sys.argv
290        try:
291            del warning_tests.__file__
292            warning_tests.__name__ = '__main__'
293            del sys.argv
294            with warnings_state(self.module):
295                with original_warnings.catch_warnings(record=True,
296                        module=self.module) as w:
297                    warning_tests.inner('spam10', stacklevel=1)
298                    self.assertEqual(w[-1].filename, '__main__')
299        finally:
300            warning_tests.__file__ = filename
301            warning_tests.__name__ = module_name
302            sys.argv = argv
303
304    def test_missing_filename_main_with_argv_empty_string(self):
305        # If __file__ is not specified, the caller is __main__, and sys.argv[0]
306        # is the empty string, then '__main__ is the file name.
307        # Tests issue 2743.
308        file_name = warning_tests.__file__
309        module_name = warning_tests.__name__
310        argv = sys.argv
311        try:
312            del warning_tests.__file__
313            warning_tests.__name__ = '__main__'
314            sys.argv = ['']
315            with warnings_state(self.module):
316                with original_warnings.catch_warnings(record=True,
317                        module=self.module) as w:
318                    warning_tests.inner('spam11', stacklevel=1)
319                    self.assertEqual(w[-1].filename, '__main__')
320        finally:
321            warning_tests.__file__ = file_name
322            warning_tests.__name__ = module_name
323            sys.argv = argv
324
325    def test_warn_explicit_type_errors(self):
326        # warn_explicit() shoud error out gracefully if it is given objects
327        # of the wrong types.
328        # lineno is expected to be an integer.
329        self.assertRaises(TypeError, self.module.warn_explicit,
330                            None, UserWarning, None, None)
331        # Either 'message' needs to be an instance of Warning or 'category'
332        # needs to be a subclass.
333        self.assertRaises(TypeError, self.module.warn_explicit,
334                            None, None, None, 1)
335        # 'registry' must be a dict or None.
336        self.assertRaises((TypeError, AttributeError),
337                            self.module.warn_explicit,
338                            None, Warning, None, 1, registry=42)
339
340    def test_bad_str(self):
341        # issue 6415
342        # Warnings instance with a bad format string for __str__ should not
343        # trigger a bus error.
344        class BadStrWarning(Warning):
345            """Warning with a bad format string for __str__."""
346            def __str__(self):
347                return ("A bad formatted string %(err)" %
348                        {"err" : "there is no %(err)s"})
349
350        self.assertRaises(ValueError, self.module.warn, BadStrWarning())
351
352
353class CWarnTests(BaseTest, WarnTests):
354    module = c_warnings
355
356class PyWarnTests(BaseTest, WarnTests):
357    module = py_warnings
358
359
360class WCmdLineTests(unittest.TestCase):
361
362    def test_improper_input(self):
363        # Uses the private _setoption() function to test the parsing
364        # of command-line warning arguments
365        with original_warnings.catch_warnings(module=self.module):
366            self.assertRaises(self.module._OptionError,
367                              self.module._setoption, '1:2:3:4:5:6')
368            self.assertRaises(self.module._OptionError,
369                              self.module._setoption, 'bogus::Warning')
370            self.assertRaises(self.module._OptionError,
371                              self.module._setoption, 'ignore:2::4:-5')
372            self.module._setoption('error::Warning::0')
373            self.assertRaises(UserWarning, self.module.warn, 'convert to error')
374
375class CWCmdLineTests(BaseTest, WCmdLineTests):
376    module = c_warnings
377
378class PyWCmdLineTests(BaseTest, WCmdLineTests):
379    module = py_warnings
380
381
382class _WarningsTests(BaseTest):
383
384    """Tests specific to the _warnings module."""
385
386    module = c_warnings
387
388    def test_filter(self):
389        # Everything should function even if 'filters' is not in warnings.
390        with original_warnings.catch_warnings(module=self.module) as w:
391            self.module.filterwarnings("error", "", Warning, "", 0)
392            self.assertRaises(UserWarning, self.module.warn,
393                                'convert to error')
394            del self.module.filters
395            self.assertRaises(UserWarning, self.module.warn,
396                                'convert to error')
397
398    def test_onceregistry(self):
399        # Replacing or removing the onceregistry should be okay.
400        global __warningregistry__
401        message = UserWarning('onceregistry test')
402        try:
403            original_registry = self.module.onceregistry
404            __warningregistry__ = {}
405            with original_warnings.catch_warnings(record=True,
406                    module=self.module) as w:
407                self.module.resetwarnings()
408                self.module.filterwarnings("once", category=UserWarning)
409                self.module.warn_explicit(message, UserWarning, "file", 42)
410                self.failUnlessEqual(w[-1].message, message)
411                del w[:]
412                self.module.warn_explicit(message, UserWarning, "file", 42)
413                self.assertEquals(len(w), 0)
414                # Test the resetting of onceregistry.
415                self.module.onceregistry = {}
416                __warningregistry__ = {}
417                self.module.warn('onceregistry test')
418                self.failUnlessEqual(w[-1].message.args, message.args)
419                # Removal of onceregistry is okay.
420                del w[:]
421                del self.module.onceregistry
422                __warningregistry__ = {}
423                self.module.warn_explicit(message, UserWarning, "file", 42)
424                self.assertEquals(len(w), 0)
425        finally:
426            self.module.onceregistry = original_registry
427
428    def test_showwarning_missing(self):
429        # Test that showwarning() missing is okay.
430        text = 'del showwarning test'
431        with original_warnings.catch_warnings(module=self.module):
432            self.module.filterwarnings("always", category=UserWarning)
433            del self.module.showwarning
434            with test_support.captured_output('stderr') as stream:
435                self.module.warn(text)
436                result = stream.getvalue()
437        self.failUnless(text in result)
438
439    def test_showwarning_not_callable(self):
440        self.module.filterwarnings("always", category=UserWarning)
441        old_showwarning = self.module.showwarning
442        self.module.showwarning = 23
443        try:
444            self.assertRaises(TypeError, self.module.warn, "Warning!")
445        finally:
446            self.module.showwarning = old_showwarning
447            self.module.resetwarnings()
448
449    def test_show_warning_output(self):
450        # With showarning() missing, make sure that output is okay.
451        text = 'test show_warning'
452        with original_warnings.catch_warnings(module=self.module):
453            self.module.filterwarnings("always", category=UserWarning)
454            del self.module.showwarning
455            with test_support.captured_output('stderr') as stream:
456                warning_tests.inner(text)
457                result = stream.getvalue()
458        self.failUnlessEqual(result.count('\n'), 2,
459                             "Too many newlines in %r" % result)
460        first_line, second_line = result.split('\n', 1)
461        expected_file = os.path.splitext(warning_tests.__file__)[0] + '.py'
462        first_line_parts = first_line.rsplit(':', 3)
463        path, line, warning_class, message = first_line_parts
464        line = int(line)
465        self.failUnlessEqual(expected_file, path)
466        self.failUnlessEqual(warning_class, ' ' + UserWarning.__name__)
467        self.failUnlessEqual(message, ' ' + text)
468        expected_line = '  ' + linecache.getline(path, line).strip() + '\n'
469        assert expected_line
470        self.failUnlessEqual(second_line, expected_line)
471
472
473class WarningsDisplayTests(unittest.TestCase):
474
475    """Test the displaying of warnings and the ability to overload functions
476    related to displaying warnings."""
477
478    def test_formatwarning(self):
479        message = "msg"
480        category = Warning
481        file_name = os.path.splitext(warning_tests.__file__)[0] + '.py'
482        line_num = 3
483        file_line = linecache.getline(file_name, line_num).strip()
484        format = "%s:%s: %s: %s\n  %s\n"
485        expect = format % (file_name, line_num, category.__name__, message,
486                            file_line)
487        self.failUnlessEqual(expect, self.module.formatwarning(message,
488                                                category, file_name, line_num))
489        # Test the 'line' argument.
490        file_line += " for the win!"
491        expect = format % (file_name, line_num, category.__name__, message,
492                            file_line)
493        self.failUnlessEqual(expect, self.module.formatwarning(message,
494                                    category, file_name, line_num, file_line))
495
496    def test_showwarning(self):
497        file_name = os.path.splitext(warning_tests.__file__)[0] + '.py'
498        line_num = 3
499        expected_file_line = linecache.getline(file_name, line_num).strip()
500        message = 'msg'
501        category = Warning
502        file_object = StringIO.StringIO()
503        expect = self.module.formatwarning(message, category, file_name,
504                                            line_num)
505        self.module.showwarning(message, category, file_name, line_num,
506                                file_object)
507        self.failUnlessEqual(file_object.getvalue(), expect)
508        # Test 'line' argument.
509        expected_file_line += "for the win!"
510        expect = self.module.formatwarning(message, category, file_name,
511                                            line_num, expected_file_line)
512        file_object = StringIO.StringIO()
513        self.module.showwarning(message, category, file_name, line_num,
514                                file_object, expected_file_line)
515        self.failUnlessEqual(expect, file_object.getvalue())
516
517class CWarningsDisplayTests(BaseTest, WarningsDisplayTests):
518    module = c_warnings
519
520class PyWarningsDisplayTests(BaseTest, WarningsDisplayTests):
521    module = py_warnings
522
523
524class CatchWarningTests(BaseTest):
525
526    """Test catch_warnings()."""
527
528    def test_catch_warnings_restore(self):
529        wmod = self.module
530        orig_filters = wmod.filters
531        orig_showwarning = wmod.showwarning
532        # Ensure both showwarning and filters are restored when recording
533        with wmod.catch_warnings(module=wmod, record=True):
534            wmod.filters = wmod.showwarning = object()
535        self.assert_(wmod.filters is orig_filters)
536        self.assert_(wmod.showwarning is orig_showwarning)
537        # Same test, but with recording disabled
538        with wmod.catch_warnings(module=wmod, record=False):
539            wmod.filters = wmod.showwarning = object()
540        self.assert_(wmod.filters is orig_filters)
541        self.assert_(wmod.showwarning is orig_showwarning)
542
543    def test_catch_warnings_recording(self):
544        wmod = self.module
545        # Ensure warnings are recorded when requested
546        with wmod.catch_warnings(module=wmod, record=True) as w:
547            self.assertEqual(w, [])
548            self.assert_(type(w) is list)
549            wmod.simplefilter("always")
550            wmod.warn("foo")
551            self.assertEqual(str(w[-1].message), "foo")
552            wmod.warn("bar")
553            self.assertEqual(str(w[-1].message), "bar")
554            self.assertEqual(str(w[0].message), "foo")
555            self.assertEqual(str(w[1].message), "bar")
556            del w[:]
557            self.assertEqual(w, [])
558        # Ensure warnings are not recorded when not requested
559        orig_showwarning = wmod.showwarning
560        with wmod.catch_warnings(module=wmod, record=False) as w:
561            self.assert_(w is None)
562            self.assert_(wmod.showwarning is orig_showwarning)
563
564    def test_catch_warnings_reentry_guard(self):
565        wmod = self.module
566        # Ensure catch_warnings is protected against incorrect usage
567        x = wmod.catch_warnings(module=wmod, record=True)
568        self.assertRaises(RuntimeError, x.__exit__)
569        with x:
570            self.assertRaises(RuntimeError, x.__enter__)
571        # Same test, but with recording disabled
572        x = wmod.catch_warnings(module=wmod, record=False)
573        self.assertRaises(RuntimeError, x.__exit__)
574        with x:
575            self.assertRaises(RuntimeError, x.__enter__)
576
577    def test_catch_warnings_defaults(self):
578        wmod = self.module
579        orig_filters = wmod.filters
580        orig_showwarning = wmod.showwarning
581        # Ensure default behaviour is not to record warnings
582        with wmod.catch_warnings(module=wmod) as w:
583            self.assert_(w is None)
584            self.assert_(wmod.showwarning is orig_showwarning)
585            self.assert_(wmod.filters is not orig_filters)
586        self.assert_(wmod.filters is orig_filters)
587        if wmod is sys.modules['warnings']:
588            # Ensure the default module is this one
589            with wmod.catch_warnings() as w:
590                self.assert_(w is None)
591                self.assert_(wmod.showwarning is orig_showwarning)
592                self.assert_(wmod.filters is not orig_filters)
593            self.assert_(wmod.filters is orig_filters)
594
595    def test_check_warnings(self):
596        # Explicit tests for the test_support convenience wrapper
597        wmod = self.module
598        if wmod is sys.modules['warnings']:
599            with test_support.check_warnings() as w:
600                self.assertEqual(w.warnings, [])
601                wmod.simplefilter("always")
602                wmod.warn("foo")
603                self.assertEqual(str(w.message), "foo")
604                wmod.warn("bar")
605                self.assertEqual(str(w.message), "bar")
606                self.assertEqual(str(w.warnings[0].message), "foo")
607                self.assertEqual(str(w.warnings[1].message), "bar")
608                w.reset()
609                self.assertEqual(w.warnings, [])
610
611
612
613class CCatchWarningTests(CatchWarningTests):
614    module = c_warnings
615
616class PyCatchWarningTests(CatchWarningTests):
617    module = py_warnings
618
619
620class ShowwarningDeprecationTests(BaseTest):
621
622    """Test the deprecation of the old warnings.showwarning() API works."""
623
624    @staticmethod
625    def bad_showwarning(message, category, filename, lineno, file=None):
626        pass
627
628    @staticmethod
629    def ok_showwarning(*args):
630        pass
631
632    def test_deprecation(self):
633        # message, category, filename, lineno[, file[, line]]
634        args = ("message", UserWarning, "file name", 42)
635        with original_warnings.catch_warnings(module=self.module):
636            self.module.filterwarnings("error", category=DeprecationWarning)
637            self.module.showwarning = self.bad_showwarning
638            self.assertRaises(DeprecationWarning, self.module.warn_explicit,
639                                *args)
640            self.module.showwarning = self.ok_showwarning
641            try:
642                self.module.warn_explicit(*args)
643            except DeprecationWarning as exc:
644                self.fail('showwarning(*args) should not trigger a '
645                            'DeprecationWarning')
646
647class CShowwarningDeprecationTests(ShowwarningDeprecationTests):
648    module = c_warnings
649
650
651class PyShowwarningDeprecationTests(ShowwarningDeprecationTests):
652    module = py_warnings
653
654
655def test_main():
656    py_warnings.onceregistry.clear()
657    c_warnings.onceregistry.clear()
658    test_support.run_unittest(CFilterTests, PyFilterTests,
659                                CWarnTests, PyWarnTests,
660                                CWCmdLineTests, PyWCmdLineTests,
661                                _WarningsTests,
662                                CWarningsDisplayTests, PyWarningsDisplayTests,
663                                CCatchWarningTests, PyCatchWarningTests,
664                                CShowwarningDeprecationTests,
665                                    PyShowwarningDeprecationTests,
666                             )
667
668
669if __name__ == "__main__":
670    test_main()