Skip to content

Commit

Permalink
Nonstring marker handling (#36)
Browse files Browse the repository at this point in the history
Co-authored-by: trag1c <[email protected]>
  • Loading branch information
cadaniel02 and trag1c authored Jun 6, 2024
1 parent 69fc292 commit 0410b88
Show file tree
Hide file tree
Showing 2 changed files with 9 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
6 changes: 6 additions & 0 deletions tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,12 @@ def test_invalid_marker(marker: str) -> None:
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 string"):
Dahlia(marker=marker)


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

0 comments on commit 0410b88

Please sign in to comment.