From a0fe997d0975c485cf01bc79ab11263a79a3cd53 Mon Sep 17 00:00:00 2001 From: fspreck <f.spreckelsen@indiscale.com> Date: Tue, 17 Oct 2023 12:29:29 +0200 Subject: [PATCH] TST: Add unit test for units in json schema --- unittests/test_json_schema_exporter.py | 43 ++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/unittests/test_json_schema_exporter.py b/unittests/test_json_schema_exporter.py index 42ab9d90..6b43b382 100644 --- a/unittests/test_json_schema_exporter.py +++ b/unittests/test_json_schema_exporter.py @@ -152,6 +152,49 @@ def test_rt_with_scalar_props(): validate(example, schema, format_checker=FormatChecker()) +def test_units(): + + rt = db.RecordType() + rt.add_property(name="ScalarWithUnit", datatype=db.DOUBLE, unit="m") + rt.add_property(name="ListWithUnit", description="This is a list.", + datatype=db.LIST(db.DOUBLE), unit="m") + + schema = rtjs(rt, units_in_description=True) + + props = schema["properties"] + assert "ScalarWithUnit" in props + assert props["ScalarWithUnit"]["type"] == "number" + assert "description" in props["ScalarWithUnit"] + assert props["ScalarWithUnit"]["description"] == "Unit is m." + assert "unit" not in props["ScalarWithUnit"] + + assert "ListWithUnit" in props + assert props["ListWithUnit"]["type"] == "array" + assert "items" in props["ListWithUnit"] + assert props["ListWithUnit"]["items"]["type"] == "number" + assert "description" in props["ListWithUnit"] + assert props["ListWithUnit"]["description"] == "This is a list. Unit is m." + assert "unit" not in props["ListWithUnit"] + + schema = rtjs(rt, units_in_description=False) + + props = schema["properties"] + assert "ScalarWithUnit" in props + assert props["ScalarWithUnit"]["type"] == "number" + assert "description" not in props["ScalarWithUnit"] + assert "unit" in props["ScalarWithUnit"] + assert props["ScalarWithUnit"]["unit"] == "m" + + assert "ListWithUnit" in props + assert props["ListWithUnit"]["type"] == "array" + assert "items" in props["ListWithUnit"] + assert props["ListWithUnit"]["items"]["type"] == "number" + assert "description" in props["ListWithUnit"] + assert props["ListWithUnit"]["description"] == "This is a list." + assert "unit" in props["ListWithUnit"] + assert props["ListWithUnit"]["unit"] == "m" + + def test_rt_with_list_props(): rt = db.RecordType() -- GitLab