Skip to content

Commit

Permalink
Add missing tests for description requirement
Browse files Browse the repository at this point in the history
This adds some tests for checking descriptions when the
require_description flag is on for the default model.
  • Loading branch information
JeremyMcCormick committed Feb 15, 2024
1 parent 333103e commit 5f0c332
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
20 changes: 18 additions & 2 deletions tests/test_datamodel.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,9 @@ def test_validation(self) -> None:
with self.assertRaises(ValidationError):
Column(**units_data)

# Turn on description requirement for next two tests.
def test_require_description(self) -> None:
"""Test the require_description flag for the `Column` class."""
# Turn on description requirement for this test.
Schema.require_description(True)

# Make sure that setting the flag for description requirement works
Expand All @@ -131,14 +133,28 @@ def test_validation(self) -> None:
# Creating a column without a description when required should throw an
# error.
with self.assertRaises(ValidationError):
col = Column(
Column(
**{
"name": "testColumn",
"@id": "#test_col_id",
"datatype": "string",
}
)

# Creating a column with a None description when required should throw.
with self.assertRaises(ValidationError):
Column(**{"name": "testColumn", "@id": "#test_col_id", "datatype": "string", "description": None})

# Creating a column with an empty description when required should
# throw.
with self.assertRaises(ValidationError):
Column(**{"name": "testColumn", "@id": "#test_col_id", "datatype": "string", "description": ""})

# Creating a column with a description that is not long enough should
# throw.
with self.assertRaises(ValidationError):
Column(**{"name": "testColumn", "@id": "#test_col_id", "datatype": "string", "description": "xy"})

# Turn off flag or it will affect subsequent tests.
Schema.require_description(False)

Expand Down
4 changes: 4 additions & 0 deletions tests/test_validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ def test_rsp_validation(self) -> None:
with self.assertRaises(ValidationError):
RspColumn(name="testColumn", id="#test_col_id", datatype="string", description=None)

# A column description which is not long enough should throw.
with self.assertRaises(ValidationError):
RspColumn(name="testColumn", id="#test_col_id", datatype="string", description="xy")

# Creating a valid RSP column should not throw an exception.
col = RspColumn(
**{
Expand Down

0 comments on commit 5f0c332

Please sign in to comment.