Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 13 additions & 5 deletions ado/schema/domain.py
Original file line number Diff line number Diff line change
Expand Up @@ -659,8 +659,12 @@ def variableType_matches_values(
valuesCheck = values.data.get("values") is not None
intervalCheck = values.data.get("interval") is not None
if not (valuesCheck or intervalCheck):
domain_range = values.data.get("domainRange")
raise ValueError(
"A DISCRETE_VARIABLE_TYPE had neither values nor interval specified"
f"A DISCRETE_VARIABLE_TYPE had neither values nor interval specified. "
f"Provided: values={values.data.get('values')}, "
f"interval={values.data.get('interval')}, "
f"domainRange={domain_range}"
)

elif value == VariableTypeEnum.CONTINUOUS_VARIABLE_TYPE:
Expand All @@ -677,12 +681,14 @@ def variableType_matches_values(
elif value == VariableTypeEnum.OPEN_CATEGORICAL_VARIABLE_TYPE:
if values.data.get("interval") is not None:
raise ValueError(
"The interval field of an OPEN_CATEGORICAL_VARIABLE_TYPE was not None"
f"An OPEN_CATEGORICAL_VARIABLE_TYPE must not have interval specified. "
f"Provided: interval={values.data.get('interval')}"
)

if values.data.get("domainRange") is not None:
raise ValueError(
"The domainRange field of an OPEN_CATEGORICAL_VARIABLE_TYPE was not None"
f"An OPEN_CATEGORICAL_VARIABLE_TYPE must not have domainRange specified. "
f"Provided: domainRange={values.data.get('domainRange')}"
)

elif value == VariableTypeEnum.BINARY_VARIABLE_TYPE:
Expand All @@ -700,12 +706,14 @@ def variableType_matches_values(

if values.data.get("interval") is not None:
raise ValueError(
"The interval field for a BINARY_VARIABLE_TYPE must be None"
f"A BINARY_VARIABLE_TYPE must not have interval specified. "
f"Provided: interval={values.data.get('interval')}"
)

if values.data.get("domainRange") is not None:
raise ValueError(
"The domainRange field for a BINARY_VARIABLE_TYPE must be None"
f"A BINARY_VARIABLE_TYPE must not have domainRange specified. "
f"Provided: domainRange={values.data.get('domainRange')}"
)

return value
Expand Down
4 changes: 2 additions & 2 deletions tests/schema/test_domain.py
Original file line number Diff line number Diff line change
Expand Up @@ -1066,15 +1066,15 @@ def test_binary_variable_type_with_no_values() -> None:
def test_binary_variable_type_rejects_interval() -> None:
"""Test that BINARY_VARIABLE_TYPE rejects interval specification"""
with pytest.raises(
ValueError, match="interval field for a BINARY_VARIABLE_TYPE must be None"
ValueError, match="A BINARY_VARIABLE_TYPE must not have interval specified"
):
PropertyDomain(variableType=VariableTypeEnum.BINARY_VARIABLE_TYPE, interval=1)


def test_binary_variable_type_rejects_domain_range() -> None:
"""Test that BINARY_VARIABLE_TYPE rejects domainRange specification"""
with pytest.raises(
ValueError, match="domainRange field for a BINARY_VARIABLE_TYPE must be None"
ValueError, match="A BINARY_VARIABLE_TYPE must not have domainRange specified"
):
PropertyDomain(
variableType=VariableTypeEnum.BINARY_VARIABLE_TYPE, domainRange=[0, 1]
Expand Down