Changeset View
Changeset View
Standalone View
Standalone View
swh/indexer/tests/test_metadata.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 json | import json | ||||
import unittest | import unittest | ||||
from hypothesis import given, strategies | from hypothesis import given, strategies | ||||
import xmltodict | |||||
from swh.model.hashutil import hash_to_bytes | from swh.model.hashutil import hash_to_bytes | ||||
from swh.indexer.codemeta import CODEMETA_KEYS | from swh.indexer.codemeta import CODEMETA_KEYS | ||||
from swh.indexer.metadata_dictionary import ( | from swh.indexer.metadata_dictionary import ( | ||||
CROSSWALK_TABLE, MAPPINGS, merge_values) | CROSSWALK_TABLE, MAPPINGS, merge_values) | ||||
from swh.indexer.metadata_detector import ( | from swh.indexer.metadata_detector import ( | ||||
detect_metadata, extract_minimal_metadata_dict | detect_metadata, extract_minimal_metadata_dict | ||||
) | ) | ||||
from swh.indexer.metadata import ( | from swh.indexer.metadata import ( | ||||
ContentMetadataIndexer, RevisionMetadataIndexer | ContentMetadataIndexer, RevisionMetadataIndexer | ||||
) | ) | ||||
from .utils import ( | from .utils import ( | ||||
BASE_TEST_CONFIG, fill_obj_storage, fill_storage, | BASE_TEST_CONFIG, fill_obj_storage, fill_storage, | ||||
YARN_PARSER_METADATA, json_document_strategy | YARN_PARSER_METADATA, json_document_strategy, | ||||
xml_document_strategy, | |||||
) | ) | ||||
TRANSLATOR_TOOL = { | TRANSLATOR_TOOL = { | ||||
'name': 'swh-metadata-translator', | 'name': 'swh-metadata-translator', | ||||
'version': '0.0.2', | 'version': '0.0.2', | ||||
'configuration': { | 'configuration': { | ||||
'type': 'local', | 'type': 'local', | ||||
▲ Show 20 Lines • Show All 1,029 Lines • ▼ Show 20 Lines | def test_npm_adversarial(self, doc): | ||||
raw = json.dumps(doc).encode() | raw = json.dumps(doc).encode() | ||||
self.npm_mapping.translate(raw) | self.npm_mapping.translate(raw) | ||||
@given(json_document_strategy(keys=CODEMETA_KEYS)) | @given(json_document_strategy(keys=CODEMETA_KEYS)) | ||||
def test_codemeta_adversarial(self, doc): | def test_codemeta_adversarial(self, doc): | ||||
raw = json.dumps(doc).encode() | raw = json.dumps(doc).encode() | ||||
self.codemeta_mapping.translate(raw) | self.codemeta_mapping.translate(raw) | ||||
@given(json_document_strategy( | @given(xml_document_strategy( | ||||
keys=list(MAPPINGS['MavenMapping'].mapping))) | keys=list(MAPPINGS['MavenMapping'].mapping), | ||||
root='project', | |||||
xmlns='http://maven.apache.org/POM/4.0.0')) | |||||
def test_maven_adversarial(self, doc): | def test_maven_adversarial(self, doc): | ||||
raw = xmltodict.unparse({'project': doc}, pretty=True) | self.maven_mapping.translate(doc) | ||||
self.maven_mapping.translate(raw) | |||||
@given(strategies.dictionaries( | @given(strategies.dictionaries( | ||||
# keys | # keys | ||||
strategies.one_of( | strategies.one_of( | ||||
strategies.text(), | strategies.text(), | ||||
*map(strategies.just, MAPPINGS['GemspecMapping'].mapping) | *map(strategies.just, MAPPINGS['GemspecMapping'].mapping) | ||||
), | ), | ||||
# values | # values | ||||
▲ Show 20 Lines • Show All 48 Lines • Show Last 20 Lines |