Skip to content

Commit

Permalink
test: adds negative test for get_trestle_model_dir in test_types.py
Browse files Browse the repository at this point in the history
Signed-off-by: Jennifer Power <[email protected]>
  • Loading branch information
jpower432 committed Dec 15, 2023
1 parent 1f86c44 commit eede685
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
11 changes: 11 additions & 0 deletions tests/trestlebot/tasks/authored/test_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"""Test author types for Trestlebot"""

import os
from unittest.mock import Mock

import pytest

Expand Down Expand Up @@ -98,3 +99,13 @@ def test_invalid_authored_type(tmp_trestle_dir: str) -> None:
match="Invalid authored type fake",
):
_ = types.get_authored_object("fake", tmp_trestle_dir, "")


def test_get_model_dir_with_invalid_type() -> None:
"""Test triggering an error with an invalid type when getting the model dir."""
with pytest.raises(
AuthoredObjectException,
match="Invalid authored object <class 'unittest.mock.Mock'>",
):
mock = Mock(spec=AuthoredObjectBase)
_ = types.get_trestle_model_dir(mock)
4 changes: 3 additions & 1 deletion trestlebot/tasks/authored/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,4 +67,6 @@ def get_trestle_model_dir(authored_object: AuthoredObjectBase) -> str:
elif isinstance(authored_object, AuthoredSSP):
return const.MODEL_DIR_SSP
else:
raise AuthoredObjectException(f"Invalid authored object {authored_object}")
raise AuthoredObjectException(
f"Invalid authored object {type(authored_object)}"
)

0 comments on commit eede685

Please sign in to comment.