diff --git a/swh/indexer/tests/test_fossology_license.py b/swh/indexer/tests/test_fossology_license.py --- a/swh/indexer/tests/test_fossology_license.py +++ b/swh/indexer/tests/test_fossology_license.py @@ -12,7 +12,8 @@ from swh.indexer.tests.test_utils import ( MockObjStorage, BasicMockStorage, BasicMockIndexerStorage, - SHA1_TO_LICENSES, CommonContentIndexerTest, CommonContentIndexerRangeTest + SHA1_TO_LICENSES, CommonContentIndexerTest, CommonContentIndexerRangeTest, + CommonIndexerWithErrorsTest, CommonIndexerNoTool ) @@ -65,24 +66,6 @@ self.tool = self.tools[0] -class FossologyLicenseIndexerUnknownToolTestStorage( - FossologyLicenseTestIndexer): - """Specific fossology license indexer whose configuration is not - enough to satisfy the indexing checks - - """ - def prepare(self): - super().prepare() - self.tools = None - - -class TestFossologyLicenseIndexerWithErrors(unittest.TestCase): - def test_wrong_unknown_configuration_tool(self): - """Indexer with unknown configuration tool should fail the check""" - with self.assertRaisesRegex(ValueError, 'Tools None is unknown'): - FossologyLicenseIndexerUnknownToolTestStorage() - - class TestFossologyLicenseIndexer(CommonContentIndexerTest, unittest.TestCase): """Language indexer test scenarios: @@ -181,3 +164,20 @@ 'licenses': SHA1_TO_LICENSES[self.id2] } } + + +class FossologyLicenseIndexerUnknownToolTestStorage( + CommonIndexerNoTool, FossologyLicenseTestIndexer): + """Fossology license indexer with wrong configuration""" + + +class FossologyLicenseRangeIndexerUnknownToolTestStorage( + CommonIndexerNoTool, FossologyLicenseRangeIndexerTest): + """Fossology license range indexer with wrong configuration""" + + +class TestFossologyLicenseIndexersErrors( + CommonIndexerWithErrorsTest, unittest.TestCase): + """Test the indexer raise the right errors when wrongly initialized""" + Indexer = FossologyLicenseIndexerUnknownToolTestStorage + RangeIndexer = FossologyLicenseRangeIndexerUnknownToolTestStorage diff --git a/swh/indexer/tests/test_language.py b/swh/indexer/tests/test_language.py --- a/swh/indexer/tests/test_language.py +++ b/swh/indexer/tests/test_language.py @@ -8,7 +8,8 @@ from swh.indexer import language from swh.indexer.language import ContentLanguageIndexer from swh.indexer.tests.test_utils import ( - BasicMockIndexerStorage, MockObjStorage, CommonContentIndexerTest + BasicMockIndexerStorage, MockObjStorage, CommonContentIndexerTest, + CommonIndexerWithErrorsTest, CommonIndexerNoTool ) @@ -86,3 +87,14 @@ 'lang': 'text-only' } } + + +class LanguageIndexerUnknownToolTestStorage( + CommonIndexerNoTool, LanguageTestIndexer): + """Fossology license indexer with wrong configuration""" + + +class TestLanguageIndexersErrors( + CommonIndexerWithErrorsTest, unittest.TestCase): + """Test the indexer raise the right errors when wrongly initialized""" + Indexer = LanguageIndexerUnknownToolTestStorage diff --git a/swh/indexer/tests/test_mimetype.py b/swh/indexer/tests/test_mimetype.py --- a/swh/indexer/tests/test_mimetype.py +++ b/swh/indexer/tests/test_mimetype.py @@ -12,7 +12,8 @@ from swh.indexer.tests.test_utils import ( MockObjStorage, BasicMockStorage, BasicMockIndexerStorage, - CommonContentIndexerTest, CommonContentIndexerRangeTest + CommonContentIndexerTest, CommonContentIndexerRangeTest, + CommonIndexerWithErrorsTest, CommonIndexerNoTool ) @@ -39,23 +40,6 @@ self.tool = self.tools[0] -class MimetypeIndexerUnknownToolTestStorage(MimetypeTestIndexer): - """Specific mimetype whose configuration is not enough to satisfy the - indexing checks. - - """ - def prepare(self): - super().prepare() - self.tools = None - - -class TestMimetypeIndexerWithErrors(unittest.TestCase): - def test_wrong_unknown_configuration_tool(self): - """Indexer with unknown configuration tool should fail the check""" - with self.assertRaisesRegex(ValueError, 'Tools None is unknown'): - MimetypeIndexerUnknownToolTestStorage() - - class TestMimetypeIndexer(CommonContentIndexerTest, unittest.TestCase): """Mimetype indexer test scenarios: @@ -157,3 +141,20 @@ 'indexer_configuration_id': 10, 'mimetype': b'text/plain'} } + + +class MimetypeIndexerUnknownToolTestStorage( + CommonIndexerNoTool, MimetypeTestIndexer): + """Fossology license indexer with wrong configuration""" + + +class MimetypeRangeIndexerUnknownToolTestStorage( + CommonIndexerNoTool, MimetypeRangeIndexerTest): + """Fossology license range indexer with wrong configuration""" + + +class TestMimetypeIndexersErrors( + CommonIndexerWithErrorsTest, unittest.TestCase): + """Test the indexer raise the right errors when wrongly initialized""" + Indexer = MimetypeIndexerUnknownToolTestStorage + RangeIndexer = MimetypeRangeIndexerUnknownToolTestStorage diff --git a/swh/indexer/tests/test_utils.py b/swh/indexer/tests/test_utils.py --- a/swh/indexer/tests/test_utils.py +++ b/swh/indexer/tests/test_utils.py @@ -3,6 +3,7 @@ # License: GNU General Public License version 3, or any later version # See top-level LICENSE file for more information +import unittest from swh.objstorage.exc import ObjNotFoundError from swh.model import hashutil @@ -518,6 +519,33 @@ }] +class CommonIndexerNoTool: + """Mixin to wronly initialize content indexer""" + def prepare(self): + super().prepare() + self.tools = None + + +class CommonIndexerWithErrorsTest: + """Test indexer configuration checks. + + """ + Indexer = None + RangeIndexer = None + + def test_wrong_unknown_configuration_tool(self): + """Indexer with unknown configuration tool fails check""" + with self.assertRaisesRegex(ValueError, 'Tools None is unknown'): + print('indexer: %s' % self.Indexer) + self.Indexer() + + def test_wrong_unknown_configuration_tool_range(self): + """Range Indexer with unknown configuration tool fails check""" + if self.RangeIndexer is not None: + with self.assertRaisesRegex(ValueError, 'Tools None is unknown'): + self.RangeIndexer() + + class CommonContentIndexerTest: def assert_results_ok(self, actual_results, expected_results=None): if expected_results is None: