From 58018363df159ebe5c9f7c3394a89d028b9b6dcb Mon Sep 17 00:00:00 2001 From: Katie Atkinson Date: Tue, 11 Feb 2014 01:59:19 +0000 Subject: [PATCH 1/3] BUG: #6175 removed assert_ from test_base.py. --- pandas/tests/test_base.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/pandas/tests/test_base.py b/pandas/tests/test_base.py index 3cb3528b6fff4..1325e9b7ba9f3 100644 --- a/pandas/tests/test_base.py +++ b/pandas/tests/test_base.py @@ -99,10 +99,10 @@ def setUp(self): 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.assert_(np.array_equal(self.container, original)) + self.assertIsInstance(self.container.view(), FrozenNDArray) + self.assertNotIsInstance(self.container.view(np.ndarray), FrozenNDArray) + self.assertIsNot(self.container.view(), self.container) + self.assert_numpy_array_equals(self.container, original) # shallow copy should be the same too assert_isinstance(self.container._shallow_copy(), FrozenNDArray) # setting should not be allowed @@ -114,10 +114,10 @@ def test_values(self): original = self.container.view(np.ndarray).copy() n = original[0] + 15 vals = self.container.values() - self.assert_(np.array_equal(original, vals)) - self.assert_(original is not vals) + self.assert_numpy_array_equals(original, vals) + self.assertIsNot(original, vals) vals[0] = n - self.assert_(np.array_equal(self.container, original)) + self.assert_numpy_array_equals(self.container, original) self.assertEqual(vals[0], n) From 5c3240227ecfc3183f7f24eb7bbb728118e62714 Mon Sep 17 00:00:00 2001 From: Katie Atkinson Date: Tue, 18 Feb 2014 04:03:36 +0000 Subject: [PATCH 2/3] Adding back test_base.py, after accidental delete --- pandas/tests/test_base.py | 129 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 129 insertions(+) create mode 100644 pandas/tests/test_base.py diff --git a/pandas/tests/test_base.py b/pandas/tests/test_base.py new file mode 100644 index 0000000000000..1325e9b7ba9f3 --- /dev/null +++ b/pandas/tests/test_base.py @@ -0,0 +1,129 @@ +import re +import numpy as np +import pandas.compat as compat +from pandas.compat import u +from pandas.core.base import FrozenList, FrozenNDArray +from pandas.util.testing import assertRaisesRegexp, assert_isinstance +import pandas.util.testing as tm + +class CheckStringMixin(object): + def test_string_methods_dont_fail(self): + repr(self.container) + str(self.container) + bytes(self.container) + if not compat.PY3: + unicode(self.container) + + def test_tricky_container(self): + if not hasattr(self, 'unicode_container'): + raise nose.SkipTest('Need unicode_container to test with this') + repr(self.unicode_container) + str(self.unicode_container) + bytes(self.unicode_container) + if not compat.PY3: + unicode(self.unicode_container) + + +class CheckImmutable(object): + mutable_regex = re.compile('does not support mutable operations') + + def check_mutable_error(self, *args, **kwargs): + # pass whatever functions you normally would to assertRaises (after the Exception kind) + assertRaisesRegexp(TypeError, self.mutable_regex, *args, **kwargs) + + def test_no_mutable_funcs(self): + def setitem(): self.container[0] = 5 + + self.check_mutable_error(setitem) + + def setslice(): self.container[1:2] = 3 + + self.check_mutable_error(setslice) + + def delitem(): del self.container[0] + + self.check_mutable_error(delitem) + + def delslice(): del self.container[0:3] + + self.check_mutable_error(delslice) + mutable_methods = getattr(self, "mutable_methods", []) + for meth in mutable_methods: + self.check_mutable_error(getattr(self.container, meth)) + + def test_slicing_maintains_type(self): + result = self.container[1:2] + expected = self.lst[1:2] + self.check_result(result, expected) + + def check_result(self, result, expected, klass=None): + klass = klass or self.klass + assert_isinstance(result, klass) + self.assertEqual(result, expected) + + +class TestFrozenList(CheckImmutable, CheckStringMixin, tm.TestCase): + mutable_methods = ('extend', 'pop', 'remove', 'insert') + unicode_container = FrozenList([u("\u05d0"), u("\u05d1"), "c"]) + + def setUp(self): + self.lst = [1, 2, 3, 4, 5] + self.container = FrozenList(self.lst) + self.klass = FrozenList + + def test_add(self): + result = self.container + (1, 2, 3) + expected = FrozenList(self.lst + [1, 2, 3]) + self.check_result(result, expected) + + result = (1, 2, 3) + self.container + expected = FrozenList([1, 2, 3] + self.lst) + self.check_result(result, expected) + + def test_inplace(self): + q = r = self.container + q += [5] + self.check_result(q, self.lst + [5]) + # other shouldn't be mutated + self.check_result(r, self.lst) + + +class TestFrozenNDArray(CheckImmutable, CheckStringMixin, tm.TestCase): + mutable_methods = ('put', 'itemset', 'fill') + unicode_container = FrozenNDArray([u("\u05d0"), u("\u05d1"), "c"]) + + def setUp(self): + self.lst = [3, 5, 7, -2] + self.container = FrozenNDArray(self.lst) + self.klass = FrozenNDArray + + def test_shallow_copying(self): + original = self.container.copy() + self.assertIsInstance(self.container.view(), FrozenNDArray) + self.assertNotIsInstance(self.container.view(np.ndarray), FrozenNDArray) + self.assertIsNot(self.container.view(), self.container) + self.assert_numpy_array_equals(self.container, original) + # shallow copy should be the same too + assert_isinstance(self.container._shallow_copy(), FrozenNDArray) + # setting should not be allowed + def testit(container): container[0] = 16 + + self.check_mutable_error(testit, self.container) + + def test_values(self): + original = self.container.view(np.ndarray).copy() + n = original[0] + 15 + vals = self.container.values() + self.assert_numpy_array_equals(original, vals) + self.assertIsNot(original, vals) + vals[0] = n + self.assert_numpy_array_equals(self.container, original) + self.assertEqual(vals[0], n) + + +if __name__ == '__main__': + import nose + + nose.runmodule(argv=[__file__, '-vvs', '-x', '--pdb', '--pdb-failure'], + # '--with-coverage', '--cover-package=pandas.core'], + exit=False) From 2b227c2d8c3a5ec690c9f4d602e880088852b250 Mon Sep 17 00:00:00 2001 From: Katie Atkinson Date: Tue, 18 Feb 2014 04:22:13 +0000 Subject: [PATCH 3/3] This should create a passing test without assert_ --- pandas/tests/test_base.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pandas/tests/test_base.py b/pandas/tests/test_base.py index 1325e9b7ba9f3..a30ce9a7dcd87 100644 --- a/pandas/tests/test_base.py +++ b/pandas/tests/test_base.py @@ -102,9 +102,9 @@ def test_shallow_copying(self): self.assertIsInstance(self.container.view(), FrozenNDArray) self.assertNotIsInstance(self.container.view(np.ndarray), FrozenNDArray) self.assertIsNot(self.container.view(), self.container) - self.assert_numpy_array_equals(self.container, original) + self.assert_numpy_array_equal(self.container, original) # shallow copy should be the same too - assert_isinstance(self.container._shallow_copy(), FrozenNDArray) + self.assertIsInstance(self.container._shallow_copy(), FrozenNDArray) # setting should not be allowed def testit(container): container[0] = 16 @@ -114,10 +114,10 @@ def test_values(self): original = self.container.view(np.ndarray).copy() n = original[0] + 15 vals = self.container.values() - self.assert_numpy_array_equals(original, vals) + self.assert_numpy_array_equal(original, vals) self.assertIsNot(original, vals) vals[0] = n - self.assert_numpy_array_equals(self.container, original) + self.assert_numpy_array_equal(self.container, original) self.assertEqual(vals[0], n)