Пример #1
0
    def test_it_passes_the_frame_digest_to_the_thread_modeler(self,
                                    thread_modeler, threading):
        # Arrange
        process_modeler = Process('fake_entityid_gen',
                                                'fake_model')

        # Act
        fake_frame_digest = fake('FrameDigest')
        threading.current_thread.return_value.name = 'MainThread'
        process_modeler.on_call(fake_frame_digest)

        # Assert
        thread_modeler.return_value.on_call.assert_called_once_with(
            fake_frame_digest)
Пример #2
0
    def test_it_creates_a_thread_modeler_for_the_main_thread(self,
                                                    thread_modeler,
                                                    threading):
        # Arrange
        process_modeler = Process('fake_entityid_gen',
                                                'fake_model')

        # Act
        threading.current_thread.return_value.name = 'MainThread'
        process_modeler.on_call(fake('FrameDigest'))

        # Assert
        thread_modeler.assert_called_once_with('fake_entityid_gen',
                                                         'fake_model')
Пример #3
0
    def test_it_passes_all_calls_from_the_same_thread_to_the_same_modeler(self,
                                         thread_modeler, threading):
        # Arrange
        process_modeler = Process('fake_entityid_gen',
                                                'fake_model')

        fake_frame_digest_1 = fake('FrameDigest')
        fake_frame_digest_2 = fake('FrameDigest')

        # Act
        threading.current_thread.return_value.name = 'MainThread'
        process_modeler.on_call(fake_frame_digest_1)
        threading.current_thread.return_value.name = 'Thread-1'
        process_modeler.on_call(fake_frame_digest_2)

        # Assert
        thread_modeler.return_value
        assert_equal(thread_modeler.call_count, 2)
Пример #4
0
    def test_it_passes_all_calls_from_the_same_thread_to_the_same_modeler(self,
                                        thread_modeler, threading):
        # Arrange
        process_modeler = Process('fake_entityid_gen',
                                                'fake_model')

        fake_frame_digest_1 = fake('FrameDigest')
        fake_frame_digest_2 = fake('FrameDigest')
        threading.current_thread.return_value.name = 'MainThread'

        # Act
        process_modeler.on_call(fake_frame_digest_1)
        process_modeler.on_call(fake_frame_digest_2)

        # Assert
        thread_modeler.return_value
        assert_equal(thread_modeler.call_count, 1)
        expected_calls = [call(fake_frame_digest_1), call(fake_frame_digest_2)]
        modeler = thread_modeler.return_value
        modeler.on_call.assert_has_calls(expected_calls)
Пример #5
0
    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
Пример #6
0
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