Changeset View
Changeset View
Standalone View
Standalone View
swh/indexer/tests/storage/test_converters.py
# Copyright (C) 2015-2020 The Software Heritage developers | # Copyright (C) 2015-2022 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 | ||||
from swh.indexer.storage import converters | from swh.indexer.storage import converters | ||||
def test_ctags_to_db() -> None: | |||||
input_ctag = { | |||||
"id": b"some-id", | |||||
"indexer_configuration_id": 100, | |||||
"ctags": [ | |||||
{ | |||||
"name": "some-name", | |||||
"kind": "some-kind", | |||||
"line": 10, | |||||
"lang": "Yaml", | |||||
}, | |||||
{ | |||||
"name": "main", | |||||
"kind": "function", | |||||
"line": 12, | |||||
"lang": "Yaml", | |||||
}, | |||||
], | |||||
} | |||||
expected_ctags = [ | |||||
{ | |||||
"id": b"some-id", | |||||
"name": "some-name", | |||||
"kind": "some-kind", | |||||
"line": 10, | |||||
"lang": "Yaml", | |||||
"indexer_configuration_id": 100, | |||||
}, | |||||
{ | |||||
"id": b"some-id", | |||||
"name": "main", | |||||
"kind": "function", | |||||
"line": 12, | |||||
"lang": "Yaml", | |||||
"indexer_configuration_id": 100, | |||||
}, | |||||
] | |||||
# when | |||||
actual_ctags = list(converters.ctags_to_db(input_ctag)) | |||||
# then | |||||
assert actual_ctags == expected_ctags | |||||
def test_db_to_ctags() -> None: | |||||
input_ctags = { | |||||
"id": b"some-id", | |||||
"name": "some-name", | |||||
"kind": "some-kind", | |||||
"line": 10, | |||||
"lang": "Yaml", | |||||
"tool_id": 200, | |||||
"tool_name": "some-toolname", | |||||
"tool_version": "some-toolversion", | |||||
"tool_configuration": {}, | |||||
} | |||||
expected_ctags = { | |||||
"id": b"some-id", | |||||
"name": "some-name", | |||||
"kind": "some-kind", | |||||
"line": 10, | |||||
"lang": "Yaml", | |||||
"tool": { | |||||
"id": 200, | |||||
"name": "some-toolname", | |||||
"version": "some-toolversion", | |||||
"configuration": {}, | |||||
}, | |||||
} | |||||
# when | |||||
actual_ctags = converters.db_to_ctags(input_ctags) | |||||
# then | |||||
assert actual_ctags == expected_ctags | |||||
def test_db_to_mimetype() -> None: | def test_db_to_mimetype() -> None: | ||||
input_mimetype = { | input_mimetype = { | ||||
"id": b"some-id", | "id": b"some-id", | ||||
"tool_id": 10, | "tool_id": 10, | ||||
"tool_name": "some-toolname", | "tool_name": "some-toolname", | ||||
"tool_version": "some-toolversion", | "tool_version": "some-toolversion", | ||||
"tool_configuration": {}, | "tool_configuration": {}, | ||||
"encoding": b"ascii", | "encoding": b"ascii", | ||||
▲ Show 20 Lines • Show All 96 Lines • Show Last 20 Lines |