Changeset View
Changeset View
Standalone View
Standalone View
swh/indexer/tests/test_ctags.py
Show All 14 Lines | from swh.indexer.tests.utils import ( | ||||
BASE_TEST_CONFIG, | BASE_TEST_CONFIG, | ||||
OBJ_STORAGE_DATA, | OBJ_STORAGE_DATA, | ||||
SHA1_TO_CTAGS, | SHA1_TO_CTAGS, | ||||
CommonContentIndexerTest, | CommonContentIndexerTest, | ||||
fill_obj_storage, | fill_obj_storage, | ||||
fill_storage, | fill_storage, | ||||
filter_dict, | filter_dict, | ||||
) | ) | ||||
from swh.model.hashutil import hash_to_bytes | |||||
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 51 Lines • ▼ Show 20 Lines | |||||
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 | ||||
""" | """ | ||||
legacy_get_format = True | |||||
def get_indexer_results(self, ids): | def get_indexer_results(self, ids): | ||||
yield from self.idx_storage.content_ctags_get(ids) | yield from self.idx_storage.content_ctags_get(ids) | ||||
def setUp(self): | def setUp(self): | ||||
super().setUp() | super().setUp() | ||||
self.indexer = CtagsIndexer(config=CONFIG) | self.indexer = CtagsIndexer(config=CONFIG) | ||||
self.indexer.catch_exceptions = False | self.indexer.catch_exceptions = False | ||||
self.idx_storage = self.indexer.idx_storage | self.idx_storage = self.indexer.idx_storage | ||||
fill_storage(self.indexer.storage) | fill_storage(self.indexer.storage) | ||||
fill_obj_storage(self.indexer.objstorage) | fill_obj_storage(self.indexer.objstorage) | ||||
# Prepare test input | # Prepare test input | ||||
self.id0 = "01c9379dfc33803963d07c1ccc748d3fe4c96bb5" | self.id0 = "01c9379dfc33803963d07c1ccc748d3fe4c96bb5" | ||||
self.id1 = "d4c647f0fc257591cc9ba1722484229780d1c607" | self.id1 = "d4c647f0fc257591cc9ba1722484229780d1c607" | ||||
self.id2 = "688a5ef812c53907562fe379d4b3851e69c7cb15" | self.id2 = "688a5ef812c53907562fe379d4b3851e69c7cb15" | ||||
tool = {k.replace("tool_", ""): v for (k, v) in self.indexer.tool.items()} | tool = {k.replace("tool_", ""): v for (k, v) in self.indexer.tool.items()} | ||||
self.expected_results = { | self.expected_results = [ | ||||
self.id0: {"id": self.id0, "tool": tool, **SHA1_TO_CTAGS[self.id0][0],}, | { | ||||
self.id1: {"id": self.id1, "tool": tool, **SHA1_TO_CTAGS[self.id1][0],}, | "id": hash_to_bytes(self.id0), | ||||
self.id2: {"id": self.id2, "tool": tool, **SHA1_TO_CTAGS[self.id2][0],}, | "tool": tool, | ||||
} | **SHA1_TO_CTAGS[self.id0][0], | ||||
}, | |||||
{ | |||||
"id": hash_to_bytes(self.id1), | |||||
"tool": tool, | |||||
**SHA1_TO_CTAGS[self.id1][0], | |||||
}, | |||||
{ | |||||
"id": hash_to_bytes(self.id2), | |||||
"tool": tool, | |||||
**SHA1_TO_CTAGS[self.id2][0], | |||||
}, | |||||
] | |||||
self._set_mocks() | self._set_mocks() | ||||
def _set_mocks(self): | def _set_mocks(self): | ||||
def find_ctags_for_content(raw_content): | def find_ctags_for_content(raw_content): | ||||
for (sha1, ctags) in SHA1_TO_CTAGS.items(): | for (sha1, ctags) in SHA1_TO_CTAGS.items(): | ||||
if OBJ_STORAGE_DATA[sha1] == raw_content: | if OBJ_STORAGE_DATA[sha1] == raw_content: | ||||
return ctags | return ctags | ||||
Show All 31 Lines |