Skip to content

ENH: Add new specialized asserts for tests #6376

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

Merged
merged 1 commit into from
Feb 17, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions pandas/tests/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ def test_shallow_copying(self):
original = self.container.copy()
assert_isinstance(self.container.view(), FrozenNDArray)
self.assert_(not isinstance(self.container.view(np.ndarray), FrozenNDArray))
self.assert_(self.container.view() is not self.container)
self.assertIsNot(self.container.view(), self.container)
self.assert_numpy_array_equal(self.container, original)
# shallow copy should be the same too
assert_isinstance(self.container._shallow_copy(), FrozenNDArray)
Expand All @@ -115,7 +115,7 @@ def test_values(self):
n = original[0] + 15
vals = self.container.values()
self.assert_numpy_array_equal(original, vals)
self.assert_(original is not vals)
self.assertIsNot(original, vals)
vals[0] = n
self.assert_numpy_array_equal(self.container, original)
self.assertEqual(vals[0], n)
Expand Down
2 changes: 1 addition & 1 deletion pandas/tests/test_index.py
Original file line number Diff line number Diff line change
Expand Up @@ -1352,7 +1352,7 @@ def test_inplace_mutation_resets_values(self):
mi2 = MultiIndex(levels=levels2, labels=labels)
vals = mi1.values.copy()
vals2 = mi2.values.copy()
self.assert_(mi1._tuples is not None)
self.assertIsNotNone(mi1._tuples)

# make sure level setting works
new_vals = mi1.set_levels(levels2).values
Expand Down
10 changes: 5 additions & 5 deletions pandas/tests/test_internals.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,15 +142,15 @@ def test_merge(self):

def test_copy(self):
cop = self.fblock.copy()
self.assert_(cop is not self.fblock)
self.assertIsNot(cop, self.fblock)
assert_block_equal(self.fblock, cop)

def test_items(self):
cols = self.fblock.items
self.assert_numpy_array_equal(cols, ['a', 'c', 'e'])

cols2 = self.fblock.items
self.assert_(cols is cols2)
self.assertIs(cols, cols2)

def test_assign_ref_items(self):
new_cols = Index(['foo', 'bar', 'baz', 'quux', 'hi'])
Expand Down Expand Up @@ -305,8 +305,8 @@ def test_duplicate_item_failure(self):
self.assertRaises(AssertionError, mgr._set_ref_locs, do_refs=True)

def test_contains(self):
self.assert_('a' in self.mgr)
self.assert_('baz' not in self.mgr)
self.assertIn('a', self.mgr)
self.assertNotIn('baz', self.mgr)

def test_pickle(self):
import pickle
Expand All @@ -318,7 +318,7 @@ def test_pickle(self):
assert_frame_equal(DataFrame(self.mgr), DataFrame(mgr2))

# share ref_items
self.assert_(mgr2.blocks[0].ref_items is mgr2.blocks[1].ref_items)
self.assertIs(mgr2.blocks[0].ref_items, mgr2.blocks[1].ref_items)

# GH2431
self.assertTrue(hasattr(mgr2, "_is_consolidated"))
Expand Down
4 changes: 2 additions & 2 deletions pandas/tests/test_series.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ def test_copy_index_name_checking(self):
# making a copy

self.ts.index.name = None
self.assert_(self.ts.index.name is None)
self.assert_(self.ts is self.ts)
self.assertIsNone(self.ts.index.name)
self.assertIs(self.ts, self.ts)
cp = self.ts.copy()
cp.index.name = 'foo'
print(self.ts.index.name)
Expand Down
25 changes: 25 additions & 0 deletions pandas/util/testing.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,31 @@ def assert_numpy_array_equal(self, np_array, assert_equal):
return
raise AssertionError('{0} is not equal to {1}.'.format(np_array, assert_equal))

def assertIs(self, a, b, msg=''):
"""Checks that 'a' is 'b'"""
assert a is b, "%s: %r is not %r" % (msg.format(a,b), a, b)

def assertIsNot(self, a, b, msg=''):
"""Checks that 'a' is not 'b'"""
assert a is not b, "%s: %r is %r" % (msg.format(a,b), a, b)

def assertIsNone(self, a, msg=''):
"""Checks that 'a' is None"""
self.assertIs(a, None, msg)

def assertIsNotNone(self, a, msg=''):
"""Checks that 'a' is not None"""
self.assertIsNot(a, None, msg)

def assertIn(self, a, b, msg=''):
"""Checks that 'a' is in 'b'"""
assert a in b, "%s: %r is not in %r" % (msg.format(a,b), a, b)

def assertNotIn(self, a, b, msg=''):
"""Checks that 'a' is not in 'b'"""
assert a not in b, "%s: %r is in %r" % (msg.format(a,b), a, b)


# NOTE: don't pass an NDFrame or index to this function - may not handle it
# well.
assert_almost_equal = _testing.assert_almost_equal
Expand Down