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 unittest | import unittest | ||||
from swh.model.hashutil import hash_to_bytes | from swh.model.hashutil import hash_to_bytes | ||||
from swh.indexer.metadata_dictionary import CROSSWALK_TABLE, MAPPINGS | from swh.indexer.metadata_dictionary import ( | ||||
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 ( | ||||
▲ Show 20 Lines • Show All 58 Lines • ▼ Show 20 Lines | def test_crosstable(self): | ||||
'license': 'http://schema.org/license', | 'license': 'http://schema.org/license', | ||||
'version': 'http://schema.org/version', | 'version': 'http://schema.org/version', | ||||
'description': 'http://schema.org/description', | 'description': 'http://schema.org/description', | ||||
'name': 'http://schema.org/name', | 'name': 'http://schema.org/name', | ||||
'bugs': 'https://codemeta.github.io/terms/issueTracker', | 'bugs': 'https://codemeta.github.io/terms/issueTracker', | ||||
'homepage': 'http://schema.org/url' | 'homepage': 'http://schema.org/url' | ||||
}) | }) | ||||
def test_merge_values(self): | |||||
self.assertEqual( | |||||
merge_values('a', 'b'), | |||||
['a', 'b']) | |||||
self.assertEqual( | |||||
merge_values(['a', 'b'], 'c'), | |||||
['a', 'b', 'c']) | |||||
self.assertEqual( | |||||
merge_values('a', ['b', 'c']), | |||||
['a', 'b', 'c']) | |||||
self.assertEqual( | |||||
merge_values({'@list': ['a']}, {'@list': ['b']}), | |||||
{'@list': ['a', 'b']}) | |||||
self.assertEqual( | |||||
merge_values({'@list': ['a', 'b']}, {'@list': ['c']}), | |||||
{'@list': ['a', 'b', 'c']}) | |||||
with self.assertRaises(ValueError): | |||||
merge_values({'@list': ['a']}, 'b') | |||||
with self.assertRaises(ValueError): | |||||
merge_values('a', {'@list': ['b']}) | |||||
with self.assertRaises(ValueError): | |||||
merge_values({'@list': ['a']}, ['b']) | |||||
with self.assertRaises(ValueError): | |||||
merge_values(['a'], {'@list': ['b']}) | |||||
def test_compute_metadata_none(self): | def test_compute_metadata_none(self): | ||||
""" | """ | ||||
testing content empty content is empty | testing content empty content is empty | ||||
should return None | should return None | ||||
""" | """ | ||||
# given | # given | ||||
content = b"" | content = b"" | ||||
▲ Show 20 Lines • Show All 758 Lines • Show Last 20 Lines |