Esempio n. 1
0
    def test_add_files_accepts_a_single_file(self):
        # Arrange
        file_path = 'path/to/a/single/file.py'
        source_code_parser = SourceCodeParser('.')

        # Act
        source_code_parser.add_files(file_path)
        source_code_parser.parse()

        # Assert
        self.ast_ng_manager_mock.project_from_files.assert_called_once_with([file_path], func_wrapper=ANY)
Esempio n. 2
0
    def test_creates_project_from_file_paths(self):
        # Arrange
        file_paths = ['path/to/a.py', 'path/to/b.py']
        source_code_parser = SourceCodeParser('.')
        source_code_parser.add_files(file_paths)

        # Act
        source_code_parser.parse()

        # Assert
        self.ast_ng_manager_mock.project_from_files.assert_called_once_with(file_paths, func_wrapper=ANY)
Esempio n. 3
0
    def test_add_files_returns_true_if_at_least_one_file_was_added(self):
        # Arrange
        paths1 = ['path/to/a.py', 'path/to/b.py']
        paths2 = ['path/to/b.py', 'path/to/c.py']
        source_code_parser = SourceCodeParser('.')
        source_code_parser.add_files(paths1)

        # Act
        result = source_code_parser.add_files(paths2)

        # Assert
        assert_true(result)
Esempio n. 4
0
    def test_add_files_returns_false_no_file_was_added(self):
        # Arrange
        paths1 = ['path/to/a.py', 'path/to/b.py']
        paths2 = ['path/to/b.py']
        source_code_parser = SourceCodeParser('.')
        source_code_parser.add_files(paths1)

        # Act
        result = source_code_parser.add_files(paths2)

        # Assert
        assert_false(result)
Esempio n. 5
0
    def test_if_only_add_files_that_exist(self):
        with patch('dissect.collection.static.source_code_parser.os.path.isfile',
                   new=Mock(side_effect=lambda f: f == 'file-which-exists')):
            # Given
            parser = SourceCodeParser('.')

            # When
            parser.add_files(['file-which-exists', 'file-which-does-not-exist'])
            parser.parse()

            # Then
            self.ast_ng_manager_mock.project_from_files.assert_called_once_with(
                ['file-which-exists'], func_wrapper=ANY)
Esempio n. 6
0
    def test_visits_definitions_and_relations(self, defs_visitor_class_mock, relations_visitor_class_mock):
        # Arrange
        defs_visitor_mock = Mock()
        defs_visitor_class_mock.return_value = defs_visitor_mock
        relations_visitor_mock = Mock()
        relations_visitor_class_mock.return_value = relations_visitor_mock
        source_code_parser = SourceCodeParser('.')
        source_code_parser.add_files('dummy/path.py')

        # Act
        source_code_parser.parse()

        # Assert
        defs_visitor_mock.visit.assert_called_once_with(ANY)
        relations_visitor_mock.visit.assert_called_once_with(ANY)
Esempio n. 7
0
class Orchestrator(object):
    def __init__(self, base_path, model):
        self.model = model
        self.entity_id_generator = EntityIdGenerator(base_path)
        self.source_code_parser = SourceCodeParser(base_path)

    def include(self, modeler):
        modeler(self.source_code_parser,
                self.entity_id_generator,
                self.model)

    def process(self, file_paths):
        assert file_paths
        if not self.source_code_parser.add_files(file_paths):
            raise AlreadyProcessed(file_paths)

        self.source_code_parser.parse()
Esempio n. 8
0
 def __init__(self, base_path, model):
     self.model = model
     self.entity_id_generator = EntityIdGenerator(base_path)
     self.source_code_parser = SourceCodeParser(base_path)