示例#1
0
    def setUp(self):
        self.model = fake('Model')
        self.module_modeler = ModuleModeler(fake('SourceCodeParser'),
                                            fake('EntityIdGenerator'),
                                            self.model)

        self.fake_importer = real('Module')
        self.fake_importer.name = 'importer'

        self.importer_module = Mock()
        self.dependency1 = real('Module')
        self.dependency2 = real('Module')
        self.model.modules.get_by_name.side_effect = lambda name: {
                                                    'importer': self.importer_module,
                                                    'some.module': self.dependency1,
                                                    'some.other.module': self.dependency2}[name]
    def test_add_still_works(self, entity_class):
        # Arrange
        observable_repo = ObservableEntityRepo(Mock())
        entity = real(entity_class)

        # Act
        observable_repo.add(entity)

        # Assert
        assert_equal(observable_repo.get_by_id(entity.id_), entity)
    def test_it_notifies_when_one_entity_is_added(self, entity_class):
        # Arrange
        observer = Mock()
        repo = ObservableEntityRepo(observer)
        entity = real(entity_class)

        # Act
        repo.add(entity)

        # Assert
        observer.on_entity.assert_called_once_with(entity)
    def test_it_does_not_notify_if_an_entity_is_added_again(self):
        # Arrange
        observer = Mock()
        repo = ObservableEntityRepo(observer)
        module = real('Module')

        # Act
        repo.add(module)
        repo.add(module)

        # Assert
        observer.on_entity.assert_called_once_with(module)
示例#5
0
    def test_on_call_notifies_function_call_to_the_observer(self):
        # Arrange
        frame_digest = fake('FrameDigest', spec_set=False)
        expected_function_call = real('FunctionCall')
        self.function_call_modeler.on_call.return_value = expected_function_call

        # Act
        driver = Driver(*self.init_args)
        driver.on_call(frame_digest)

        # Assert
        self.observer.on_call.assert_called_once_with(ANY)
        actual_function_call = self.observer.on_call.call_args[0][0]
        assert_equal(actual_function_call.function, expected_function_call.function)
示例#6
0
    def test_one_function_is_added_to_function_repo(self):
        # Arrange
        module = real('Module')
        module.id_ = 'fake_file_name'
        self.model.modules.add(module)

        function_modeler = FunctionModeler(self.source_code_parser, EntityIdGenerator('.'), self.model)
        node = MagicMock()
        node.parent = Mock(spec=astroid.scoped_nodes.Module)
        node.parent.file = 'fake_file_name'
        node.lineno = 44

        # Act
        function_modeler.on_function(node)

        # Assert
        expected_function = Function('fake_file_name:44',
                                     'fake_function_name',
                                     module)
        self.model.functions.add.assert_called_once_with(expected_function)
示例#7
0
    def test_one_method_is_added_to_function_repo(self):
        # Arrange
        class_mock = real('Class_')
        class_mock.id_ = 'fake_file_name:33'
        self.model.classes.add(class_mock)

        function_modeler = FunctionModeler(self.source_code_parser,
                                                 EntityIdGenerator('.'),
                                                 self.model)
        node = MagicMock()
        node.parent = Mock(spec=astroid.scoped_nodes.Class)
        node.parent.parent.file = 'fake_file_name'
        node.parent.lineno = 33
        node.name = 'fake_function_name'
        node.lineno = 44

        # Act
        function_modeler.on_function(node)

        # Assert
        expected_function = Method('fake_file_name:44',
                                   'fake_function_name',
                                   class_mock)
        self.model.functions.add.assert_called_once_with(expected_function)
示例#8
0
 def test_not_eq_comparison(self):
     method1 = unique(real('Method'))
     method2 = unique(real('Method'))
     assert_not_equal(method1, method2)
示例#9
0
 def test_add_one_method(self):
     class_ = real('Class_')
     method = Method('dummy_id', 'dummy_name', class_)
     class_.add_method(method)
示例#10
0
 def test_eq_comparison(self):
     class_1 = real('Class_')
     class_2 = real('Class_')
     assert_equal(class_1, class_2)
示例#11
0
 def test_non_equal_comparison(self):
     function1 = unique(real('Function'))
     function2 = unique(real('Function'))
     assert_not_equal(function1, function2)
示例#12
0
 def test_equal_comparison(self):
     function1 = real('Function')
     function2 = real('Function')
     assert_equal(function1, function2)
示例#13
0
 def test_creation(self):
     # Arrange nothing
     # Act
     real('Class_')
示例#14
0
 def test_eq_comparison(self):
     method1 = real('Method')
     method2 = real('Method')
     assert_equal(method1, method2)
示例#15
0
 def test_creation(self):
     real('Method')
示例#16
0
 def test_creation(self):
     real('FunctionCall')
示例#17
0
 def test_not_eq_comparison(self):
     class_1 = unique(real('Class_'))
     class_2 = unique(real('Class_'))
     assert_not_equal(class_1, class_2)