<s> import warnings <EOL> import os <EOL> import unittest <EOL> from test import test_support <EOL> class WarningMessage : <EOL> "<STR_LIT>" <EOL> pass <EOL> def showwarning ( message , category , filename , lineno , file = None ) : <EOL> msg . message = str ( message ) <EOL> msg . category = category . __name__ <EOL> msg . filename = os . path . basename ( filename ) <EOL> msg . lineno = lineno <EOL> class TestModule ( unittest . TestCase ) : <EOL> def setUp ( self ) : <EOL> global msg <EOL> msg = WarningMessage ( ) <EOL> self . _filters = warnings . filters [ : ] <EOL> self . _showwarning = warnings . showwarning <EOL> warnings . showwarning = showwarning <EOL> self . ignored = [ w [ <NUM_LIT:2> ] . __name__ for w in self . _filters <EOL> if w [ <NUM_LIT:0> ] == '<STR_LIT:ignore>' and w [ <NUM_LIT:1> ] is None and w [ <NUM_LIT:3> ] is None ] <EOL> def tearDown ( self ) : <EOL> warnings . filters = self . _filters [ : ] <EOL> warnings . showwarning = self . _showwarning <EOL> def test_warn_default_category ( self ) : <EOL> for i in range ( <NUM_LIT:4> ) : <EOL> text = '<STR_LIT>' % i <EOL> warnings . warn ( text ) <EOL> self . assertEqual ( msg . message , text ) <EOL> self . assertEqual ( msg . category , '<STR_LIT>' ) <EOL> def test_warn_specific_category ( self ) : <EOL> text = '<STR_LIT:None>' <EOL> for category in [ DeprecationWarning , FutureWarning , <EOL> PendingDeprecationWarning , RuntimeWarning , <EOL> SyntaxWarning , UserWarning , Warning ] : <EOL> if category . __name__ in self . ignored : <EOL> text = '<STR_LIT>' + category . __name__ <EOL> warnings . warn ( text , category ) <EOL> self . assertNotEqual ( msg . message , text ) <EOL> else : <EOL> text = '<STR_LIT>' % category . __name__ <EOL> warnings . warn ( text , category ) <EOL> self . assertEqual ( msg . message , text ) <EOL> self . assertEqual ( msg . category , category . __name__ ) <EOL> def test_filtering ( self ) : <EOL> warnings . filterwarnings ( "<STR_LIT:error>" , "<STR_LIT>" , Warning , "<STR_LIT>" , <NUM_LIT:0> ) <EOL> self . assertRaises ( UserWarning , warnings . warn , '<STR_LIT>' ) <EOL> warnings . resetwarnings ( ) <EOL> text = '<STR_LIT>' <EOL> warnings . warn ( text ) <EOL> self . assertEqual ( msg . message , text ) <EOL> self . assertEqual ( msg . category , '<STR_LIT>' ) <EOL> warnings . filterwarnings ( "<STR_LIT:ignore>" , "<STR_LIT>" , Warning , "<STR_LIT>" , <NUM_LIT:0> ) <EOL> text = '<STR_LIT>' <EOL> warnings . warn ( text ) <EOL> self . assertNotEqual ( msg . message , text ) <EOL> warnings . resetwarnings ( ) <EOL> warnings . filterwarnings ( "<STR_LIT:error>" , "<STR_LIT>" , Warning , "<STR_LIT>" , <NUM_LIT:0> ) <EOL> self . assertRaises ( UserWarning , warnings . warn , '<STR_LIT>' ) <EOL> text = '<STR_LIT>' <EOL> warnings . warn ( text ) <EOL> self . assertEqual ( msg . message , text ) <EOL> self . assertEqual ( msg . category , '<STR_LIT>' ) <EOL> def test_options ( self ) : <EOL> self . assertRaises ( warnings . _OptionError , <EOL> warnings . _setoption , '<STR_LIT>' ) <EOL> self . assertRaises ( warnings . _OptionError , <EOL> warnings . _setoption , '<STR_LIT>' ) <EOL> self . assertRaises ( warnings . _OptionError , <EOL> warnings . _setoption , '<STR_LIT>' ) <EOL> warnings . _setoption ( '<STR_LIT>' ) <EOL> self . assertRaises ( UserWarning , warnings . warn , '<STR_LIT>' ) <EOL> def test_main ( verbose = None ) : <EOL> if '<STR_LIT>' in globals ( ) : <EOL> del globals ( ) [ '<STR_LIT>' ] <EOL> test_support . run_unittest ( TestModule ) <EOL> if __name__ == "<STR_LIT:__main__>" : <EOL> test_main ( verbose = True ) </s>
