Skip to content

Commit 437654c

Browse files
sinhrksjreback
authored andcommitted
TST: Fix assertNotIsInstance msg
Author: sinhrks <[email protected]> Closes #13091 from sinhrks/test_notisinstance and squashes the following commits: 51044b5 [sinhrks] TST: Fix assertNotIsInstance msg
1 parent dd0064b commit 437654c

File tree

2 files changed

+21
-6
lines changed

2 files changed

+21
-6
lines changed

pandas/tests/test_testing.py

+15
Original file line numberDiff line numberDiff line change
@@ -627,6 +627,21 @@ def test_frame_equal_message(self):
627627
by_blocks=True)
628628

629629

630+
class TestIsInstance(tm.TestCase):
631+
632+
def test_isinstance(self):
633+
634+
expected = "Expected type "
635+
with assertRaisesRegexp(AssertionError, expected):
636+
tm.assertIsInstance(1, pd.Series)
637+
638+
def test_notisinstance(self):
639+
640+
expected = "Input must not be type "
641+
with assertRaisesRegexp(AssertionError, expected):
642+
tm.assertNotIsInstance(pd.Series([1]), pd.Series)
643+
644+
630645
class TestRNGContext(unittest.TestCase):
631646

632647
def test_RNGContext(self):

pandas/util/testing.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -868,9 +868,9 @@ def assertIsInstance(obj, cls, msg=''):
868868
"""Test that obj is an instance of cls
869869
(which can be a class or a tuple of classes,
870870
as supported by isinstance())."""
871-
assert isinstance(obj, cls), (
872-
"%sExpected object to be of type %r, found %r instead" % (
873-
msg, cls, type(obj)))
871+
if not isinstance(obj, cls):
872+
err_msg = "{0}Expected type {1}, found {2} instead"
873+
raise AssertionError(err_msg.format(msg, cls, type(obj)))
874874

875875

876876
def assert_isinstance(obj, class_type_or_tuple, msg=''):
@@ -882,9 +882,9 @@ def assertNotIsInstance(obj, cls, msg=''):
882882
"""Test that obj is not an instance of cls
883883
(which can be a class or a tuple of classes,
884884
as supported by isinstance())."""
885-
assert not isinstance(obj, cls), (
886-
"%sExpected object to be of type %r, found %r instead" % (
887-
msg, cls, type(obj)))
885+
if isinstance(obj, cls):
886+
err_msg = "{0}Input must not be type {1}"
887+
raise AssertionError(err_msg.format(msg, cls))
888888

889889

890890
def assert_categorical_equal(res, exp):

0 commit comments

Comments
 (0)