Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added better error message for a nonstring marker #35

Closed
Closed
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
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 st"):
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
Loading