def test_method_as_str(self):
        # noinspection PyShadowingNames
        def foo(_):
            pass

        # noinspection PyUnresolvedReferences
        with patch.object(MyClass, 'foo', foo):
            profile_function_or_method('tests.test_dynamic_profiling',
                                       'MyClass.foo', 'test')
            dc = mock_data_collector()
            with patch('silk.profiling.profiler.DataCollector',
                       return_value=dc) as mock_DataCollector:
                MyClass().foo()
                self.assertEqual(
                    mock_DataCollector.return_value.register_profile.
                    call_count, 1)
                call_args = mock_DataCollector.return_value.register_profile.call_args[
                    0][0]
                self.assertTrue(
                    dict_contains(
                        {
                            'func_name': foo.__name__,
                            'dynamic': True,
                            'file_path': source_file_name(),
                            'name': 'test',
                            'line_num': foo.__code__.co_firstlineno
                        }, call_args))
Exemplo n.º 2
0
 def test_func_as_str(self):
     name = foo.__name__
     line_num = six.get_function_code(foo).co_firstlineno
     profile_function_or_method('tests.test_dynamic_profiling', 'foo', 'test')
     dc = mock_data_collector()
     with patch('silk.profiling.profiler.DataCollector', return_value=dc) as mock_DataCollector:
         foo()
         self.assertEqual(mock_DataCollector.return_value.register_profile.call_count, 1)
         call_args = mock_DataCollector.return_value.register_profile.call_args[0][0]
         self.assertDictContainsSubset({
             'func_name': name,
             'dynamic': True,
             'file_path': source_file_name(),
             'name': 'test',
             'line_num': line_num
         }, call_args)
 def test_func_as_str(self):
     name = foo.__name__
     line_num = foo.__code__.co_firstlineno
     profile_function_or_method('tests.test_dynamic_profiling', 'foo', 'test')
     dc = mock_data_collector()
     with patch('silk.profiling.profiler.DataCollector', return_value=dc) as mock_DataCollector:
         foo()
         self.assertEqual(mock_DataCollector.return_value.register_profile.call_count, 1)
         call_args = mock_DataCollector.return_value.register_profile.call_args[0][0]
         self.assertDictContainsSubset({
             'func_name': name,
             'dynamic': True,
             'file_path': source_file_name(),
             'name': 'test',
             'line_num': line_num
         }, call_args)
Exemplo n.º 4
0
    def test_method_as_str(self):
        # noinspection PyShadowingNames
        def foo(_):
            pass

        # noinspection PyUnresolvedReferences
        with patch.object(MyClass, 'foo', foo):
            profile_function_or_method('tests.test_dynamic_profiling', 'MyClass.foo', 'test')
            dc = mock_data_collector()
            with patch('silk.profiling.profiler.DataCollector', return_value=dc) as mock_DataCollector:
                MyClass().foo()
                self.assertEqual(mock_DataCollector.return_value.register_profile.call_count, 1)
                call_args = mock_DataCollector.return_value.register_profile.call_args[0][0]
                self.assertDictContainsSubset({
                    'func_name': foo.__name__,
                    'dynamic': True,
                    'file_path': source_file_name(),
                    'name': 'test',
                    'line_num': six.get_function_code(foo).co_firstlineno
                }, call_args)
Exemplo n.º 5
0
 def _apply_dynamic_mappings(self):
     dynamic_profile_configs = config.SILKY_DYNAMIC_PROFILING
     for conf in dynamic_profile_configs:
         module = conf.get('module')
         function = conf.get('function')
         start_line = conf.get('start_line')
         end_line = conf.get('end_line')
         name = conf.get('name')
         if module and function:
             if start_line and end_line:  # Dynamic context manager
                 dynamic.inject_context_manager_func(module=module,
                                                     func=function,
                                                     start_line=start_line,
                                                     end_line=end_line,
                                                     name=name)
             else:  # Dynamic decorator
                 dynamic.profile_function_or_method(module=module,
                                                    func=function,
                                                    name=name)
         else:
             raise KeyError('Invalid dynamic mapping %s' % conf)
Exemplo n.º 6
0
 def _apply_dynamic_mappings(self):
     dynamic_profile_configs = config.SILKY_DYNAMIC_PROFILING
     for conf in dynamic_profile_configs:
         module = conf.get('module')
         function = conf.get('function')
         start_line = conf.get('start_line')
         end_line = conf.get('end_line')
         name = conf.get('name')
         if module and function:
             if start_line and end_line:  # Dynamic context manager
                 dynamic.inject_context_manager_func(module=module,
                                                     func=function,
                                                     start_line=start_line,
                                                     end_line=end_line,
                                                     name=name)
             else:  # Dynamic decorator
                 dynamic.profile_function_or_method(module=module,
                                                    func=function,
                                                    name=name)
         else:
             raise KeyError('Invalid dynamic mapping %s' % conf)