Skip to content

Commit

Permalink
Added better error message for a nonstring marker
Browse files Browse the repository at this point in the history
  • Loading branch information
cadaniel02 committed Jun 6, 2024
1 parent 69fc292 commit 19848ed
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
3 changes: 3 additions & 0 deletions dahlia/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ def _find_ansi_codes(string: str) -> set[str]:


def _with_marker(marker: str) -> list[re.Pattern[str]]:
if not isinstance(marker, str):
msg = "The marker has to be a string"
raise TypeError(msg)
if len(marker) != 1:
msg = "The marker has to be a single character"
raise ValueError(msg)
Expand Down
4 changes: 4 additions & 0 deletions tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ def test_invalid_marker(marker: str) -> None:
with pytest.raises(ValueError, match="The marker has to be a single character"):
Dahlia(marker=marker)

@pytest.mark.parametrize("marker", [123, [1], {"key": "value"}])
def test_nonstring_marker(marker: str) -> None:
with pytest.raises(TypeError, match="The marker has to be a st"):
Dahlia(marker=marker)

@pytest.mark.parametrize(("auto_reset", "expected"), [(True, "\x1b[0m"), (False, "")])
def test_auto_reset(auto_reset: bool, expected: str) -> None:
Expand Down

0 comments on commit 19848ed

Please sign in to comment.