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 pytest | import pytest | ||||
from unittest.mock import patch | from unittest.mock import patch | ||||
from typing import Any, Dict | from typing import Any, Dict | ||||
from swh.indexer import fossology_license | from swh.indexer import fossology_license | ||||
from swh.indexer.fossology_license import ( | from swh.indexer.fossology_license import ( | ||||
FossologyLicenseIndexer, | FossologyLicenseIndexer, | ||||
FossologyLicenseRangeIndexer, | FossologyLicensePartitionIndexer, | ||||
compute_license, | compute_license, | ||||
) | ) | ||||
from swh.indexer.tests.utils import ( | from swh.indexer.tests.utils import ( | ||||
SHA1_TO_LICENSES, | SHA1_TO_LICENSES, | ||||
CommonContentIndexerTest, | CommonContentIndexerTest, | ||||
CommonContentIndexerRangeTest, | CommonContentIndexerPartitionTest, | ||||
BASE_TEST_CONFIG, | BASE_TEST_CONFIG, | ||||
fill_storage, | fill_storage, | ||||
fill_obj_storage, | fill_obj_storage, | ||||
filter_dict, | filter_dict, | ||||
) | ) | ||||
class BasicTest(unittest.TestCase): | class BasicTest(unittest.TestCase): | ||||
▲ Show 20 Lines • Show All 73 Lines • ▼ Show 20 Lines | def setUp(self): | ||||
self.id2: {"tool": tool, "licenses": SHA1_TO_LICENSES[self.id2],}, | self.id2: {"tool": tool, "licenses": SHA1_TO_LICENSES[self.id2],}, | ||||
} | } | ||||
def tearDown(self): | def tearDown(self): | ||||
super().tearDown() | super().tearDown() | ||||
fossology_license.compute_license = self.orig_compute_license | fossology_license.compute_license = self.orig_compute_license | ||||
class TestFossologyLicenseRangeIndexer( | class TestFossologyLicensePartitionIndexer( | ||||
CommonContentIndexerRangeTest, unittest.TestCase | CommonContentIndexerPartitionTest, 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() | super().setUp() | ||||
# replace actual license computation with a mock | # replace actual license computation with a mock | ||||
self.orig_compute_license = fossology_license.compute_license | self.orig_compute_license = fossology_license.compute_license | ||||
fossology_license.compute_license = mock_compute_license | fossology_license.compute_license = mock_compute_license | ||||
self.indexer = FossologyLicenseRangeIndexer(config=RANGE_CONFIG) | self.indexer = FossologyLicensePartitionIndexer(config=RANGE_CONFIG) | ||||
self.indexer.catch_exceptions = False | self.indexer.catch_exceptions = False | ||||
fill_storage(self.indexer.storage) | fill_storage(self.indexer.storage) | ||||
fill_obj_storage(self.indexer.objstorage) | fill_obj_storage(self.indexer.objstorage) | ||||
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"] | ||||
Show All 22 Lines | |||||
def test_fossology_w_no_tool(): | def test_fossology_w_no_tool(): | ||||
with pytest.raises(ValueError): | with pytest.raises(ValueError): | ||||
FossologyLicenseIndexer(config=filter_dict(CONFIG, "tools")) | FossologyLicenseIndexer(config=filter_dict(CONFIG, "tools")) | ||||
def test_fossology_range_w_no_tool(): | def test_fossology_range_w_no_tool(): | ||||
with pytest.raises(ValueError): | with pytest.raises(ValueError): | ||||
FossologyLicenseRangeIndexer(config=filter_dict(RANGE_CONFIG, "tools")) | FossologyLicensePartitionIndexer(config=filter_dict(RANGE_CONFIG, "tools")) |