Skip to content

Commit 7fd2450

Browse files
committed
read response_options from file
1 parent 55bf186 commit 7fd2450

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

reproschema/models/response_options.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -342,6 +342,12 @@ def from_data(cls, data: dict):
342342
if klass.at_type != data["@type"]:
343343
raise ValueError(f"Mismatch in type {data['@type']} != {klass.at_type}")
344344
klass.schema = data
345+
"""Load values into instance"""
346+
for key in klass.schema:
347+
if key.startswith("@"):
348+
klass.__setattr__(f"at_{key[1:]}", klass.schema[key])
349+
else:
350+
klass.__setattr__(key, klass.schema[key])
345351
return klass
346352

347353
@classmethod

reproschema/models/tests/test_response_options.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,3 +47,16 @@ def test_default():
4747
assert content == expected
4848

4949
clean_up(response_options_dir, response_options)
50+
51+
52+
def test_constructor_from_file():
53+
54+
response_options = ResponseOption.from_file(
55+
response_options_dir.joinpath(
56+
"..", "data", "response_options", "example.jsonld"
57+
)
58+
)
59+
60+
assert response_options.at_id == "example.jsonld"
61+
assert response_options.valueType == "xsd:integer"
62+
assert response_options.choices[0]["name"] == {"en": "Not at all"}

0 commit comments

Comments
 (0)