@@ -92,6 +92,16 @@ def test_error(self):
9292 self .assertRaises (UserWarning , self .module .warn ,
9393 "FilterTests.test_error" )
9494
95+ def test_error_after_default (self ):
96+ with original_warnings .catch_warnings (module = self .module ) as w :
97+ self .module .resetwarnings ()
98+ message = "FilterTests.test_ignore_after_default"
99+ def f ():
100+ self .module .warn (message , UserWarning )
101+ f ()
102+ self .module .filterwarnings ("error" , category = UserWarning )
103+ self .assertRaises (UserWarning , f )
104+
95105 def test_ignore (self ):
96106 with original_warnings .catch_warnings (record = True ,
97107 module = self .module ) as w :
@@ -100,6 +110,19 @@ def test_ignore(self):
100110 self .module .warn ("FilterTests.test_ignore" , UserWarning )
101111 self .assertEqual (len (w ), 0 )
102112
113+ def test_ignore_after_default (self ):
114+ with original_warnings .catch_warnings (record = True ,
115+ module = self .module ) as w :
116+ self .module .resetwarnings ()
117+ message = "FilterTests.test_ignore_after_default"
118+ def f ():
119+ self .module .warn (message , UserWarning )
120+ f ()
121+ self .module .filterwarnings ("ignore" , category = UserWarning )
122+ f ()
123+ f ()
124+ self .assertEqual (len (w ), 1 )
125+
103126 def test_always (self ):
104127 with original_warnings .catch_warnings (record = True ,
105128 module = self .module ) as w :
@@ -111,6 +134,26 @@ def test_always(self):
111134 self .module .warn (message , UserWarning )
112135 self .assertTrue (w [- 1 ].message , message )
113136
137+ def test_always_after_default (self ):
138+ with original_warnings .catch_warnings (record = True ,
139+ module = self .module ) as w :
140+ self .module .resetwarnings ()
141+ message = "FilterTests.test_always_after_ignore"
142+ def f ():
143+ self .module .warn (message , UserWarning )
144+ f ()
145+ self .assertEqual (len (w ), 1 )
146+ self .assertEqual (w [- 1 ].message .args [0 ], message )
147+ f ()
148+ self .assertEqual (len (w ), 1 )
149+ self .module .filterwarnings ("always" , category = UserWarning )
150+ f ()
151+ self .assertEqual (len (w ), 2 )
152+ self .assertEqual (w [- 1 ].message .args [0 ], message )
153+ f ()
154+ self .assertEqual (len (w ), 3 )
155+ self .assertEqual (w [- 1 ].message .args [0 ], message )
156+
114157 def test_default (self ):
115158 with original_warnings .catch_warnings (record = True ,
116159 module = self .module ) as w :
@@ -506,7 +549,9 @@ def test_default_action(self):
506549 registry = registry )
507550 self .assertEqual (w [- 1 ].message , message )
508551 self .assertEqual (len (w ), 1 )
509- self .assertEqual (len (registry ), 1 )
552+ # One actual registry key plus the "version" key
553+ self .assertEqual (len (registry ), 2 )
554+ self .assertIn ("version" , registry )
510555 del w [:]
511556 # Test removal.
512557 del self .module .defaultaction
@@ -516,7 +561,7 @@ def test_default_action(self):
516561 registry = registry )
517562 self .assertEqual (w [- 1 ].message , message )
518563 self .assertEqual (len (w ), 1 )
519- self .assertEqual (len (registry ), 1 )
564+ self .assertEqual (len (registry ), 2 )
520565 del w [:]
521566 # Test setting.
522567 self .module .defaultaction = "ignore"
0 commit comments