diff --git a/unittests/test_json_schema_exporter.py b/unittests/test_json_schema_exporter.py index 42ab9d909ad844cee93db70f75321b5e5e8723ff..6b43b382ab460d37af855f8359d5a6005312e84f 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()