<s> import re <EOL> import sys <EOL> class TestParser ( object ) : <EOL> def __init__ ( self , path ) : <EOL> self . path = path <EOL> def removeComments ( self , rawlines ) : <EOL> fixed_lines = [ ] <EOL> for l in rawlines : <EOL> idx = l . find ( '<STR_LIT:#>' ) <EOL> if idx == - <NUM_LIT:1> : <EOL> fixed_lines . append ( l ) <EOL> else : <EOL> fixed_lines . append ( l [ <NUM_LIT:0> : idx ] ) <EOL> return '<STR_LIT:\n>' . join ( fixed_lines ) <EOL> def parse ( self ) : <EOL> test = { } <EOL> with open ( self . path ) as handle : <EOL> raw_lines = handle . read ( ) . split ( '<STR_LIT:\n>' ) <EOL> test_text = self . removeComments ( raw_lines ) <EOL> test [ '<STR_LIT>' ] = raw_lines <EOL> test [ '<STR_LIT:path>' ] = self . path <EOL> test [ '<STR_LIT>' ] = [ ] <EOL> lines = test_text . split ( '<STR_LIT:\n>' ) <EOL> i = <NUM_LIT:0> <EOL> while ( i < len ( lines ) ) : <EOL> if re . match ( '<STR_LIT>' , lines [ i ] ) : <EOL> test [ '<STR_LIT>' ] . append ( ( "<STR_LIT>" , raw_lines [ i ] ) ) <EOL> i += <NUM_LIT:1> <EOL> continue <EOL> m = re . match ( '<STR_LIT>' , lines [ i ] ) <EOL> if m : <EOL> test [ m . group ( <NUM_LIT:1> ) ] = m . group ( <NUM_LIT:2> ) <EOL> test [ '<STR_LIT>' ] . append ( ( "<STR_LIT>" , m . group ( <NUM_LIT:1> ) ) ) <EOL> i += <NUM_LIT:1> <EOL> continue <EOL> m = re . match ( '<STR_LIT>' , lines [ i ] ) <EOL> if m : <EOL> msg = [ ] <EOL> i += <NUM_LIT:1> <EOL> while ( not re . match ( '<STR_LIT>' , lines [ i ] ) ) : <EOL> msg . append ( raw_lines [ i ] ) <EOL> i += <NUM_LIT:1> <EOL> test [ m . group ( <NUM_LIT:1> ) ] = '<STR_LIT:\n>' . join ( msg ) <EOL> test [ '<STR_LIT>' ] . append ( ( "<STR_LIT>" , m . group ( <NUM_LIT:1> ) ) ) <EOL> i += <NUM_LIT:1> <EOL> continue <EOL> print '<STR_LIT>' % self . path <EOL> sys . exit ( <NUM_LIT:1> ) <EOL> return test <EOL> def emitTestDict ( testDict , handle ) : <EOL> for kind , data in testDict [ '<STR_LIT>' ] : <EOL> if kind == "<STR_LIT>" : <EOL> handle . write ( data + "<STR_LIT:\n>" ) <EOL> elif kind == "<STR_LIT>" : <EOL> handle . write ( '<STR_LIT>' % ( data , testDict [ data ] ) ) <EOL> elif kind == "<STR_LIT>" : <EOL> handle . write ( '<STR_LIT>' % ( data , testDict [ data ] ) ) <EOL> else : <EOL> raise Exception ( "<STR_LIT>" ) </s>
