Skip to content

Commit

Permalink
馃憣 IMPROVE: rstrip logic
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisjsewell committed Jan 9, 2022
1 parent 9670dbe commit 0ce3eeb
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
2 changes: 1 addition & 1 deletion pytest_param_files/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""Create pytest parametrize decorators from external files."""
from .main import ParamTestData # noqa: F401

__version__ = "0.3.2"
__version__ = "0.3.3"
20 changes: 14 additions & 6 deletions pytest_param_files/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,8 +208,10 @@ def assert_expected(
actual = actual.rstrip()
expected = expected.rstrip()
if rstrip_lines:
actual = "\n".join(line.rstrip() for line in actual.splitlines())
expected = "\n".join(line.rstrip() for line in expected.splitlines())
actual = "\n".join(line.rstrip() for line in actual.splitlines()).rstrip()
expected = "\n".join(
line.rstrip() for line in expected.splitlines()
).rstrip()

if actual == expected:
return None
Expand All @@ -225,7 +227,7 @@ def regen_file(
if rstrip:
actual = actual.rstrip()
if rstrip_lines:
actual = "\n".join(line.rstrip() for line in actual.splitlines())
actual = "\n".join(line.rstrip() for line in actual.splitlines()).rstrip()
text = []
for index, current in enumerate(self.read()):
text.append(f"[{current.title}] {current.description}\n")
Expand All @@ -234,10 +236,16 @@ def regen_file(
text.append(".\n")
if index == data.index:
# TODO what if actual has '.' line in the middle?
text.append(actual)
expected = actual
else:
text.append(current.expected)
text.append("\n.\n\n")
expected = current.expected
text.append(expected)
if not expected.endswith("\n"):
text.append("\n")
text.append(".\n")
text.append("\n")
if text:
text = text[:-1]
self.path.write_text("".join(text), encoding=self.encoding)

def _diff(self, actual: str, expected: str, data: ParamTestData) -> str:
Expand Down

0 comments on commit 0ce3eeb

Please sign in to comment.