Skip to content

Commit

Permalink
馃憣 IMPROVE: Add rstrip_lines to assert_expected
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisjsewell committed Jan 9, 2022
1 parent 3114af6 commit 2dd9b7c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
2 changes: 1 addition & 1 deletion pytest_param_files/__init__.py
@@ -1,4 +1,4 @@
"""Create pytest parametrize decorators from external files."""
from .main import ParamTestData, with_parameters # noqa: F401

__version__ = "0.2.1"
__version__ = "0.2.2"
15 changes: 12 additions & 3 deletions pytest_param_files/main.py
Expand Up @@ -3,7 +3,7 @@
import difflib
from pathlib import Path
import re
from typing import Any, List, Tuple, Union
from typing import Any, List, Tuple, Union, cast

import pytest

Expand Down Expand Up @@ -140,17 +140,26 @@ def read(self) -> List[Tuple[int, str, str, str, str]]:
return tests

def assert_expected(
self, actual: str, data: ParamTestData, rstrip: bool = False
self,
actual: str,
data: ParamTestData,
rstrip: bool = False,
rstrip_lines: bool = False,
) -> None:
"""Assert the actual result of the test.
:param rstrip: Whether to apply `str.rstrip` to actual and expected before comparing.
:param rstrip_lines: Whether to apply `str.rstrip`
to each line of actual and expected before comparing.
"""
__tracebackhide__ = True
expected = data.expected
expected = cast(str, data.expected)
if rstrip:
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())

try:
assert actual == expected
Expand Down

0 comments on commit 2dd9b7c

Please sign in to comment.