<s> """<STR_LIT>""" <EOL> import unittest <EOL> import __builtin__ <EOL> from copperhead import prelude <EOL> from copperhead . compiler import pltools , pyast , coresyntax as S , rewrites as F , passes as P <EOL> def expr ( text ) : return pyast . expression_from_text ( text ) <EOL> def stmt ( text ) : return pyast . statement_from_text ( text ) <EOL> class ExprParsingTests ( unittest . TestCase ) : <EOL> def setUp ( self ) : pass <EOL> def tearDown ( self ) : pass <EOL> def testLiterals ( self ) : <EOL> self . assertEqual ( str ( expr ( '<STR_LIT:1>' ) ) , '<STR_LIT:1>' ) <EOL> self . assertEqual ( str ( expr ( '<STR_LIT:x>' ) ) , '<STR_LIT:x>' ) <EOL> self . assertEqual ( repr ( expr ( '<STR_LIT:1>' ) ) , "<STR_LIT>" ) <EOL> self . assertEqual ( repr ( expr ( '<STR_LIT:x>' ) ) , "<STR_LIT>" ) <EOL> def testOperators ( self ) : <EOL> self . assertEqual ( str ( expr ( '<STR_LIT>' ) ) , '<STR_LIT>' ) <EOL> self . assertEqual ( str ( expr ( '<STR_LIT>' ) ) , '<STR_LIT>' ) <EOL> self . assertEqual ( str ( expr ( '<STR_LIT>' ) ) , '<STR_LIT>' ) <EOL> self . assertEqual ( str ( expr ( '<STR_LIT>' ) ) , <EOL> '<STR_LIT>' ) <EOL> def testMap ( self ) : <EOL> self . assertEqual ( str ( expr ( '<STR_LIT>' ) ) , '<STR_LIT>' ) <EOL> def testIf ( self ) : <EOL> self . assertEqual ( str ( expr ( '<STR_LIT>' ) ) , '<STR_LIT>' ) <EOL> def testLambda ( self ) : <EOL> self . assertEqual ( str ( expr ( '<STR_LIT>' ) ) , <EOL> '<STR_LIT>' ) <EOL> def testComprehensions ( self ) : <EOL> self . assertEqual ( str ( expr ( '<STR_LIT>' ) ) , <EOL> '<STR_LIT>' ) <EOL> self . assertEqual ( str ( expr ( '<STR_LIT>' ) ) , <EOL> '<STR_LIT>' ) <EOL> def testSubscripts ( self ) : <EOL> self . assertEqual ( str ( expr ( '<STR_LIT>' ) ) , '<STR_LIT>' ) <EOL> self . assertEqual ( repr ( expr ( '<STR_LIT>' ) ) , <EOL> "<STR_LIT>" ) <EOL> self . assertEqual ( repr ( expr ( '<STR_LIT>' ) ) , <EOL> "<STR_LIT>" ) <EOL> class StmtParsingTests ( unittest . TestCase ) : <EOL> def setUp ( self ) : pass <EOL> def tearDown ( self ) : pass <EOL> def match ( self , src , ref ) : <EOL> code = stmt ( src ) <EOL> text = '<STR_LIT:\n>' . join ( map ( str , code ) ) <EOL> self . assertEqual ( text , ref ) <EOL> def testBindings ( self ) : <EOL> self . match ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> def testReturn ( self ) : <EOL> self . match ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> def testProcedure ( self ) : <EOL> self . match ( '<STR_LIT>' , <EOL> '<STR_LIT>' ) <EOL> def testCond ( self ) : <EOL> self . match ( '<STR_LIT>' , <EOL> '<STR_LIT>' ) <EOL> class FreeVariableTests ( unittest . TestCase ) : <EOL> def setUp ( self ) : <EOL> self . env = pltools . Environment ( prelude . __dict__ , __builtin__ . __dict__ ) <EOL> def tearDown ( self ) : pass <EOL> def check ( self , src , vars ) : <EOL> f = S . free_variables ( src , self . env ) <EOL> self . assertEqual ( sorted ( f ) , sorted ( list ( vars ) ) ) <EOL> def testLiterals ( self ) : <EOL> self . check ( expr ( '<STR_LIT>' ) , [ ] ) <EOL> self . check ( expr ( '<STR_LIT>' ) , [ ] ) <EOL> self . check ( expr ( '<STR_LIT:None>' ) , [ ] ) <EOL> self . check ( expr ( '<STR_LIT>' ) , '<STR_LIT:x>' ) <EOL> def testSimple ( self ) : <EOL> self . check ( expr ( '<STR_LIT>' ) , '<STR_LIT>' ) <EOL> self . check ( expr ( '<STR_LIT>' ) , '<STR_LIT>' ) <EOL> def testLambda ( self ) : <EOL> self . check ( expr ( '<STR_LIT>' ) , '<STR_LIT:y>' ) <EOL> self . check ( expr ( '<STR_LIT>' ) , [ ] ) <EOL> def testClosure ( self ) : <EOL> self . check ( S . Closure ( [ S . Name ( '<STR_LIT:a>' ) , S . Name ( '<STR_LIT:b>' ) ] , <EOL> S . Lambda ( map ( S . Name , [ '<STR_LIT:x>' , '<STR_LIT:y>' , '<STR_LIT:z>' ] ) , <EOL> S . And ( map ( S . Name , [ '<STR_LIT:w>' , '<STR_LIT:x>' , '<STR_LIT:y>' , '<STR_LIT:z>' ] ) ) ) ) , <EOL> '<STR_LIT>' ) <EOL> def testBindings ( self ) : <EOL> self . check ( stmt ( '<STR_LIT>' ) , '<STR_LIT:y>' ) <EOL> self . check ( stmt ( '<STR_LIT>' ) , '<STR_LIT:y>' ) <EOL> self . check ( stmt ( '<STR_LIT>' ) , '<STR_LIT:y>' ) <EOL> self . check ( stmt ( '<STR_LIT>' ) , '<STR_LIT>' ) <EOL> class SubstitutionTests ( unittest . TestCase ) : <EOL> def setUp ( self ) : pass <EOL> def tearDown ( self ) : pass <EOL> def check ( self , src , subst , ref ) : <EOL> e = expr ( src ) <EOL> code = S . substituted_expression ( e , subst ) <EOL> self . assertEqual ( str ( code ) , ref ) <EOL> def testExpressions ( self ) : <EOL> self . check ( '<STR_LIT>' , { '<STR_LIT:x>' : '<STR_LIT>' } , '<STR_LIT>' ) <EOL> def testLambda ( self ) : <EOL> self . check ( '<STR_LIT>' , { '<STR_LIT:x>' : '<STR_LIT>' , '<STR_LIT:y>' : '<STR_LIT>' } , <EOL> '<STR_LIT>' ) <EOL> self . check ( '<STR_LIT>' , { '<STR_LIT:x>' : '<STR_LIT>' , '<STR_LIT:y>' : '<STR_LIT>' } , <EOL> '<STR_LIT>' ) <EOL> class SyntaxErrorTests ( unittest . TestCase ) : <EOL> def check ( self , fn , * args ) : <EOL> self . assertRaises ( SyntaxError , fn , * args ) <EOL> def testCond ( self ) : <EOL> self . check ( stmt , """<STR_LIT>""" ) <EOL> def testArity ( self ) : <EOL> self . check ( F . arity_check , stmt ( """<STR_LIT>""" ) ) <EOL> self . check ( F . arity_check , stmt ( """<STR_LIT>""" ) ) <EOL> self . check ( P . run_compilation , P . frontend , stmt ( """<STR_LIT>""" ) , P . Compilation ( silence = True ) ) <EOL> def testReturn ( self ) : <EOL> self . check ( F . return_check , stmt ( """<STR_LIT>""" ) ) <EOL> self . check ( F . return_check , stmt ( """<STR_LIT>""" ) ) <EOL> self . check ( F . return_check , stmt ( """<STR_LIT>""" ) ) <EOL> self . check ( F . return_check , stmt ( """<STR_LIT>""" ) ) <EOL> def testBuiltin ( self ) : <EOL> self . check ( F . builtin_check , stmt ( """<STR_LIT>""" ) ) <EOL> self . check ( F . builtin_check , stmt ( """<STR_LIT>""" ) ) <EOL> self . check ( F . builtin_check , stmt ( """<STR_LIT>""" ) ) <EOL> stmt ( """<STR_LIT>""" ) <EOL> if __name__ == "<STR_LIT:__main__>" : <EOL> unittest . main ( ) </s>
