<s> import unittest <EOL> import warnings <EOL> import sys <EOL> from test import test_support <EOL> class TestSpecifics ( unittest . TestCase ) : <EOL> def test_debug_assignment ( self ) : <EOL> self . assertRaises ( SyntaxError , compile , '<STR_LIT>' , '<STR_LIT:?>' , '<STR_LIT>' ) <EOL> import __builtin__ <EOL> prev = __builtin__ . __debug__ <EOL> setattr ( __builtin__ , '<STR_LIT>' , '<STR_LIT>' ) <EOL> setattr ( __builtin__ , '<STR_LIT>' , prev ) <EOL> def test_argument_handling ( self ) : <EOL> self . assertRaises ( SyntaxError , eval , '<STR_LIT>' ) <EOL> self . assertRaises ( SyntaxError , eval , '<STR_LIT>' ) <EOL> self . assertRaises ( SyntaxError , eval , '<STR_LIT>' ) <EOL> try : <EOL> exec '<STR_LIT>' <EOL> self . fail ( "<STR_LIT>" ) <EOL> except SyntaxError : <EOL> pass <EOL> try : <EOL> exec '<STR_LIT>' <EOL> self . fail ( "<STR_LIT>" ) <EOL> except SyntaxError : <EOL> pass <EOL> try : <EOL> exec '<STR_LIT>' <EOL> self . fail ( "<STR_LIT>" ) <EOL> except SyntaxError : <EOL> pass <EOL> def test_syntax_error ( self ) : <EOL> self . assertRaises ( SyntaxError , compile , "<STR_LIT>" , "<STR_LIT:filename>" , "<STR_LIT>" ) <EOL> def test_none_keyword_arg ( self ) : <EOL> self . assertRaises ( SyntaxError , compile , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) <EOL> def test_duplicate_global_local ( self ) : <EOL> try : <EOL> exec '<STR_LIT>' <EOL> self . fail ( "<STR_LIT>" ) <EOL> except SyntaxError : <EOL> pass <EOL> def test_exec_with_general_mapping_for_locals ( self ) : <EOL> class M : <EOL> "<STR_LIT>" <EOL> def __getitem__ ( self , key ) : <EOL> if key == '<STR_LIT:a>' : <EOL> return <NUM_LIT:12> <EOL> raise KeyError <EOL> def __setitem__ ( self , key , value ) : <EOL> self . results = ( key , value ) <EOL> def keys ( self ) : <EOL> return list ( '<STR_LIT>' ) <EOL> m = M ( ) <EOL> g = globals ( ) <EOL> exec '<STR_LIT>' in g , m <EOL> self . assertEqual ( m . results , ( '<STR_LIT:z>' , <NUM_LIT:12> ) ) <EOL> try : <EOL> exec '<STR_LIT>' in g , m <EOL> except NameError : <EOL> pass <EOL> else : <EOL> self . fail ( '<STR_LIT>' ) <EOL> exec '<STR_LIT>' in g , m <EOL> self . assertEqual ( m . results , ( '<STR_LIT:z>' , list ( '<STR_LIT>' ) ) ) <EOL> exec '<STR_LIT>' in g , m <EOL> self . assertEqual ( m . results , ( '<STR_LIT:z>' , g ) ) <EOL> exec '<STR_LIT>' in g , m <EOL> self . assertEqual ( m . results , ( '<STR_LIT:z>' , m ) ) <EOL> try : <EOL> exec '<STR_LIT>' in m <EOL> except TypeError : <EOL> pass <EOL> else : <EOL> self . fail ( '<STR_LIT>' ) <EOL> class A : <EOL> "<STR_LIT>" <EOL> pass <EOL> m = A ( ) <EOL> try : <EOL> exec '<STR_LIT>' in g , m <EOL> except TypeError : <EOL> pass <EOL> else : <EOL> self . fail ( '<STR_LIT>' ) <EOL> class D ( dict ) : <EOL> def __getitem__ ( self , key ) : <EOL> if key == '<STR_LIT:a>' : <EOL> return <NUM_LIT:12> <EOL> return dict . __getitem__ ( self , key ) <EOL> d = D ( ) <EOL> exec '<STR_LIT>' in g , d <EOL> self . assertEqual ( d [ '<STR_LIT:z>' ] , <NUM_LIT:12> ) <EOL> def test_extended_arg ( self ) : <EOL> longexpr = '<STR_LIT>' + '<STR_LIT>' * <NUM_LIT> <EOL> code = '''<STR_LIT>''' % ( ( longexpr , ) * <NUM_LIT:10> ) <EOL> exec code <EOL> self . assertEqual ( f ( <NUM_LIT:5> ) , <NUM_LIT:0> ) <EOL> def test_complex_args ( self ) : <EOL> def comp_args ( ( a , b ) ) : <EOL> return a , b <EOL> self . assertEqual ( comp_args ( ( <NUM_LIT:1> , <NUM_LIT:2> ) ) , ( <NUM_LIT:1> , <NUM_LIT:2> ) ) <EOL> def comp_args ( ( a , b ) = ( <NUM_LIT:3> , <NUM_LIT:4> ) ) : <EOL> return a , b <EOL> self . assertEqual ( comp_args ( ( <NUM_LIT:1> , <NUM_LIT:2> ) ) , ( <NUM_LIT:1> , <NUM_LIT:2> ) ) <EOL> self . assertEqual ( comp_args ( ) , ( <NUM_LIT:3> , <NUM_LIT:4> ) ) <EOL> def comp_args ( a , ( b , c ) ) : <EOL> return a , b , c <EOL> self . assertEqual ( comp_args ( <NUM_LIT:1> , ( <NUM_LIT:2> , <NUM_LIT:3> ) ) , ( <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> ) ) <EOL> def comp_args ( a = <NUM_LIT:2> , ( b , c ) = ( <NUM_LIT:3> , <NUM_LIT:4> ) ) : <EOL> return a , b , c <EOL> self . assertEqual ( comp_args ( <NUM_LIT:1> , ( <NUM_LIT:2> , <NUM_LIT:3> ) ) , ( <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> ) ) <EOL> self . assertEqual ( comp_args ( ) , ( <NUM_LIT:2> , <NUM_LIT:3> , <NUM_LIT:4> ) ) <EOL> def test_argument_order ( self ) : <EOL> try : <EOL> exec '<STR_LIT>' <EOL> self . fail ( "<STR_LIT>" ) <EOL> except SyntaxError : <EOL> pass <EOL> def test_float_literals ( self ) : <EOL> self . assertRaises ( SyntaxError , eval , "<STR_LIT>" ) <EOL> self . assertRaises ( SyntaxError , eval , "<STR_LIT>" ) <EOL> self . assertRaises ( SyntaxError , eval , "<STR_LIT>" ) <EOL> self . assertRaises ( SyntaxError , eval , "<STR_LIT>" ) <EOL> def test_indentation ( self ) : <EOL> s = """<STR_LIT>""" <EOL> compile ( s , "<STR_LIT>" , "<STR_LIT>" ) <EOL> def test_leading_newlines ( self ) : <EOL> s256 = "<STR_LIT>" . join ( [ "<STR_LIT:\n>" ] * <NUM_LIT> + [ "<STR_LIT>" ] ) <EOL> co = compile ( s256 , '<STR_LIT>' , '<STR_LIT>' ) <EOL> self . assertEqual ( co . co_firstlineno , <NUM_LIT> ) <EOL> self . assertEqual ( co . co_lnotab , '<STR_LIT>' ) <EOL> def test_literals_with_leading_zeroes ( self ) : <EOL> for arg in [ "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , <EOL> "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ] : <EOL> self . assertRaises ( SyntaxError , eval , arg ) <EOL> self . assertEqual ( eval ( "<STR_LIT>" ) , <NUM_LIT> ) <EOL> self . assertEqual ( eval ( "<STR_LIT>" ) , <NUM_LIT> ) <EOL> self . assertEqual ( eval ( "<STR_LIT>" ) , <NUM_LIT> ) <EOL> self . assertEqual ( eval ( "<STR_LIT>" ) , <NUM_LIT:255> ) <EOL> self . assertEqual ( eval ( "<STR_LIT>" ) , <NUM_LIT:255> ) <EOL> self . assertEqual ( eval ( "<STR_LIT>" ) , <NUM_LIT:255> ) <EOL> self . assertEqual ( eval ( "<STR_LIT>" ) , <NUM_LIT> ) <EOL> self . assertEqual ( eval ( "<STR_LIT>" ) , <NUM_LIT> ) <EOL> self . assertEqual ( eval ( "<STR_LIT>" ) , <NUM_LIT> ) <EOL> self . assertEqual ( eval ( "<STR_LIT>" ) , <NUM_LIT> ) <EOL> self . assertEqual ( eval ( "<STR_LIT>" ) , <NUM_LIT:0> ) <EOL> self . assertEqual ( eval ( "<STR_LIT>" ) , <NUM_LIT:0> ) <EOL> self . assertEqual ( eval ( "<STR_LIT>" ) , <NUM_LIT> ) <EOL> self . assertEqual ( eval ( "<STR_LIT>" ) , <NUM_LIT> ) <EOL> self . assertEqual ( eval ( "<STR_LIT>" ) , <NUM_LIT> ) <EOL> self . assertEqual ( eval ( "<STR_LIT>" ) , <NUM_LIT:0> ) <EOL> self . assertEqual ( eval ( "<STR_LIT>" ) , <NUM_LIT:0> ) <EOL> self . assertEqual ( eval ( "<STR_LIT>" ) , <NUM_LIT> ) <EOL> self . assertEqual ( eval ( "<STR_LIT>" ) , <NUM_LIT> ) <EOL> self . assertEqual ( eval ( "<STR_LIT>" ) , <NUM_LIT> ) <EOL> self . assertEqual ( eval ( "<STR_LIT>" ) , <NUM_LIT> ) <EOL> self . assertEqual ( eval ( "<STR_LIT>" ) , <NUM_LIT> ) <EOL> self . assertEqual ( eval ( "<STR_LIT>" ) , <NUM_LIT:7> ) <EOL> self . assertEqual ( eval ( "<STR_LIT>" ) , <NUM_LIT> ) <EOL> self . assertEqual ( eval ( "<STR_LIT>" ) , <NUM_LIT> ) <EOL> def test_unary_minus ( self ) : <EOL> if sys . maxint == <NUM_LIT> : <EOL> all_one_bits = '<STR_LIT>' <EOL> self . assertEqual ( eval ( all_one_bits ) , <NUM_LIT> L ) <EOL> self . assertEqual ( eval ( "<STR_LIT:->" + all_one_bits ) , - <NUM_LIT> L ) <EOL> elif sys . maxint == <NUM_LIT> : <EOL> all_one_bits = '<STR_LIT>' <EOL> self . assertEqual ( eval ( all_one_bits ) , <NUM_LIT> L ) <EOL> self . assertEqual ( eval ( "<STR_LIT:->" + all_one_bits ) , - <NUM_LIT> L ) <EOL> else : <EOL> self . fail ( "<STR_LIT>" ) <EOL> self . assertTrue ( isinstance ( eval ( "<STR_LIT:%s>" % ( - sys . maxint - <NUM_LIT:1> ) ) , int ) ) <EOL> self . assertTrue ( isinstance ( eval ( "<STR_LIT:%s>" % ( - sys . maxint - <NUM_LIT:2> ) ) , long ) ) <EOL> if sys . maxint == <NUM_LIT> : <EOL> def test_32_63_bit_values ( self ) : <EOL> a = + <NUM_LIT> <EOL> b = - <NUM_LIT> <EOL> c = + <NUM_LIT> <EOL> d = - <NUM_LIT> <EOL> e = + <NUM_LIT> <EOL> f = - <NUM_LIT> <EOL> g = + <NUM_LIT> <EOL> h = - <NUM_LIT> <EOL> for variable in self . test_32_63_bit_values . func_code . co_consts : <EOL> if variable is not None : <EOL> self . assertTrue ( isinstance ( variable , int ) ) <EOL> def test_sequence_unpacking_error ( self ) : <EOL> i , j = ( <NUM_LIT:1> , - <NUM_LIT:1> ) or ( - <NUM_LIT:1> , <NUM_LIT:1> ) <EOL> self . assertEqual ( i , <NUM_LIT:1> ) <EOL> self . assertEqual ( j , - <NUM_LIT:1> ) <EOL> def test_none_assignment ( self ) : <EOL> stmts = [ <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> ] <EOL> for stmt in stmts : <EOL> stmt += "<STR_LIT:\n>" <EOL> self . assertRaises ( SyntaxError , compile , stmt , '<STR_LIT>' , '<STR_LIT>' ) <EOL> self . assertRaises ( SyntaxError , compile , stmt , '<STR_LIT>' , '<STR_LIT>' ) <EOL> def test_import ( self ) : <EOL> succeed = [ <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> ] <EOL> fail = [ <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> ] <EOL> for stmt in succeed : <EOL> compile ( stmt , '<STR_LIT>' , '<STR_LIT>' ) <EOL> for stmt in fail : <EOL> self . assertRaises ( SyntaxError , compile , stmt , '<STR_LIT>' , '<STR_LIT>' ) <EOL> def test_for_distinct_code_objects ( self ) : <EOL> def f ( ) : <EOL> f1 = lambda x = <NUM_LIT:1> : x <EOL> f2 = lambda x = <NUM_LIT:2> : x <EOL> return f1 , f2 <EOL> f1 , f2 = f ( ) <EOL> self . assertNotEqual ( id ( f1 . func_code ) , id ( f2 . func_code ) ) <EOL> def test_unicode_encoding ( self ) : <EOL> code = u"<STR_LIT>" <EOL> self . assertRaises ( SyntaxError , compile , code , "<STR_LIT>" , "<STR_LIT>" ) <EOL> def test_subscripts ( self ) : <EOL> class str_map ( object ) : <EOL> def __init__ ( self ) : <EOL> self . data = { } <EOL> def __getitem__ ( self , key ) : <EOL> return self . data [ str ( key ) ] <EOL> def __setitem__ ( self , key , value ) : <EOL> self . data [ str ( key ) ] = value <EOL> def __delitem__ ( self , key ) : <EOL> del self . data [ str ( key ) ] <EOL> def __contains__ ( self , key ) : <EOL> return str ( key ) in self . data <EOL> d = str_map ( ) <EOL> d [ <NUM_LIT:1> ] = <NUM_LIT:1> <EOL> self . assertEqual ( d [ <NUM_LIT:1> ] , <NUM_LIT:1> ) <EOL> d [ <NUM_LIT:1> ] += <NUM_LIT:1> <EOL> self . assertEqual ( d [ <NUM_LIT:1> ] , <NUM_LIT:2> ) <EOL> del d [ <NUM_LIT:1> ] <EOL> self . assertEqual ( <NUM_LIT:1> in d , False ) <EOL> d [ <NUM_LIT:1> , <NUM_LIT:1> ] = <NUM_LIT:1> <EOL> self . assertEqual ( d [ <NUM_LIT:1> , <NUM_LIT:1> ] , <NUM_LIT:1> ) <EOL> d [ <NUM_LIT:1> , <NUM_LIT:1> ] += <NUM_LIT:1> <EOL> self . assertEqual ( d [ <NUM_LIT:1> , <NUM_LIT:1> ] , <NUM_LIT:2> ) <EOL> del d [ <NUM_LIT:1> , <NUM_LIT:1> ] <EOL> self . assertEqual ( ( <NUM_LIT:1> , <NUM_LIT:1> ) in d , False ) <EOL> d [ <NUM_LIT:1> : <NUM_LIT:2> ] = <NUM_LIT:1> <EOL> self . assertEqual ( d [ <NUM_LIT:1> : <NUM_LIT:2> ] , <NUM_LIT:1> ) <EOL> d [ <NUM_LIT:1> : <NUM_LIT:2> ] += <NUM_LIT:1> <EOL> self . assertEqual ( d [ <NUM_LIT:1> : <NUM_LIT:2> ] , <NUM_LIT:2> ) <EOL> del d [ <NUM_LIT:1> : <NUM_LIT:2> ] <EOL> self . assertEqual ( slice ( <NUM_LIT:1> , <NUM_LIT:2> ) in d , False ) <EOL> d [ <NUM_LIT:1> : <NUM_LIT:2> , <NUM_LIT:1> : <NUM_LIT:2> ] = <NUM_LIT:1> <EOL> self . assertEqual ( d [ <NUM_LIT:1> : <NUM_LIT:2> , <NUM_LIT:1> : <NUM_LIT:2> ] , <NUM_LIT:1> ) <EOL> d [ <NUM_LIT:1> : <NUM_LIT:2> , <NUM_LIT:1> : <NUM_LIT:2> ] += <NUM_LIT:1> <EOL> self . assertEqual ( d [ <NUM_LIT:1> : <NUM_LIT:2> , <NUM_LIT:1> : <NUM_LIT:2> ] , <NUM_LIT:2> ) <EOL> del d [ <NUM_LIT:1> : <NUM_LIT:2> , <NUM_LIT:1> : <NUM_LIT:2> ] <EOL> self . assertEqual ( ( slice ( <NUM_LIT:1> , <NUM_LIT:2> ) , slice ( <NUM_LIT:1> , <NUM_LIT:2> ) ) in d , False ) <EOL> d [ <NUM_LIT:1> : <NUM_LIT:2> : <NUM_LIT:3> ] = <NUM_LIT:1> <EOL> self . assertEqual ( d [ <NUM_LIT:1> : <NUM_LIT:2> : <NUM_LIT:3> ] , <NUM_LIT:1> ) <EOL> d [ <NUM_LIT:1> : <NUM_LIT:2> : <NUM_LIT:3> ] += <NUM_LIT:1> <EOL> self . assertEqual ( d [ <NUM_LIT:1> : <NUM_LIT:2> : <NUM_LIT:3> ] , <NUM_LIT:2> ) <EOL> del d [ <NUM_LIT:1> : <NUM_LIT:2> : <NUM_LIT:3> ] <EOL> self . assertEqual ( slice ( <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> ) in d , False ) <EOL> d [ <NUM_LIT:1> : <NUM_LIT:2> : <NUM_LIT:3> , <NUM_LIT:1> : <NUM_LIT:2> : <NUM_LIT:3> ] = <NUM_LIT:1> <EOL> self . assertEqual ( d [ <NUM_LIT:1> : <NUM_LIT:2> : <NUM_LIT:3> , <NUM_LIT:1> : <NUM_LIT:2> : <NUM_LIT:3> ] , <NUM_LIT:1> ) <EOL> d [ <NUM_LIT:1> : <NUM_LIT:2> : <NUM_LIT:3> , <NUM_LIT:1> : <NUM_LIT:2> : <NUM_LIT:3> ] += <NUM_LIT:1> <EOL> self . assertEqual ( d [ <NUM_LIT:1> : <NUM_LIT:2> : <NUM_LIT:3> , <NUM_LIT:1> : <NUM_LIT:2> : <NUM_LIT:3> ] , <NUM_LIT:2> ) <EOL> del d [ <NUM_LIT:1> : <NUM_LIT:2> : <NUM_LIT:3> , <NUM_LIT:1> : <NUM_LIT:2> : <NUM_LIT:3> ] <EOL> self . assertEqual ( ( slice ( <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> ) , slice ( <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> ) ) in d , False ) <EOL> d [ ... ] = <NUM_LIT:1> <EOL> self . assertEqual ( d [ ... ] , <NUM_LIT:1> ) <EOL> d [ ... ] += <NUM_LIT:1> <EOL> self . assertEqual ( d [ ... ] , <NUM_LIT:2> ) <EOL> del d [ ... ] <EOL> self . assertEqual ( Ellipsis in d , False ) <EOL> d [ ... , ... ] = <NUM_LIT:1> <EOL> self . assertEqual ( d [ ... , ... ] , <NUM_LIT:1> ) <EOL> d [ ... , ... ] += <NUM_LIT:1> <EOL> self . assertEqual ( d [ ... , ... ] , <NUM_LIT:2> ) <EOL> del d [ ... , ... ] <EOL> self . assertEqual ( ( Ellipsis , Ellipsis ) in d , False ) <EOL> def test_main ( ) : <EOL> test_support . run_unittest ( TestSpecifics ) <EOL> if __name__ == "<STR_LIT:__main__>" : <EOL> test_main ( ) </s>
