<s> import unittest <EOL> import sys <EOL> from test . test_support import check_py3k_warnings , CleanImport , run_unittest <EOL> import warnings <EOL> if not sys . py3kwarning : <EOL> raise unittest . SkipTest ( '<STR_LIT>' % __name__ ) <EOL> try : <EOL> from test . test_support import __warningregistry__ as _registry <EOL> except ImportError : <EOL> def check_deprecated_module ( module_name ) : <EOL> return False <EOL> else : <EOL> past_warnings = _registry . keys ( ) <EOL> del _registry <EOL> def check_deprecated_module ( module_name ) : <EOL> """<STR_LIT>""" <EOL> return any ( module_name in msg and '<STR_LIT>' in msg <EOL> and issubclass ( cls , DeprecationWarning ) <EOL> and ( '<STR_LIT>' in msg or '<STR_LIT>' in msg ) <EOL> for ( msg , cls , line ) in past_warnings ) <EOL> def reset_module_registry ( module ) : <EOL> try : <EOL> registry = module . __warningregistry__ <EOL> except AttributeError : <EOL> pass <EOL> else : <EOL> registry . clear ( ) <EOL> class TestPy3KWarnings ( unittest . TestCase ) : <EOL> def assertWarning ( self , _ , warning , expected_message ) : <EOL> self . assertEqual ( str ( warning . message ) , expected_message ) <EOL> def assertNoWarning ( self , _ , recorder ) : <EOL> self . assertEqual ( len ( recorder . warnings ) , <NUM_LIT:0> ) <EOL> def test_backquote ( self ) : <EOL> expected = '<STR_LIT>' <EOL> with check_py3k_warnings ( ( expected , SyntaxWarning ) ) : <EOL> exec "<STR_LIT>" in { } <EOL> def test_paren_arg_names ( self ) : <EOL> expected = '<STR_LIT>' <EOL> def check ( s ) : <EOL> with check_py3k_warnings ( ( expected , SyntaxWarning ) ) : <EOL> exec s in { } <EOL> check ( "<STR_LIT>" ) <EOL> check ( "<STR_LIT>" ) <EOL> check ( "<STR_LIT>" ) <EOL> def test_forbidden_names ( self ) : <EOL> def safe_exec ( expr ) : <EOL> def f ( ** kwargs ) : pass <EOL> exec expr in { '<STR_LIT:f>' : f } <EOL> tests = [ ( "<STR_LIT:True>" , "<STR_LIT>" ) , <EOL> ( "<STR_LIT:False>" , "<STR_LIT>" ) , <EOL> ( "<STR_LIT>" , "<STR_LIT>" ) ] <EOL> with check_py3k_warnings ( ( '<STR_LIT>' , SyntaxWarning ) ) as w : <EOL> for keyword , expected in tests : <EOL> safe_exec ( "<STR_LIT>" . format ( keyword ) ) <EOL> self . assertWarning ( None , w , expected ) <EOL> w . reset ( ) <EOL> try : <EOL> safe_exec ( "<STR_LIT>" . format ( keyword ) ) <EOL> except NameError : <EOL> pass <EOL> self . assertWarning ( None , w , expected ) <EOL> w . reset ( ) <EOL> safe_exec ( "<STR_LIT>" . format ( keyword ) ) <EOL> self . assertWarning ( None , w , expected ) <EOL> w . reset ( ) <EOL> safe_exec ( "<STR_LIT>" . format ( keyword ) ) <EOL> self . assertWarning ( None , w , expected ) <EOL> w . reset ( ) <EOL> safe_exec ( "<STR_LIT>" . format ( keyword ) ) <EOL> self . assertWarning ( None , w , expected ) <EOL> w . reset ( ) <EOL> def test_type_inequality_comparisons ( self ) : <EOL> expected = '<STR_LIT>' <EOL> with check_py3k_warnings ( ) as w : <EOL> self . assertWarning ( int < str , w , expected ) <EOL> w . reset ( ) <EOL> self . assertWarning ( type < object , w , expected ) <EOL> def test_object_inequality_comparisons ( self ) : <EOL> expected = '<STR_LIT>' <EOL> with check_py3k_warnings ( ) as w : <EOL> self . assertWarning ( str < [ ] , w , expected ) <EOL> w . reset ( ) <EOL> self . assertWarning ( object ( ) < ( <NUM_LIT:1> , <NUM_LIT:2> ) , w , expected ) <EOL> def test_dict_inequality_comparisons ( self ) : <EOL> expected = '<STR_LIT>' <EOL> with check_py3k_warnings ( ) as w : <EOL> self . assertWarning ( { } < { <NUM_LIT:2> : <NUM_LIT:3> } , w , expected ) <EOL> w . reset ( ) <EOL> self . assertWarning ( { } <= { } , w , expected ) <EOL> w . reset ( ) <EOL> self . assertWarning ( { } > { <NUM_LIT:2> : <NUM_LIT:3> } , w , expected ) <EOL> w . reset ( ) <EOL> self . assertWarning ( { <NUM_LIT:2> : <NUM_LIT:3> } >= { } , w , expected ) <EOL> def test_cell_inequality_comparisons ( self ) : <EOL> expected = '<STR_LIT>' <EOL> def f ( x ) : <EOL> def g ( ) : <EOL> return x <EOL> return g <EOL> cell0 , = f ( <NUM_LIT:0> ) . func_closure <EOL> cell1 , = f ( <NUM_LIT:1> ) . func_closure <EOL> with check_py3k_warnings ( ) as w : <EOL> self . assertWarning ( cell0 == cell1 , w , expected ) <EOL> w . reset ( ) <EOL> self . assertWarning ( cell0 < cell1 , w , expected ) <EOL> def test_code_inequality_comparisons ( self ) : <EOL> expected = '<STR_LIT>' <EOL> def f ( x ) : <EOL> pass <EOL> def g ( x ) : <EOL> pass <EOL> with check_py3k_warnings ( ) as w : <EOL> self . assertWarning ( f . func_code < g . func_code , w , expected ) <EOL> w . reset ( ) <EOL> self . assertWarning ( f . func_code <= g . func_code , w , expected ) <EOL> w . reset ( ) <EOL> self . assertWarning ( f . func_code >= g . func_code , w , expected ) <EOL> w . reset ( ) <EOL> self . assertWarning ( f . func_code > g . func_code , w , expected ) <EOL> def test_builtin_function_or_method_comparisons ( self ) : <EOL> expected = ( '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> func = eval <EOL> meth = { } . get <EOL> with check_py3k_warnings ( ) as w : <EOL> self . assertWarning ( func < meth , w , expected ) <EOL> w . reset ( ) <EOL> self . assertWarning ( func > meth , w , expected ) <EOL> w . reset ( ) <EOL> self . assertWarning ( meth <= func , w , expected ) <EOL> w . reset ( ) <EOL> self . assertWarning ( meth >= func , w , expected ) <EOL> w . reset ( ) <EOL> self . assertNoWarning ( meth == func , w ) <EOL> self . assertNoWarning ( meth != func , w ) <EOL> lam = lambda x : x <EOL> self . assertNoWarning ( lam == func , w ) <EOL> self . assertNoWarning ( lam != func , w ) <EOL> def test_frame_attributes ( self ) : <EOL> template = "<STR_LIT>" <EOL> f = sys . _getframe ( <NUM_LIT:0> ) <EOL> for attr in ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) : <EOL> expected = template % attr <EOL> with check_py3k_warnings ( ) as w : <EOL> self . assertWarning ( getattr ( f , attr ) , w , expected ) <EOL> w . reset ( ) <EOL> self . assertWarning ( setattr ( f , attr , None ) , w , expected ) <EOL> def test_sort_cmp_arg ( self ) : <EOL> expected = "<STR_LIT>" <EOL> lst = range ( <NUM_LIT:5> ) <EOL> cmp = lambda x , y : - <NUM_LIT:1> <EOL> with check_py3k_warnings ( ) as w : <EOL> self . assertWarning ( lst . sort ( cmp = cmp ) , w , expected ) <EOL> w . reset ( ) <EOL> self . assertWarning ( sorted ( lst , cmp = cmp ) , w , expected ) <EOL> w . reset ( ) <EOL> self . assertWarning ( lst . sort ( cmp ) , w , expected ) <EOL> w . reset ( ) <EOL> self . assertWarning ( sorted ( lst , cmp ) , w , expected ) <EOL> def test_sys_exc_clear ( self ) : <EOL> expected = '<STR_LIT>' <EOL> with check_py3k_warnings ( ) as w : <EOL> self . assertWarning ( sys . exc_clear ( ) , w , expected ) <EOL> def test_methods_members ( self ) : <EOL> expected = '<STR_LIT>' <EOL> class C : <EOL> __methods__ = [ '<STR_LIT:a>' ] <EOL> __members__ = [ '<STR_LIT:b>' ] <EOL> c = C ( ) <EOL> with check_py3k_warnings ( ) as w : <EOL> self . assertWarning ( dir ( c ) , w , expected ) <EOL> def test_softspace ( self ) : <EOL> expected = '<STR_LIT>' <EOL> with file ( __file__ ) as f : <EOL> with check_py3k_warnings ( ) as w : <EOL> self . assertWarning ( f . softspace , w , expected ) <EOL> def set ( ) : <EOL> f . softspace = <NUM_LIT:0> <EOL> with check_py3k_warnings ( ) as w : <EOL> self . assertWarning ( set ( ) , w , expected ) <EOL> def test_slice_methods ( self ) : <EOL> class Spam ( object ) : <EOL> def __getslice__ ( self , i , j ) : pass <EOL> def __setslice__ ( self , i , j , what ) : pass <EOL> def __delslice__ ( self , i , j ) : pass <EOL> class Egg : <EOL> def __getslice__ ( self , i , h ) : pass <EOL> def __setslice__ ( self , i , j , what ) : pass <EOL> def __delslice__ ( self , i , j ) : pass <EOL> expected = "<STR_LIT>" <EOL> for obj in ( Spam ( ) , Egg ( ) ) : <EOL> with check_py3k_warnings ( ) as w : <EOL> self . assertWarning ( obj [ <NUM_LIT:1> : <NUM_LIT:2> ] , w , expected . format ( '<STR_LIT>' ) ) <EOL> w . reset ( ) <EOL> del obj [ <NUM_LIT:3> : <NUM_LIT:4> ] <EOL> self . assertWarning ( None , w , expected . format ( '<STR_LIT>' ) ) <EOL> w . reset ( ) <EOL> obj [ <NUM_LIT:4> : <NUM_LIT:5> ] = "<STR_LIT>" <EOL> self . assertWarning ( None , w , expected . format ( '<STR_LIT>' ) ) <EOL> def test_tuple_parameter_unpacking ( self ) : <EOL> expected = "<STR_LIT>" <EOL> with check_py3k_warnings ( ( expected , SyntaxWarning ) ) : <EOL> exec "<STR_LIT>" <EOL> def test_buffer ( self ) : <EOL> expected = '<STR_LIT>' <EOL> with check_py3k_warnings ( ) as w : <EOL> self . assertWarning ( buffer ( '<STR_LIT:a>' ) , w , expected ) <EOL> def test_file_xreadlines ( self ) : <EOL> expected = ( "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> with file ( __file__ ) as f : <EOL> with check_py3k_warnings ( ) as w : <EOL> self . assertWarning ( f . xreadlines ( ) , w , expected ) <EOL> def test_hash_inheritance ( self ) : <EOL> with check_py3k_warnings ( ) as w : <EOL> class WarnOnlyCmp ( object ) : <EOL> def __cmp__ ( self , other ) : pass <EOL> self . assertEqual ( len ( w . warnings ) , <NUM_LIT:0> ) <EOL> w . reset ( ) <EOL> class WarnOnlyEq ( object ) : <EOL> def __eq__ ( self , other ) : pass <EOL> self . assertEqual ( len ( w . warnings ) , <NUM_LIT:1> ) <EOL> self . assertWarning ( None , w , <EOL> "<STR_LIT>" ) <EOL> w . reset ( ) <EOL> class WarnCmpAndEq ( object ) : <EOL> def __cmp__ ( self , other ) : pass <EOL> def __eq__ ( self , other ) : pass <EOL> self . assertEqual ( len ( w . warnings ) , <NUM_LIT:1> ) <EOL> self . assertWarning ( None , w , <EOL> "<STR_LIT>" ) <EOL> w . reset ( ) <EOL> class NoWarningOnlyHash ( object ) : <EOL> def __hash__ ( self ) : pass <EOL> self . assertEqual ( len ( w . warnings ) , <NUM_LIT:0> ) <EOL> class DefinesAllThree ( object ) : <EOL> def __cmp__ ( self , other ) : pass <EOL> def __eq__ ( self , other ) : pass <EOL> def __hash__ ( self ) : pass <EOL> class WarnOnlyCmp ( DefinesAllThree ) : <EOL> def __cmp__ ( self , other ) : pass <EOL> self . assertEqual ( len ( w . warnings ) , <NUM_LIT:0> ) <EOL> w . reset ( ) <EOL> class WarnOnlyEq ( DefinesAllThree ) : <EOL> def __eq__ ( self , other ) : pass <EOL> self . assertEqual ( len ( w . warnings ) , <NUM_LIT:1> ) <EOL> self . assertWarning ( None , w , <EOL> "<STR_LIT>" ) <EOL> w . reset ( ) <EOL> class WarnCmpAndEq ( DefinesAllThree ) : <EOL> def __cmp__ ( self , other ) : pass <EOL> def __eq__ ( self , other ) : pass <EOL> self . assertEqual ( len ( w . warnings ) , <NUM_LIT:1> ) <EOL> self . assertWarning ( None , w , <EOL> "<STR_LIT>" ) <EOL> w . reset ( ) <EOL> class NoWarningOnlyHash ( DefinesAllThree ) : <EOL> def __hash__ ( self ) : pass <EOL> self . assertEqual ( len ( w . warnings ) , <NUM_LIT:0> ) <EOL> def test_operator ( self ) : <EOL> from operator import isCallable , sequenceIncludes <EOL> callable_warn = ( "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> seq_warn = ( "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> with check_py3k_warnings ( ) as w : <EOL> self . assertWarning ( isCallable ( self ) , w , callable_warn ) <EOL> w . reset ( ) <EOL> self . assertWarning ( sequenceIncludes ( range ( <NUM_LIT:3> ) , <NUM_LIT:2> ) , w , seq_warn ) <EOL> class TestStdlibRemovals ( unittest . TestCase ) : <EOL> all_platforms = ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT:user>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) <EOL> inclusive_platforms = { '<STR_LIT>' : ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT:GET>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) , <EOL> '<STR_LIT>' : ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' ) , <EOL> '<STR_LIT>' : ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> } <EOL> optional_modules = ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) <EOL> def check_removal ( self , module_name , optional = False ) : <EOL> """<STR_LIT>""" <EOL> with CleanImport ( module_name ) , warnings . catch_warnings ( ) : <EOL> warnings . filterwarnings ( "<STR_LIT:error>" , "<STR_LIT>" , <EOL> DeprecationWarning , __name__ ) <EOL> warnings . filterwarnings ( "<STR_LIT:error>" , "<STR_LIT>" , <EOL> DeprecationWarning , __name__ ) <EOL> try : <EOL> __import__ ( module_name , level = <NUM_LIT:0> ) <EOL> except DeprecationWarning as exc : <EOL> self . assertIn ( module_name , exc . args [ <NUM_LIT:0> ] , <EOL> "<STR_LIT>" <EOL> % module_name ) <EOL> except ImportError : <EOL> if not optional : <EOL> self . fail ( "<STR_LIT>" <EOL> "<STR_LIT>" . format ( module_name ) ) <EOL> else : <EOL> if not check_deprecated_module ( module_name ) : <EOL> self . fail ( "<STR_LIT>" <EOL> . format ( module_name ) ) <EOL> def test_platform_independent_removals ( self ) : <EOL> for module_name in self . all_platforms : <EOL> self . check_removal ( module_name ) <EOL> def test_platform_specific_removals ( self ) : <EOL> for module_name in self . inclusive_platforms . get ( sys . platform , [ ] ) : <EOL> self . check_removal ( module_name , optional = True ) <EOL> def test_optional_module_removals ( self ) : <EOL> for module_name in self . optional_modules : <EOL> self . check_removal ( module_name , optional = True ) <EOL> def test_os_path_walk ( self ) : <EOL> msg = "<STR_LIT>" <EOL> def dumbo ( where , names , args ) : pass <EOL> for path_mod in ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) : <EOL> mod = __import__ ( path_mod ) <EOL> reset_module_registry ( mod ) <EOL> with check_py3k_warnings ( ) as w : <EOL> mod . walk ( "<STR_LIT>" , dumbo , None ) <EOL> self . assertEqual ( str ( w . message ) , msg ) <EOL> def test_reduce_move ( self ) : <EOL> from operator import add <EOL> reset_module_registry ( unittest . case ) <EOL> with warnings . catch_warnings ( ) : <EOL> warnings . filterwarnings ( "<STR_LIT:error>" , "<STR_LIT>" ) <EOL> self . assertRaises ( DeprecationWarning , reduce , add , range ( <NUM_LIT:10> ) ) <EOL> def test_mutablestring_removal ( self ) : <EOL> import UserString <EOL> reset_module_registry ( UserString ) <EOL> with warnings . catch_warnings ( ) : <EOL> warnings . filterwarnings ( "<STR_LIT:error>" , "<STR_LIT>" , <EOL> DeprecationWarning ) <EOL> self . assertRaises ( DeprecationWarning , UserString . MutableString ) <EOL> def test_main ( ) : <EOL> run_unittest ( TestPy3KWarnings , <EOL> TestStdlibRemovals ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> test_main ( ) </s>
