@@ -755,6 +755,10 @@ def test_improper_input(self):
755755 self .module ._setoption ('ignore::===' )
756756 with self .assertRaisesRegex (self .module ._OptionError , 'Wärning' ):
757757 self .module ._setoption ('ignore::Wärning' )
758+ with self .assertRaisesRegex (self .module ._OptionError , 'message' ):
759+ self .module ._setoption ('ignore:/?/:Warning' )
760+ with self .assertRaisesRegex (self .module ._OptionError , 'module' ):
761+ self .module ._setoption ('ignore::Warning:/?/' )
758762 self .module ._setoption ('error::Warning::0' )
759763 self .assertRaises (UserWarning , self .module .warn , 'convert to error' )
760764
@@ -769,6 +773,31 @@ def test_import_from_module(self):
769773 with self .assertRaises (TestWarning ):
770774 self .module .warn ('test warning' , TestWarning )
771775
776+ def test_message (self ):
777+ # Match prefix, case-insensitive.
778+ with self .module .catch_warnings ():
779+ self .module ._setoption ('error:TEST WARN:UserWarning' )
780+ with self .assertRaises (UserWarning ):
781+ self .module .warn ('Test Warning' )
782+ with self .module .catch_warnings ():
783+ self .module ._setoption (r'error:/TE.*WARN/:UserWarning' )
784+ with self .assertRaises (UserWarning ):
785+ self .module .warn ('Test Warning' )
786+
787+ def test_module (self ):
788+ with self .module .catch_warnings ():
789+ self .module ._setoption (f'error::UserWarning:{ __name__ } ' )
790+ with self .assertRaises (UserWarning ):
791+ self .module .warn ('test warning' )
792+ # Only full match.
793+ self .module ._setoption (f'ignore::UserWarning:{ __name__ [:- 2 ]} ' )
794+ with self .assertRaises (UserWarning ):
795+ self .module .warn ('test warning' )
796+ with self .module .catch_warnings ():
797+ self .module ._setoption (f'error::UserWarning:/{ re .escape (__name__ [:- 2 ])} ./' )
798+ with self .assertRaises (UserWarning ):
799+ self .module .warn ('test warning' )
800+
772801
773802class CWCmdLineTests (WCmdLineTests , unittest .TestCase ):
774803 module = c_warnings
0 commit comments