Changeset View
Changeset View
Standalone View
Standalone View
swh/indexer/tests/test_ctags.py
# Copyright (C) 2017-2018 The Software Heritage developers | # Copyright (C) 2017-2018 The Software Heritage developers | ||||
# See the AUTHORS file at the top-level directory of this distribution | # See the AUTHORS file at the top-level directory of this distribution | ||||
# License: GNU General Public License version 3, or any later version | # License: GNU General Public License version 3, or any later version | ||||
# See top-level LICENSE file for more information | # See top-level LICENSE file for more information | ||||
import unittest | import unittest | ||||
import logging | |||||
from unittest.mock import patch | from unittest.mock import patch | ||||
from swh.indexer.ctags import ( | from swh.indexer.ctags import ( | ||||
CtagsIndexer, run_ctags | CtagsIndexer, run_ctags | ||||
) | ) | ||||
from swh.indexer.tests.test_utils import ( | from swh.indexer.tests.test_utils import ( | ||||
BasicMockIndexerStorage, MockObjStorage, CommonContentIndexerTest, | BasicMockIndexerStorage, MockObjStorage, CommonContentIndexerTest, | ||||
CommonIndexerWithErrorsTest, CommonIndexerNoTool, | CommonIndexerWithErrorsTest, CommonIndexerNoTool, | ||||
SHA1_TO_CTAGS, NoDiskIndexer | SHA1_TO_CTAGS, NoDiskIndexer, BASE_TEST_CONFIG | ||||
) | ) | ||||
class BasicTest(unittest.TestCase): | class BasicTest(unittest.TestCase): | ||||
@patch('swh.indexer.ctags.subprocess') | @patch('swh.indexer.ctags.subprocess') | ||||
def test_run_ctags(self, mock_subprocess): | def test_run_ctags(self, mock_subprocess): | ||||
"""Computing licenses from a raw content should return results | """Computing licenses from a raw content should return results | ||||
▲ Show 20 Lines • Show All 49 Lines • ▼ Show 20 Lines | def compute_ctags(self, path, lang): | ||||
**SHA1_TO_CTAGS.get(path) | **SHA1_TO_CTAGS.get(path) | ||||
} | } | ||||
class CtagsIndexerTest(NoDiskIndexer, InjectCtagsIndexer, CtagsIndexer): | class CtagsIndexerTest(NoDiskIndexer, InjectCtagsIndexer, CtagsIndexer): | ||||
"""Specific language whose configuration is enough to satisfy the | """Specific language whose configuration is enough to satisfy the | ||||
indexing tests. | indexing tests. | ||||
""" | """ | ||||
def prepare(self): | def parse_config_file(self, *args, **kwargs): | ||||
self.config = { | return { | ||||
**BASE_TEST_CONFIG, | |||||
'tools': { | 'tools': { | ||||
'name': 'universal-ctags', | 'name': 'universal-ctags', | ||||
'version': '~git7859817b', | 'version': '~git7859817b', | ||||
'configuration': { | 'configuration': { | ||||
'command_line': '''ctags --fields=+lnz --sort=no ''' | 'command_line': '''ctags --fields=+lnz --sort=no ''' | ||||
''' --links=no <filepath>''', | ''' --links=no <filepath>''', | ||||
'max_content_size': 1000, | 'max_content_size': 1000, | ||||
}, | }, | ||||
}, | }, | ||||
'languages': { | 'languages': { | ||||
'python': 'python', | 'python': 'python', | ||||
'haskell': 'haskell', | 'haskell': 'haskell', | ||||
'bar': 'bar', | 'bar': 'bar', | ||||
}, | |||||
'workdir': '/nowhere', | |||||
} | } | ||||
} | |||||
def prepare(self): | |||||
super().prepare() | |||||
self.idx_storage = BasicMockIndexerStorage() | self.idx_storage = BasicMockIndexerStorage() | ||||
self.log = logging.getLogger('swh.indexer') | |||||
self.objstorage = MockObjStorage() | self.objstorage = MockObjStorage() | ||||
self.tool_config = self.config['tools']['configuration'] | self.tool_config = self.config['tools']['configuration'] | ||||
self.max_content_size = self.tool_config['max_content_size'] | |||||
self.tools = self.register_tools(self.config['tools']) | |||||
self.tool = self.tools[0] | |||||
self.language_map = self.config['languages'] | |||||
class TestCtagsIndexer(CommonContentIndexerTest, unittest.TestCase): | class TestCtagsIndexer(CommonContentIndexerTest, unittest.TestCase): | ||||
"""Ctags indexer test scenarios: | """Ctags indexer test scenarios: | ||||
- Known sha1s in the input list have their data indexed | - Known sha1s in the input list have their data indexed | ||||
- Unknown sha1 in the input list are not indexed | - Unknown sha1 in the input list are not indexed | ||||
Show All 38 Lines |