Changeset View
Changeset View
Standalone View
Standalone View
swh/web/tests/data.py
# Copyright (C) 2018-2019 The Software Heritage developers | # Copyright (C) 2018-2019 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 Affero General Public License version 3, or any later version | # License: GNU Affero 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 | ||||
from copy import deepcopy | from copy import deepcopy | ||||
import os | import os | ||||
import time | import time | ||||
from swh.indexer.language import LanguageIndexer | |||||
from swh.indexer.fossology_license import FossologyLicenseIndexer | from swh.indexer.fossology_license import FossologyLicenseIndexer | ||||
from swh.indexer.mimetype import MimetypeIndexer | from swh.indexer.mimetype import MimetypeIndexer | ||||
from swh.indexer.ctags import CtagsIndexer | from swh.indexer.ctags import CtagsIndexer | ||||
from swh.indexer.storage import get_indexer_storage | from swh.indexer.storage import get_indexer_storage | ||||
from swh.model.hashutil import hash_to_hex, hash_to_bytes, DEFAULT_ALGORITHMS | from swh.model.hashutil import hash_to_hex, hash_to_bytes, DEFAULT_ALGORITHMS | ||||
from swh.model.identifiers import directory_identifier | from swh.model.identifiers import directory_identifier | ||||
from swh.loader.git.from_disk import GitLoaderFromArchive | from swh.loader.git.from_disk import GitLoaderFromArchive | ||||
from swh.storage.algos.dir_iterators import dir_iterator | from swh.storage.algos.dir_iterators import dir_iterator | ||||
▲ Show 20 Lines • Show All 53 Lines • ▼ Show 20 Lines | def parse_config_file(self, *args, **kwargs): | ||||
'configuration': { | 'configuration': { | ||||
"type": "library", | "type": "library", | ||||
"debian-package": "python3-magic" | "debian-package": "python3-magic" | ||||
} | } | ||||
} | } | ||||
} | } | ||||
# LanguageIndexer with custom configuration for tests | |||||
class _LanguageIndexer(LanguageIndexer): | |||||
def parse_config_file(self, *args, **kwargs): | |||||
return { | |||||
**_TEST_INDEXER_BASE_CONFIG, | |||||
'tools': { | |||||
'name': 'pygments', | |||||
'version': '2.0.1+dfsg-1.1+deb8u1', | |||||
'configuration': { | |||||
'type': 'library', | |||||
'debian-package': 'python3-pygments', | |||||
'max_content_size': 10240, | |||||
} | |||||
} | |||||
} | |||||
# FossologyLicenseIndexer with custom configuration for tests | # FossologyLicenseIndexer with custom configuration for tests | ||||
class _FossologyLicenseIndexer(FossologyLicenseIndexer): | class _FossologyLicenseIndexer(FossologyLicenseIndexer): | ||||
def parse_config_file(self, *args, **kwargs): | def parse_config_file(self, *args, **kwargs): | ||||
return { | return { | ||||
**_TEST_INDEXER_BASE_CONFIG, | **_TEST_INDEXER_BASE_CONFIG, | ||||
'workdir': '/tmp/swh/indexer.fossology.license', | 'workdir': '/tmp/swh/indexer.fossology.license', | ||||
'tools': { | 'tools': { | ||||
'name': 'nomos', | 'name': 'nomos', | ||||
▲ Show 20 Lines • Show All 150 Lines • ▼ Show 20 Lines | def _init_tests_data(): | ||||
} | } | ||||
def _init_indexers(tests_data): | def _init_indexers(tests_data): | ||||
# Instantiate content indexers that will be used in tests | # Instantiate content indexers that will be used in tests | ||||
# and force them to use the memory storages | # and force them to use the memory storages | ||||
indexers = {} | indexers = {} | ||||
for idx_name, idx_class in (('mimetype_indexer', _MimetypeIndexer), | for idx_name, idx_class in (('mimetype_indexer', _MimetypeIndexer), | ||||
('language_indexer', _LanguageIndexer), | |||||
('license_indexer', _FossologyLicenseIndexer), | ('license_indexer', _FossologyLicenseIndexer), | ||||
('ctags_indexer', _CtagsIndexer)): | ('ctags_indexer', _CtagsIndexer)): | ||||
idx = idx_class() | idx = idx_class() | ||||
idx.storage = tests_data['storage'] | idx.storage = tests_data['storage'] | ||||
idx.objstorage = tests_data['storage'].objstorage | idx.objstorage = tests_data['storage'].objstorage | ||||
idx.idx_storage = tests_data['idx_storage'] | idx.idx_storage = tests_data['idx_storage'] | ||||
idx.register_tools(idx.config['tools']) | idx.register_tools(idx.config['tools']) | ||||
indexers[idx_name] = idx | indexers[idx_name] = idx | ||||
Show All 33 Lines |