Skip to content

Commit

Permalink
TST: add message matches to pytest.raises in test_duplicate_labels.py…
Browse files Browse the repository at this point in the history
… GH30999 (pandas-dev#37114)
  • Loading branch information
theMogget authored and JulianWgs committed Oct 26, 2020
1 parent 1f8cca8 commit 43bf412
Showing 1 changed file with 18 additions and 10 deletions.
28 changes: 18 additions & 10 deletions pandas/tests/generic/test_duplicate_labels.py
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,8 @@ def test_set_flags_with_duplicates(self, cls, axes):
result = cls(**axes)
assert result.flags.allows_duplicate_labels is True

with pytest.raises(pd.errors.DuplicateLabelError):
msg = "Index has duplicates."
with pytest.raises(pd.errors.DuplicateLabelError, match=msg):
cls(**axes).set_flags(allows_duplicate_labels=False)

@pytest.mark.parametrize(
Expand All @@ -287,7 +288,8 @@ def test_set_flags_with_duplicates(self, cls, axes):
],
)
def test_setting_allows_duplicate_labels_raises(self, data):
with pytest.raises(pd.errors.DuplicateLabelError):
msg = "Index has duplicates."
with pytest.raises(pd.errors.DuplicateLabelError, match=msg):
data.flags.allows_duplicate_labels = False

assert data.flags.allows_duplicate_labels is True
Expand All @@ -297,7 +299,8 @@ def test_setting_allows_duplicate_labels_raises(self, data):
)
def test_series_raises(self, func):
s = pd.Series([0, 1], index=["a", "b"]).set_flags(allows_duplicate_labels=False)
with pytest.raises(pd.errors.DuplicateLabelError):
msg = "Index has duplicates."
with pytest.raises(pd.errors.DuplicateLabelError, match=msg):
func(s)

@pytest.mark.parametrize(
Expand Down Expand Up @@ -332,7 +335,8 @@ def test_getitem_raises(self, getter, target):
else:
target = df

with pytest.raises(pd.errors.DuplicateLabelError):
msg = "Index has duplicates."
with pytest.raises(pd.errors.DuplicateLabelError, match=msg):
getter(target)

@pytest.mark.parametrize(
Expand All @@ -352,7 +356,8 @@ def test_getitem_raises(self, getter, target):
],
)
def test_concat_raises(self, objs, kwargs):
with pytest.raises(pd.errors.DuplicateLabelError):
msg = "Index has duplicates."
with pytest.raises(pd.errors.DuplicateLabelError, match=msg):
pd.concat(objs, **kwargs)

@not_implemented
Expand All @@ -361,7 +366,8 @@ def test_merge_raises(self):
allows_duplicate_labels=False
)
b = pd.DataFrame({"B": [0, 1, 2]}, index=["a", "b", "b"])
with pytest.raises(pd.errors.DuplicateLabelError):
msg = "Index has duplicates."
with pytest.raises(pd.errors.DuplicateLabelError, match=msg):
pd.merge(a, b, left_index=True, right_index=True)


Expand All @@ -381,13 +387,14 @@ def test_merge_raises(self):
ids=lambda x: type(x).__name__,
)
def test_raises_basic(idx):
with pytest.raises(pd.errors.DuplicateLabelError):
msg = "Index has duplicates."
with pytest.raises(pd.errors.DuplicateLabelError, match=msg):
pd.Series(1, index=idx).set_flags(allows_duplicate_labels=False)

with pytest.raises(pd.errors.DuplicateLabelError):
with pytest.raises(pd.errors.DuplicateLabelError, match=msg):
pd.DataFrame({"A": [1, 1]}, index=idx).set_flags(allows_duplicate_labels=False)

with pytest.raises(pd.errors.DuplicateLabelError):
with pytest.raises(pd.errors.DuplicateLabelError, match=msg):
pd.DataFrame([[1, 2]], columns=idx).set_flags(allows_duplicate_labels=False)


Expand All @@ -412,7 +419,8 @@ def test_format_duplicate_labels_message_multi():

def test_dataframe_insert_raises():
df = pd.DataFrame({"A": [1, 2]}).set_flags(allows_duplicate_labels=False)
with pytest.raises(ValueError, match="Cannot specify"):
msg = "Cannot specify"
with pytest.raises(ValueError, match=msg):
df.insert(0, "A", [3, 4], allow_duplicates=True)


Expand Down

0 comments on commit 43bf412

Please sign in to comment.