@@ -79,20 +79,19 @@ def test_error(self):
7979 "FilterTests.test_error" )
8080
8181 def test_ignore (self ):
82- with support .catch_warning (self .module ) as w :
82+ with support .catch_warning (module = self .module ) as w :
8383 self .module .resetwarnings ()
8484 self .module .filterwarnings ("ignore" , category = UserWarning )
8585 self .module .warn ("FilterTests.test_ignore" , UserWarning )
86- self .assert_ ( not w . message )
86+ self .assertEquals ( len ( w ), 0 )
8787
8888 def test_always (self ):
89- with support .catch_warning (self .module ) as w :
89+ with support .catch_warning (module = self .module ) as w :
9090 self .module .resetwarnings ()
9191 self .module .filterwarnings ("always" , category = UserWarning )
9292 message = "FilterTests.test_always"
9393 self .module .warn (message , UserWarning )
9494 self .assert_ (message , w .message )
95- w .message = None # Reset.
9695 self .module .warn (message , UserWarning )
9796 self .assert_ (w .message , message )
9897
@@ -107,7 +106,7 @@ def test_default(self):
107106 self .assertEquals (w .message , message )
108107 w .reset ()
109108 elif x == 1 :
110- self .assert_ (not w . message , "unexpected warning: " + str (w ))
109+ self .assert_ (not len ( w ) , "unexpected warning: " + str (w ))
111110 else :
112111 raise ValueError ("loop variant unhandled" )
113112
@@ -120,7 +119,7 @@ def test_module(self):
120119 self .assertEquals (w .message , message )
121120 w .reset ()
122121 self .module .warn (message , UserWarning )
123- self .assert_ (not w . message , "unexpected message: " + str (w ))
122+ self .assert_ (not len ( w ) , "unexpected message: " + str (w ))
124123
125124 def test_once (self ):
126125 with support .catch_warning (self .module ) as w :
@@ -133,10 +132,10 @@ def test_once(self):
133132 w .reset ()
134133 self .module .warn_explicit (message , UserWarning , "test_warnings.py" ,
135134 13 )
136- self .assert_ ( not w . message )
135+ self .assertEquals ( len ( w ), 0 )
137136 self .module .warn_explicit (message , UserWarning , "test_warnings2.py" ,
138137 42 )
139- self .assert_ ( not w . message )
138+ self .assertEquals ( len ( w ), 0 )
140139
141140 def test_inheritance (self ):
142141 with support .catch_warning (self .module ) as w :
@@ -156,7 +155,7 @@ def test_ordering(self):
156155 self .module .warn ("FilterTests.test_ordering" , UserWarning )
157156 except UserWarning :
158157 self .fail ("order handling for actions failed" )
159- self .assert_ ( not w . message )
158+ self .assertEquals ( len ( w ), 0 )
160159
161160 def test_filterwarnings (self ):
162161 # Test filterwarnings().
@@ -317,7 +316,6 @@ def test_warn_explicit_type_errors(self):
317316 None , Warning , None , 1 , registry = 42 )
318317
319318
320-
321319class CWarnTests (BaseTest , WarnTests ):
322320 module = c_warnings
323321
@@ -377,7 +375,7 @@ def test_onceregistry(self):
377375 self .failUnlessEqual (w .message , message )
378376 w .reset ()
379377 self .module .warn_explicit (message , UserWarning , "file" , 42 )
380- self .assert_ ( not w . message )
378+ self .assertEquals ( len ( w ), 0 )
381379 # Test the resetting of onceregistry.
382380 self .module .onceregistry = {}
383381 __warningregistry__ = {}
@@ -388,7 +386,7 @@ def test_onceregistry(self):
388386 del self .module .onceregistry
389387 __warningregistry__ = {}
390388 self .module .warn_explicit (message , UserWarning , "file" , 42 )
391- self .failUnless ( not w . message )
389+ self .assertEquals ( len ( w ), 0 )
392390 finally :
393391 self .module .onceregistry = original_registry
394392
@@ -487,45 +485,45 @@ class CWarningsDisplayTests(BaseTest, WarningsDisplayTests):
487485class PyWarningsDisplayTests (BaseTest , WarningsDisplayTests ):
488486 module = py_warnings
489487
490- class WarningsSupportTests (object ):
491- """Test the warning tools from test support module"""
488+ class CatchWarningTests (BaseTest ):
492489
493- def test_catch_warning_restore (self ):
490+ """Test catch_warnings()."""
491+
492+ def test_catch_warnings_restore (self ):
494493 wmod = self .module
495494 orig_filters = wmod .filters
496495 orig_showwarning = wmod .showwarning
497- with support .catch_warning (wmod ):
496+ with support .catch_warning (module = wmod ):
498497 wmod .filters = wmod .showwarning = object ()
499498 self .assert_ (wmod .filters is orig_filters )
500499 self .assert_ (wmod .showwarning is orig_showwarning )
501- with support .catch_warning (wmod , record = False ):
500+ with support .catch_warning (module = wmod , record = False ):
502501 wmod .filters = wmod .showwarning = object ()
503502 self .assert_ (wmod .filters is orig_filters )
504503 self .assert_ (wmod .showwarning is orig_showwarning )
505504
506- def test_catch_warning_recording (self ):
505+ def test_catch_warnings_recording (self ):
507506 wmod = self .module
508- with support .catch_warning (wmod ) as w :
509- self .assertEqual (w . warnings , [])
507+ with support .catch_warning (module = wmod ) as w :
508+ self .assertEqual (w , [])
510509 wmod .simplefilter ("always" )
511510 wmod .warn ("foo" )
512511 self .assertEqual (str (w .message ), "foo" )
513512 wmod .warn ("bar" )
514513 self .assertEqual (str (w .message ), "bar" )
515- self .assertEqual (str (w . warnings [0 ].message ), "foo" )
516- self .assertEqual (str (w . warnings [1 ].message ), "bar" )
514+ self .assertEqual (str (w [0 ].message ), "foo" )
515+ self .assertEqual (str (w [1 ].message ), "bar" )
517516 w .reset ()
518- self .assertEqual (w . warnings , [])
517+ self .assertEqual (w , [])
519518 orig_showwarning = wmod .showwarning
520- with support .catch_warning (wmod , record = False ) as w :
519+ with support .catch_warning (module = wmod , record = False ) as w :
521520 self .assert_ (w is None )
522521 self .assert_ (wmod .showwarning is orig_showwarning )
523522
524-
525- class CWarningsSupportTests (BaseTest , WarningsSupportTests ):
523+ class CCatchWarningTests (CatchWarningTests ):
526524 module = c_warnings
527525
528- class PyWarningsSupportTests ( BaseTest , WarningsSupportTests ):
526+ class PyCatchWarningTests ( CatchWarningTests ):
529527 module = py_warnings
530528
531529
@@ -539,7 +537,7 @@ def test_main():
539537 CWCmdLineTests , PyWCmdLineTests ,
540538 _WarningsTests ,
541539 CWarningsDisplayTests , PyWarningsDisplayTests ,
542- CWarningsSupportTests , PyWarningsSupportTests ,
540+ CCatchWarningTests , PyCatchWarningTests ,
543541 )
544542
545543
0 commit comments