Changeset View
Changeset View
Standalone View
Standalone View
swh/indexer/tests/test_fossology_license.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.fossology_license import ( | from swh.indexer.fossology_license import ( | ||||
FossologyLicenseIndexer, FossologyLicenseRangeIndexer, | FossologyLicenseIndexer, FossologyLicenseRangeIndexer, | ||||
compute_license | compute_license | ||||
) | ) | ||||
from swh.indexer.tests.test_utils import ( | from swh.indexer.tests.test_utils import ( | ||||
MockObjStorage, BasicMockStorage, BasicMockIndexerStorage, | |||||
SHA1_TO_LICENSES, CommonContentIndexerTest, CommonContentIndexerRangeTest, | SHA1_TO_LICENSES, CommonContentIndexerTest, CommonContentIndexerRangeTest, | ||||
CommonIndexerWithErrorsTest, CommonIndexerNoTool, NoDiskIndexer, | CommonIndexerWithErrorsTest, CommonIndexerNoTool, NoDiskIndexer, | ||||
BASE_TEST_CONFIG | BASE_TEST_CONFIG, fill_storage, fill_obj_storage | ||||
) | ) | ||||
class BasicTest(unittest.TestCase): | class BasicTest(unittest.TestCase): | ||||
@patch('swh.indexer.fossology_license.subprocess') | @patch('swh.indexer.fossology_license.subprocess') | ||||
def test_compute_license(self, mock_subprocess): | def test_compute_license(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 44 Lines • ▼ Show 20 Lines | def parse_config_file(self, *args, **kwargs): | ||||
'name': 'nomos', | 'name': 'nomos', | ||||
'version': '3.1.0rc2-31-ga2cbb8c', | 'version': '3.1.0rc2-31-ga2cbb8c', | ||||
'configuration': { | 'configuration': { | ||||
'command_line': 'nomossa <filepath>', | 'command_line': 'nomossa <filepath>', | ||||
}, | }, | ||||
}, | }, | ||||
} | } | ||||
def prepare(self): | |||||
super().prepare() | |||||
self.idx_storage = BasicMockIndexerStorage() | |||||
self.log = logging.getLogger('swh.indexer') | |||||
self.objstorage = MockObjStorage() | |||||
class TestFossologyLicenseIndexer(CommonContentIndexerTest, unittest.TestCase): | class TestFossologyLicenseIndexer(CommonContentIndexerTest, unittest.TestCase): | ||||
"""Language indexer test scenarios: | """Language 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 | ||||
""" | """ | ||||
def get_indexer_results(self, ids): | |||||
yield from self.idx_storage.content_ctags_get(ids) | |||||
def setUp(self): | def setUp(self): | ||||
super().setUp() | |||||
self.indexer = FossologyLicenseTestIndexer() | self.indexer = FossologyLicenseTestIndexer() | ||||
self.idx_storage = self.indexer.idx_storage | |||||
self.id0 = '01c9379dfc33803963d07c1ccc748d3fe4c96bb5' | self.id0 = '01c9379dfc33803963d07c1ccc748d3fe4c96bb5' | ||||
self.id1 = '688a5ef812c53907562fe379d4b3851e69c7cb15' | self.id1 = '688a5ef812c53907562fe379d4b3851e69c7cb15' | ||||
self.id2 = 'da39a3ee5e6b4b0d3255bfef95601890afd80709' # empty content | self.id2 = 'da39a3ee5e6b4b0d3255bfef95601890afd80709' # empty content | ||||
tool_id = self.indexer.tool['id'] | tool_id = self.indexer.tool['id'] | ||||
# then | # then | ||||
self.expected_results = { | self.expected_results = { | ||||
self.id0: { | self.id0: { | ||||
Show All 28 Lines | def parse_config_file(self, *args, **kwargs): | ||||
'version': '3.1.0rc2-31-ga2cbb8c', | 'version': '3.1.0rc2-31-ga2cbb8c', | ||||
'configuration': { | 'configuration': { | ||||
'command_line': 'nomossa <filepath>', | 'command_line': 'nomossa <filepath>', | ||||
}, | }, | ||||
}, | }, | ||||
'write_batch_size': 100, | 'write_batch_size': 100, | ||||
} | } | ||||
def prepare(self): | |||||
super().prepare() | |||||
self.idx_storage = BasicMockIndexerStorage() | |||||
self.log = logging.getLogger('swh.indexer') | |||||
# this hardcodes some contents, will use this to setup the storage | |||||
self.objstorage = MockObjStorage() | |||||
contents = [{'sha1': c_id} for c_id in self.objstorage] | |||||
self.storage = BasicMockStorage(contents) | |||||
class TestFossologyLicenseRangeIndexer( | class TestFossologyLicenseRangeIndexer( | ||||
CommonContentIndexerRangeTest, unittest.TestCase): | CommonContentIndexerRangeTest, unittest.TestCase): | ||||
"""Range Fossology License Indexer tests. | """Range Fossology License Indexer tests. | ||||
- new data within range are indexed | - new data within range are indexed | ||||
- no data outside a range are indexed | - no data outside a range are indexed | ||||
- with filtering existing indexed data prior to compute new index | - with filtering existing indexed data prior to compute new index | ||||
- without filtering existing indexed data prior to compute new index | - without filtering existing indexed data prior to compute new index | ||||
""" | """ | ||||
def setUp(self): | def setUp(self): | ||||
super().setUp() | |||||
self.indexer = FossologyLicenseRangeIndexerTest() | self.indexer = FossologyLicenseRangeIndexerTest() | ||||
# will play along with the objstorage's mocked contents for now | fill_storage(self.indexer.storage) | ||||
self.contents = sorted(self.indexer.objstorage) | fill_obj_storage(self.indexer.objstorage) | ||||
# FIXME: leverage swh.objstorage.in_memory_storage's | |||||
# InMemoryObjStorage, swh.storage.tests's gen_contents, and | |||||
# hypothesis to generate data to actually run indexer on those | |||||
self.id0 = '01c9379dfc33803963d07c1ccc748d3fe4c96bb5' | self.id0 = '01c9379dfc33803963d07c1ccc748d3fe4c96bb5' | ||||
self.id1 = '02fb2c89e14f7fab46701478c83779c7beb7b069' | self.id1 = '02fb2c89e14f7fab46701478c83779c7beb7b069' | ||||
self.id2 = '103bc087db1d26afc3a0283f38663d081e9b01e6' | self.id2 = '103bc087db1d26afc3a0283f38663d081e9b01e6' | ||||
tool_id = self.indexer.tool['id'] | tool_id = self.indexer.tool['id'] | ||||
self.expected_results = { | self.expected_results = { | ||||
self.id0: { | self.id0: { | ||||
'id': self.id0, | 'id': self.id0, | ||||
Show All 31 Lines |