Skip to content

Commit f2e92f3

Browse files
committed
Provide tests for the registry object
Specifically here a new placeholder for registry entry object tests and tests for handling ruleset/marker output.
1 parent ad3446c commit f2e92f3

2 files changed

Lines changed: 95 additions & 2 deletions

File tree

src/jsonid/registry_class.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,8 @@ def json(self):
9393
replace_me = helpers.substitute_type_text(replace_me)
9494
marker["ISTYPE"] = replace_me
9595
new_markers.append(marker)
96-
except KeyError:
97-
pass
96+
except (KeyError, AttributeError):
97+
new_markers.append(marker)
9898
if not new_markers:
9999
return obj.__dict__
100100
obj.markers = new_markers

tests/test_registry_class.py

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
"""Tests for the registry class object."""
2+
3+
import pytest
4+
5+
from src.jsonid import registry_class
6+
7+
registry_marker_tests = [
8+
(
9+
[
10+
{"KEY": "$id", "STARTSWITH": "http://www.parcore.org/schema/"},
11+
{"KEY": "$schema", "EXISTS": None},
12+
{"KEY": "definitions", "ISTYPE": dict},
13+
],
14+
{
15+
"identifier": "",
16+
"name": [],
17+
"version": None,
18+
"description": [],
19+
"pronom": "",
20+
"wikidata": "",
21+
"loc": "",
22+
"archive_team": "",
23+
"rfc": "",
24+
"mime": [],
25+
"markers": [
26+
{"KEY": "$id", "STARTSWITH": "http://www.parcore.org/schema/"},
27+
{"KEY": "$schema", "EXISTS": None},
28+
{"KEY": "definitions", "ISTYPE": "map"},
29+
],
30+
"depth": 0,
31+
"additional": "",
32+
"encoding": "",
33+
},
34+
),
35+
(
36+
[
37+
{"KEY": "$id", "STARTSWITH": "http://www.parcore.org/schema/"},
38+
{"KEY": "$schema", "EXISTS": None},
39+
{"KEY": "definitions", "ISTYPE": None},
40+
],
41+
{
42+
"identifier": "",
43+
"name": [],
44+
"version": None,
45+
"description": [],
46+
"pronom": "",
47+
"wikidata": "",
48+
"loc": "",
49+
"archive_team": "",
50+
"rfc": "",
51+
"mime": [],
52+
"markers": [
53+
{"KEY": "$id", "STARTSWITH": "http://www.parcore.org/schema/"},
54+
{"KEY": "$schema", "EXISTS": None},
55+
{"KEY": "definitions", "ISTYPE": None},
56+
],
57+
"depth": 0,
58+
"additional": "",
59+
"encoding": "",
60+
},
61+
),
62+
(
63+
[],
64+
{
65+
"identifier": "",
66+
"name": [],
67+
"version": None,
68+
"description": [],
69+
"pronom": "",
70+
"wikidata": "",
71+
"loc": "",
72+
"archive_team": "",
73+
"rfc": "",
74+
"mime": [],
75+
"markers": [],
76+
"depth": 0,
77+
"additional": "",
78+
"encoding": "",
79+
},
80+
),
81+
]
82+
83+
84+
@pytest.mark.parametrize("entry, expected", registry_marker_tests)
85+
def test_registry_entry_markers_json(entry, expected):
86+
"""Outputting the markers as JSON requires some subtle changes to
87+
types so they can be stringified correctly. Test these work as
88+
throughout any changes to the code base.
89+
"""
90+
entry_obj = registry_class.RegistryEntry()
91+
entry_obj.markers = entry
92+
res = entry_obj.json()
93+
assert res == expected

0 commit comments

Comments
 (0)