Skip to content

Commit

Permalink
Fix: escape '\n' in row_sep and sep error messages
Browse files Browse the repository at this point in the history
  • Loading branch information
janluke committed Jun 30, 2021
1 parent 5b48dc0 commit 00fd70c
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 6 deletions.
5 changes: 3 additions & 2 deletions cloup/formatting/_formatter.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,9 @@ def __init__(
check_positive_int(col_spacing, 'col_spacing')
if isinstance(row_sep, str) and row_sep.endswith('\n'):
raise ValueError(
"row_sep must not end with '\n'. Since v0.9, the formatter writes "
"a '\n' after it. To disable row_sep, you can leave it set to None.")
"since v0.9, row_sep must not end with '\\n'. The formatter writes "
"a '\\n' after it; no other newline is allowed.\n"
"If you want an empty line between rows, set row_sep=''.")

max_width = max_width or 80
# We subtract 1 to the terminal width to leave space for the new line character.
Expand Down
4 changes: 2 additions & 2 deletions cloup/formatting/sep.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,8 @@ def __init__(self, condition: RowSepCondition,
"""
if isinstance(sep, str) and sep.endswith('\n'):
raise ValueError(
"sep must not end with '\n'. Since v0.9, the formatter writes "
"a '\n' after it.")
"sep must not end with '\\n'. The formatter writes a '\\n' after it; "
"no other newline is allowed.")
self.condition = condition
self.sep = sep

Expand Down
2 changes: 1 addition & 1 deletion tests/test_formatting.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ def test_col2_min_width():


def test_value_error_if_row_sep_string_ends_with_newline():
with pytest.raises(ValueError, match="row_sep must not end with '\n'"):
with pytest.raises(ValueError, match=r"row_sep must not end with '\\n'"):
HelpFormatter(row_sep='\n')


Expand Down
2 changes: 1 addition & 1 deletion tests/test_sep.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def test_with_percentage(self):


def test_value_error_if_sep_string_ends_with_newline():
with pytest.raises(ValueError, match="sep must not end with '\n'"):
with pytest.raises(ValueError, match=r"sep must not end with '\\n'"):
RowSepIf(multiline_rows_are_at_least(1), sep='\n')


Expand Down

0 comments on commit 00fd70c

Please sign in to comment.