<s> import StringIO <EOL> import unittest <EOL> from pikos . filters . on_value import OnValue <EOL> from pikos . recorders . text_stream_recorder import TextStreamRecorder <EOL> from pikos . tests . compat import TestCase <EOL> from pikos . tests . monitoring_helper import MonitoringHelper <EOL> class TestCLineMonitor ( TestCase ) : <EOL> def setUp ( self ) : <EOL> try : <EOL> from pikos . cymonitors . line_monitor import LineMonitor <EOL> except ImportError : <EOL> self . skipTest ( '<STR_LIT>' ) <EOL> self . maxDiff = None <EOL> self . stream = StringIO . StringIO ( ) <EOL> self . helper = MonitoringHelper ( ) <EOL> self . filename = self . helper . filename <EOL> self . recorder = TextStreamRecorder ( <EOL> text_stream = self . stream , <EOL> filter_ = OnValue ( '<STR_LIT:filename>' , self . filename ) ) <EOL> self . monitor = LineMonitor ( self . recorder ) <EOL> self . helper . monitor = self . monitor <EOL> def test_function ( self ) : <EOL> result = self . helper . run_on_function ( ) <EOL> self . assertEqual ( result , <NUM_LIT:3> ) <EOL> template = [ <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> self . check_records ( template , self . stream ) <EOL> def test_recursive ( self ) : <EOL> result = self . helper . run_on_recursive_function ( ) <EOL> self . assertEqual ( result , <NUM_LIT:1> ) <EOL> template = [ <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> self . check_records ( template , self . stream ) <EOL> def test_generator ( self ) : <EOL> result = self . helper . run_on_generator ( ) <EOL> output = ( <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> , <NUM_LIT:5> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ) <EOL> self . assertSequenceEqual ( result , output ) <EOL> template = [ <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> "<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> self . check_records ( template , self . stream ) <EOL> def test_function_using_tuples ( self ) : <EOL> from pikos . cymonitors . line_monitor import LineMonitor <EOL> filename = self . filename <EOL> recorder = TextStreamRecorder ( <EOL> text_stream = self . stream , <EOL> filter_ = lambda x : x [ - <NUM_LIT:1> ] == filename ) <EOL> monitor = LineMonitor ( recorder , record_type = tuple ) <EOL> helper = MonitoringHelper ( monitor ) <EOL> result = helper . run_on_function ( ) <EOL> self . assertEqual ( result , <NUM_LIT:3> ) <EOL> template = [ <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" ] <EOL> self . check_records ( template , self . stream ) <EOL> def test_issue2 ( self ) : <EOL> """<STR_LIT>""" <EOL> monitor = self . monitor <EOL> FOO = """<STR_LIT>""" <EOL> @ monitor . attach <EOL> def boo ( ) : <EOL> code = compile ( FOO , '<STR_LIT:foo>' , '<STR_LIT>' ) <EOL> exec code in globals ( ) , { } <EOL> try : <EOL> boo ( ) <EOL> except TypeError : <EOL> msg = ( "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> self . fail ( msg ) <EOL> def check_records ( self , template , stream ) : <EOL> expected = [ line . format ( self . filename ) for line in template ] <EOL> records = '<STR_LIT>' . join ( stream . buflist ) . splitlines ( ) <EOL> self . assertEqual ( records , expected ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> unittest . main ( ) </s>
