<s> import sys <EOL> import pytest <EOL> import six <EOL> from _utils import factorial , find_stats , foo <EOL> from profiling . stats import RecordingStatistics <EOL> from profiling . tracing import TracingProfiler <EOL> if six . PY3 : <EOL> map = lambda * x : list ( six . moves . map ( * x ) ) <EOL> def test_setprofile ( ) : <EOL> profiler = TracingProfiler ( ) <EOL> assert sys . getprofile ( ) is None <EOL> with profiler : <EOL> assert sys . getprofile ( ) == profiler . _profile <EOL> assert sys . getprofile ( ) is None <EOL> sys . setprofile ( lambda * x : x ) <EOL> with pytest . raises ( RuntimeError ) : <EOL> profiler . start ( ) <EOL> sys . setprofile ( None ) <EOL> def test_profile ( ) : <EOL> profiler = TracingProfiler ( ) <EOL> frame = foo ( ) <EOL> profiler . _profile ( frame , '<STR_LIT>' , None ) <EOL> profiler . _profile ( frame , '<STR_LIT>' , None ) <EOL> assert len ( profiler . stats ) == <NUM_LIT:1> <EOL> stats1 = find_stats ( profiler . stats , '<STR_LIT:foo>' ) <EOL> stats2 = find_stats ( profiler . stats , '<STR_LIT:bar>' ) <EOL> stats3 = find_stats ( profiler . stats , '<STR_LIT>' ) <EOL> assert stats1 . own_hits == <NUM_LIT:0> <EOL> assert stats2 . own_hits == <NUM_LIT:0> <EOL> assert stats3 . own_hits == <NUM_LIT:1> <EOL> assert stats1 . deep_hits == <NUM_LIT:1> <EOL> assert stats2 . deep_hits == <NUM_LIT:1> <EOL> assert stats3 . deep_hits == <NUM_LIT:1> <EOL> def test_profiler ( ) : <EOL> profiler = TracingProfiler ( base_frame = sys . _getframe ( ) ) <EOL> assert isinstance ( profiler . stats , RecordingStatistics ) <EOL> stats , cpu_time , wall_time = profiler . result ( ) <EOL> assert len ( stats ) == <NUM_LIT:0> <EOL> with profiler : <EOL> factorial ( <NUM_LIT:1000> ) <EOL> factorial ( <NUM_LIT> ) <EOL> stats1 = find_stats ( profiler . stats , '<STR_LIT>' ) <EOL> stats2 = find_stats ( profiler . stats , '<STR_LIT>' ) <EOL> stats3 = find_stats ( profiler . stats , '<STR_LIT>' ) <EOL> assert stats1 . deep_time != <NUM_LIT:0> <EOL> assert stats1 . deep_time == stats1 . own_time <EOL> assert stats1 . own_time > stats2 . own_time <EOL> assert stats1 . own_time > stats3 . own_time <EOL> assert stats1 . own_hits == <NUM_LIT:2> <EOL> assert stats2 . own_hits == <NUM_LIT:0> <EOL> assert stats3 . own_hits == <NUM_LIT:1> </s>
