Skip to content

Commit

Permalink
Use pytest fixtures & parametrize for tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ziad-kermadi committed Nov 13, 2023
1 parent c9feabc commit 4e003ac
Showing 1 changed file with 6 additions and 19 deletions.
25 changes: 6 additions & 19 deletions pandas/tests/reshape/merge/test_merge_ordered.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,23 +212,10 @@ def test_elements_not_in_by_but_in_df(self):
with pytest.raises(KeyError, match=msg):
merge_ordered(left, right, on="E", left_by=["G", "h"])

def test_ffill_validate_fill_method(self):
@pytest.mark.parametrize("invalid_method", ["linear", "carrot"])
def test_ffill_validate_fill_method(self, left, right, invalid_method):
# GH 55884
df1 = DataFrame({"key": ["a", "c", "e"], "lvalue": [1, 2, 3]})
df2 = DataFrame({"key": ["b", "c", "d", "f"], "rvalue": [4, 5, 6, 7]})

for valid_method in ["ffill", None]:
try:
merge_ordered(df1, df2, on="key", fill_method=valid_method)
except Exception:
pytest.fail(f"Unexpected error with valid fill_method: {valid_method}")

for invalid_method in ["linear", "carrot"]:
with pytest.raises(
ValueError,
match=re.escape(
"fill_method must be one of ['ffill']. "
f"Got '{invalid_method}' instead."
),
):
merge_ordered(df1, df2, on="key", fill_method=invalid_method)
with pytest.raises(
ValueError, match=re.escape("fill_method must be 'ffill' or None")
):
merge_ordered(left, right, on="key", fill_method=invalid_method)

0 comments on commit 4e003ac

Please sign in to comment.