Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TST: Remove bare pytest.raises #31079

Merged
merged 11 commits into from
Jan 24, 2020
24 changes: 14 additions & 10 deletions pandas/tests/arithmetic/test_object.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,9 +155,10 @@ def test_objarr_add_invalid(self, op, box_with_array):
obj_ser.name = "objects"

obj_ser = tm.box_expected(obj_ser, box)
with pytest.raises(Exception):
msg = "can only concatenate str|unsupported operand type"
with pytest.raises(Exception, match=msg):
op(obj_ser, 1)
with pytest.raises(Exception):
with pytest.raises(Exception, match=msg):
op(obj_ser, np.array(1, dtype=np.int64))

# TODO: Moved from tests.series.test_operators; needs cleanup
Expand Down Expand Up @@ -281,13 +282,14 @@ def test_add(self):

def test_sub_fail(self):
index = tm.makeStringIndex(100)
with pytest.raises(TypeError):
msg = "unsupported operand type|<class 'list'>" # Error for index.toList()-list is uninformative?
with pytest.raises(TypeError, match=msg):
index - "a"
with pytest.raises(TypeError):
with pytest.raises(TypeError, match=msg):
index - index
with pytest.raises(TypeError):
with pytest.raises(TypeError, match=msg):
index - index.tolist()
with pytest.raises(TypeError):
with pytest.raises(TypeError, match=msg):
index.tolist() - index
gdex1 marked this conversation as resolved.
Show resolved Hide resolved

def test_sub_object(self):
Expand All @@ -301,10 +303,11 @@ def test_sub_object(self):
result = index - pd.Index([Decimal(1), Decimal(1)])
tm.assert_index_equal(result, expected)

with pytest.raises(TypeError):
msg = "unsupported operand type"
with pytest.raises(TypeError, match=msg):
index - "foo"

with pytest.raises(TypeError):
with pytest.raises(TypeError, match=msg):
index - np.array([2, "foo"])

def test_rsub_object(self):
Expand All @@ -318,8 +321,9 @@ def test_rsub_object(self):
result = np.array([Decimal(2), Decimal(2)]) - index
tm.assert_index_equal(result, expected)

with pytest.raises(TypeError):
msg = "unsupported operand type"
with pytest.raises(TypeError, match=msg):
"foo" - index

with pytest.raises(TypeError):
with pytest.raises(TypeError, match=msg):
np.array([True, pd.Timestamp.now()]) - index