Skip to content

Commit

Permalink
TST: Fix assertNotIsInstance msg
Browse files Browse the repository at this point in the history
Author: sinhrks <[email protected]>

Closes #13091 from sinhrks/test_notisinstance and squashes the following commits:

51044b5 [sinhrks] TST: Fix assertNotIsInstance msg
  • Loading branch information
sinhrks authored and jreback committed May 6, 2016
1 parent dd0064b commit 437654c
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 6 deletions.
15 changes: 15 additions & 0 deletions pandas/tests/test_testing.py
Original file line number Diff line number Diff line change
Expand Up @@ -627,6 +627,21 @@ def test_frame_equal_message(self):
by_blocks=True)


class TestIsInstance(tm.TestCase):

def test_isinstance(self):

expected = "Expected type "
with assertRaisesRegexp(AssertionError, expected):
tm.assertIsInstance(1, pd.Series)

def test_notisinstance(self):

expected = "Input must not be type "
with assertRaisesRegexp(AssertionError, expected):
tm.assertNotIsInstance(pd.Series([1]), pd.Series)


class TestRNGContext(unittest.TestCase):

def test_RNGContext(self):
Expand Down
12 changes: 6 additions & 6 deletions pandas/util/testing.py
Original file line number Diff line number Diff line change
Expand Up @@ -868,9 +868,9 @@ def assertIsInstance(obj, cls, msg=''):
"""Test that obj is an instance of cls
(which can be a class or a tuple of classes,
as supported by isinstance())."""
assert isinstance(obj, cls), (
"%sExpected object to be of type %r, found %r instead" % (
msg, cls, type(obj)))
if not isinstance(obj, cls):
err_msg = "{0}Expected type {1}, found {2} instead"
raise AssertionError(err_msg.format(msg, cls, type(obj)))


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


def assert_categorical_equal(res, exp):
Expand Down

0 comments on commit 437654c

Please sign in to comment.