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 random | |||||
import time | import time | ||||
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 | ||||
Show All 40 Lines | 'objstorage': { | ||||
'args': {}, | 'args': {}, | ||||
}, | }, | ||||
'indexer_storage': { | 'indexer_storage': { | ||||
'cls': 'memory', | 'cls': 'memory', | ||||
'args': {}, | 'args': {}, | ||||
} | } | ||||
} | } | ||||
def random_sha1(): | |||||
return hash_to_hex(bytes(random.randint(0, 255) for _ in range(20))) | |||||
def random_sha256(): | |||||
return hash_to_hex(bytes(random.randint(0, 255) for _ in range(32))) | |||||
def random_blake2s256(): | |||||
return hash_to_hex(bytes(random.randint(0, 255) for _ in range(32))) | |||||
def random_content(): | |||||
return { | |||||
'sha1': random_sha1(), | |||||
'sha1_git': random_sha1(), | |||||
'sha256': random_sha256(), | |||||
'blake2s256': random_blake2s256(), | |||||
anlambert: Can we turn these into pytest fixtures ?
I would prefer to keep test inputs as parameters. | |||||
Done Inline ActionsNo, because I need to use more than one random_sha1 in a test, and pytest fixtures don't work for TestCase methods. vlorentz: No, because I need to use more than one `random_sha1` in a test, and pytest fixtures don't work… | |||||
Not Done Inline ActionsOh right, I forgot that. Let's land this then. anlambert: Oh right, I forgot that. Let's land this then. | |||||
} | |||||
# MimetypeIndexer with custom configuration for tests | # MimetypeIndexer with custom configuration for tests | ||||
class _MimetypeIndexer(MimetypeIndexer): | class _MimetypeIndexer(MimetypeIndexer): | ||||
def parse_config_file(self, *args, **kwargs): | def parse_config_file(self, *args, **kwargs): | ||||
return { | return { | ||||
**_TEST_INDEXER_BASE_CONFIG, | **_TEST_INDEXER_BASE_CONFIG, | ||||
'tools': { | 'tools': { | ||||
'name': 'file', | 'name': 'file', | ||||
'version': '1:5.30-1+deb9u1', | 'version': '1:5.30-1+deb9u1', | ||||
▲ Show 20 Lines • Show All 228 Lines • Show Last 20 Lines |
Can we turn these into pytest fixtures ?
I would prefer to keep test inputs as parameters.