def test_it_notifies_a_function_call_in_the_current_thread(self): # Arrange call_handler = Mock() process_scoped_tracer = ProcessScopedTracer(call_handler) # Act process_scoped_tracer.start() function1() process_scoped_tracer.stop() # Assert assert_equal(call_handler.on_call.call_count, 1) assert_in('function1', [call[0][0].function_name for call in call_handler.on_call.call_args_list])
def test_it_notifies_a_function_call_in_a_new_thread(self): # Arrange call_handler = Mock() process_scoped_tracer = ProcessScopedTracer(call_handler) # Act process_scoped_tracer.start() new_thread = threading.Thread(target=function1) new_thread.start() new_thread.join() process_scoped_tracer.stop() # Assert assert_in('function1', [call[0][0].function_name for call in call_handler.on_call.call_args_list])
class Driver(object): def __init__(self, observer, entity_id_generator, orchestrator): self.observer = observer self.orchestrator = orchestrator self.process_modeler = \ ProcessModeler(entity_id_generator, orchestrator.model) self._setup_static_data_modeling() one_call_per_second_filter = CallsPerTimePeriod(1, 1, self) project_modules_filter = ProjectModules(entity_id_generator.base_path, one_call_per_second_filter) self.process_scoped_tracer = ProcessScopedTracer(project_modules_filter) self.stop = self.process_scoped_tracer.stop def start(self): self.process_scoped_tracer.start() def on_call(self, frame_digest): # I wonder what this is... if frame_digest.function_name == '<module>': return self._model_static_entities_from(frame_digest.file_name) function_call = self.process_modeler.on_call(frame_digest) self.observer.on_call(function_call) return True def _setup_static_data_modeling(self): self.orchestrator.include(ModuleModeler) self.orchestrator.include(ClassModeler) self.orchestrator.include(FunctionModeler) def _model_static_entities_from(self, file_name): try: self.orchestrator.process(file_name) except AlreadyProcessed: pass