<s> """<STR_LIT>""" <EOL> import symtable <EOL> import unittest <EOL> from test import test_support <EOL> TEST_CODE = """<STR_LIT>""" <EOL> def find_block ( block , name ) : <EOL> for ch in block . get_children ( ) : <EOL> if ch . get_name ( ) == name : <EOL> return ch <EOL> class SymtableTest ( unittest . TestCase ) : <EOL> with test_support . check_warnings ( <EOL> ( "<STR_LIT>" , SyntaxWarning ) ) : <EOL> top = symtable . symtable ( TEST_CODE , "<STR_LIT:?>" , "<STR_LIT>" ) <EOL> Mine = find_block ( top , "<STR_LIT>" ) <EOL> a_method = find_block ( Mine , "<STR_LIT>" ) <EOL> spam = find_block ( top , "<STR_LIT>" ) <EOL> internal = find_block ( spam , "<STR_LIT>" ) <EOL> foo = find_block ( top , "<STR_LIT:foo>" ) <EOL> def test_type ( self ) : <EOL> self . assertEqual ( self . top . get_type ( ) , "<STR_LIT>" ) <EOL> self . assertEqual ( self . Mine . get_type ( ) , "<STR_LIT:class>" ) <EOL> self . assertEqual ( self . a_method . get_type ( ) , "<STR_LIT>" ) <EOL> self . assertEqual ( self . spam . get_type ( ) , "<STR_LIT>" ) <EOL> self . assertEqual ( self . internal . get_type ( ) , "<STR_LIT>" ) <EOL> def test_optimized ( self ) : <EOL> self . assertFalse ( self . top . is_optimized ( ) ) <EOL> self . assertFalse ( self . top . has_exec ( ) ) <EOL> self . assertFalse ( self . top . has_import_star ( ) ) <EOL> self . assertTrue ( self . spam . is_optimized ( ) ) <EOL> self . assertFalse ( self . foo . is_optimized ( ) ) <EOL> self . assertTrue ( self . foo . has_exec ( ) ) <EOL> self . assertTrue ( self . foo . has_import_star ( ) ) <EOL> def test_nested ( self ) : <EOL> self . assertFalse ( self . top . is_nested ( ) ) <EOL> self . assertFalse ( self . Mine . is_nested ( ) ) <EOL> self . assertFalse ( self . spam . is_nested ( ) ) <EOL> self . assertTrue ( self . internal . is_nested ( ) ) <EOL> def test_children ( self ) : <EOL> self . assertTrue ( self . top . has_children ( ) ) <EOL> self . assertTrue ( self . Mine . has_children ( ) ) <EOL> self . assertFalse ( self . foo . has_children ( ) ) <EOL> def test_lineno ( self ) : <EOL> self . assertEqual ( self . top . get_lineno ( ) , <NUM_LIT:0> ) <EOL> self . assertEqual ( self . spam . get_lineno ( ) , <NUM_LIT:11> ) <EOL> def test_function_info ( self ) : <EOL> func = self . spam <EOL> self . assertEqual ( sorted ( func . get_parameters ( ) ) , [ "<STR_LIT:a>" , "<STR_LIT:b>" , "<STR_LIT>" , "<STR_LIT>" ] ) <EOL> expected = [ "<STR_LIT:a>" , "<STR_LIT:b>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT:x>" ] <EOL> self . assertEqual ( sorted ( func . get_locals ( ) ) , expected ) <EOL> self . assertEqual ( sorted ( func . get_globals ( ) ) , [ "<STR_LIT:bar>" , "<STR_LIT>" ] ) <EOL> self . assertEqual ( self . internal . get_frees ( ) , ( "<STR_LIT:x>" , ) ) <EOL> def test_globals ( self ) : <EOL> self . assertTrue ( self . spam . lookup ( "<STR_LIT>" ) . is_global ( ) ) <EOL> self . assertFalse ( self . spam . lookup ( "<STR_LIT>" ) . is_declared_global ( ) ) <EOL> self . assertTrue ( self . spam . lookup ( "<STR_LIT:bar>" ) . is_global ( ) ) <EOL> self . assertTrue ( self . spam . lookup ( "<STR_LIT:bar>" ) . is_declared_global ( ) ) <EOL> self . assertFalse ( self . internal . lookup ( "<STR_LIT:x>" ) . is_global ( ) ) <EOL> self . assertFalse ( self . Mine . lookup ( "<STR_LIT>" ) . is_global ( ) ) <EOL> def test_local ( self ) : <EOL> self . assertTrue ( self . spam . lookup ( "<STR_LIT:x>" ) . is_local ( ) ) <EOL> self . assertFalse ( self . internal . lookup ( "<STR_LIT:x>" ) . is_local ( ) ) <EOL> def test_referenced ( self ) : <EOL> self . assertTrue ( self . internal . lookup ( "<STR_LIT:x>" ) . is_referenced ( ) ) <EOL> self . assertTrue ( self . spam . lookup ( "<STR_LIT>" ) . is_referenced ( ) ) <EOL> self . assertFalse ( self . spam . lookup ( "<STR_LIT:x>" ) . is_referenced ( ) ) <EOL> def test_parameters ( self ) : <EOL> for sym in ( "<STR_LIT:a>" , "<STR_LIT>" , "<STR_LIT>" ) : <EOL> self . assertTrue ( self . spam . lookup ( sym ) . is_parameter ( ) ) <EOL> self . assertFalse ( self . spam . lookup ( "<STR_LIT:x>" ) . is_parameter ( ) ) <EOL> def test_symbol_lookup ( self ) : <EOL> self . assertEqual ( len ( self . top . get_identifiers ( ) ) , <EOL> len ( self . top . get_symbols ( ) ) ) <EOL> self . assertRaises ( KeyError , self . top . lookup , "<STR_LIT>" ) <EOL> def test_namespaces ( self ) : <EOL> self . assertTrue ( self . top . lookup ( "<STR_LIT>" ) . is_namespace ( ) ) <EOL> self . assertTrue ( self . Mine . lookup ( "<STR_LIT>" ) . is_namespace ( ) ) <EOL> self . assertTrue ( self . top . lookup ( "<STR_LIT>" ) . is_namespace ( ) ) <EOL> self . assertTrue ( self . spam . lookup ( "<STR_LIT>" ) . is_namespace ( ) ) <EOL> self . assertTrue ( self . top . lookup ( "<STR_LIT>" ) . is_namespace ( ) ) <EOL> self . assertFalse ( self . spam . lookup ( "<STR_LIT:x>" ) . is_namespace ( ) ) <EOL> self . assertTrue ( self . top . lookup ( "<STR_LIT>" ) . get_namespace ( ) is self . spam ) <EOL> ns_test = self . top . lookup ( "<STR_LIT>" ) <EOL> self . assertEqual ( len ( ns_test . get_namespaces ( ) ) , <NUM_LIT:2> ) <EOL> self . assertRaises ( ValueError , ns_test . get_namespace ) <EOL> def test_assigned ( self ) : <EOL> self . assertTrue ( self . spam . lookup ( "<STR_LIT:x>" ) . is_assigned ( ) ) <EOL> self . assertTrue ( self . spam . lookup ( "<STR_LIT:bar>" ) . is_assigned ( ) ) <EOL> self . assertTrue ( self . top . lookup ( "<STR_LIT>" ) . is_assigned ( ) ) <EOL> self . assertTrue ( self . Mine . lookup ( "<STR_LIT>" ) . is_assigned ( ) ) <EOL> self . assertFalse ( self . internal . lookup ( "<STR_LIT:x>" ) . is_assigned ( ) ) <EOL> def test_imported ( self ) : <EOL> self . assertTrue ( self . top . lookup ( "<STR_LIT>" ) . is_imported ( ) ) <EOL> def test_name ( self ) : <EOL> self . assertEqual ( self . top . get_name ( ) , "<STR_LIT>" ) <EOL> self . assertEqual ( self . spam . get_name ( ) , "<STR_LIT>" ) <EOL> self . assertEqual ( self . spam . lookup ( "<STR_LIT:x>" ) . get_name ( ) , "<STR_LIT:x>" ) <EOL> self . assertEqual ( self . Mine . get_name ( ) , "<STR_LIT>" ) <EOL> def test_class_info ( self ) : <EOL> self . assertEqual ( self . Mine . get_methods ( ) , ( '<STR_LIT>' , ) ) <EOL> def test_filename_correct ( self ) : <EOL> def checkfilename ( brokencode ) : <EOL> try : <EOL> symtable . symtable ( brokencode , "<STR_LIT>" , "<STR_LIT>" ) <EOL> except SyntaxError as e : <EOL> self . assertEqual ( e . filename , "<STR_LIT>" ) <EOL> else : <EOL> self . fail ( "<STR_LIT>" % ( brokencode , ) ) <EOL> checkfilename ( "<STR_LIT>" ) <EOL> checkfilename ( "<STR_LIT>" ) <EOL> def test_eval ( self ) : <EOL> symbols = symtable . symtable ( "<STR_LIT>" , "<STR_LIT:?>" , "<STR_LIT>" ) <EOL> def test_single ( self ) : <EOL> symbols = symtable . symtable ( "<STR_LIT>" , "<STR_LIT:?>" , "<STR_LIT>" ) <EOL> def test_exec ( self ) : <EOL> symbols = symtable . symtable ( "<STR_LIT>" , "<STR_LIT:?>" , "<STR_LIT>" ) <EOL> def test_main ( ) : <EOL> test_support . run_unittest ( SymtableTest ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> test_main ( ) </s>
