[Python-Dev] [Python-checkins] cpython: #11572: improvements to copy module tests along with removal of old test suite (original) (raw)
Jim Jewett jimjjewett at gmail.com
Fri Aug 5 23:55:33 CEST 2011
- Previous message: [Python-Dev] cpython (2.7): note Ellipsis syntax
- Next message: [Python-Dev] [Python-checkins] cpython: #11572: improvements to copy module tests along with removal of old test suite
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Why was the old test suite removed?
Even if everything is covered by the test file (and that isn't clear from this checkin), I don't see anything wrong with a quick test that doesn't require loading the whole testing apparatus. (I would have no objection to including a comment saying that the majority of the tests are in the test file; I just wonder why they have to be removed entirely.)
On Fri, Aug 5, 2011 at 5:06 PM, sandro.tosi <python-checkins at python.org> wrote:
http://hg.python.org/cpython/rev/74e79b2c114a changeset: 71749:74e79b2c114a user: Sandro Tosi <sandro.tosi at gmail.com> date: Fri Aug 05 23:05:35 2011 +0200 summary: #11572: improvements to copy module tests along with removal of old test suite
files: Lib/copy.py | 65 ----------- Lib/test/testcopy.py | 168 ++++++++++++++++------------- 2 files changed, 95 insertions(+), 138 deletions(-)
diff --git a/Lib/copy.py b/Lib/copy.py --- a/Lib/copy.py +++ b/Lib/copy.py @@ -323,68 +323,3 @@ # Helper for instance creation without calling init class EmptyClass: pass - -def test(): - l = [None, 1, 2, 3.14, 'xyzzy', (1, 2), [3.14, 'abc'], - {'abc': 'ABC'}, (), [], {}] - l1 = copy(l) - print(l1==l) - l1 = map(copy, l) - print(l1==l) - l1 = deepcopy(l) - print(l1==l) - class C: - def init(self, arg=None): - self.a = 1 - self.arg = arg - if name == 'main': - import sys - file = sys.argv[0] - else: - file = file - self.fp = open(file) - self.fp.close() - def getstate(self): - return {'a': self.a, 'arg': self.arg} - def setstate(self, state): - for key, value in state.items(): - setattr(self, key, value) - def deepcopy(self, memo=None): - new = self.class(deepcopy(self.arg, memo)) - new.a = self.a - return new - c = C('argument sketch') - l.append(c) - l2 = copy(l) - print(l == l2) - print(l) - print(l2) - l2 = deepcopy(l) - print(l == l2) - print(l) - print(l2) - l.append({l[1]: l, 'xyz': l[2]}) - l3 = copy(l) - import reprlib - print(map(reprlib.repr, l)) - print(map(reprlib.repr, l1)) - print(map(reprlib.repr, l2)) - print(map(reprlib.repr, l3)) - l3 = deepcopy(l) - print(map(reprlib.repr, l)) - print(map(reprlib.repr, l1)) - print(map(reprlib.repr, l2)) - print(map(reprlib.repr, l3)) - class odict(dict): - def init(self, d = {}): - self.a = 99 - dict.init(self, d) - def setitem(self, k, i): - dict.setitem(self, k, i) - self.a - o = odict({"A" : "B"}) - x = deepcopy(o) - print(o, x) - -if name == 'main': - test() diff --git a/Lib/test/testcopy.py b/Lib/test/testcopy.py --- a/Lib/test/testcopy.py +++ b/Lib/test/testcopy.py @@ -17,7 +17,7 @@ # Attempt full line coverage of copy.py from top to bottom def testexceptions(self): - self.assertTrue(copy.Error is copy.error) + self.assertIs(copy.Error, copy.error) self.assertTrue(issubclass(copy.Error, Exception)) # The copy() method @@ -54,20 +54,26 @@ def testcopyreduceex(self): class C(object): def reduceex(self, proto): + c.append(1) return "" def reduce(self): - raise support.TestFailed("shouldn't call this") + self.fail("shouldn't call this") + c = [] x = C() y = copy.copy(x) - self.assertTrue(y is x) + self.assertIs(y, x) + self.assertEqual(c, [1]) def testcopyreduce(self): class C(object): def reduce(self): + c.append(1) return "" + c = [] x = C() y = copy.copy(x) - self.assertTrue(y is x) + self.assertIs(y, x) + self.assertEqual(c, [1]) def testcopycant(self): class C(object): @@ -91,7 +97,7 @@ "hello", "hello\u1234", f.code, NewStyle, range(10), Classic, max] for x in tests: - self.assertTrue(copy.copy(x) is x, repr(x)) + self.assertIs(copy.copy(x), x) def testcopylist(self): x = [1, 2, 3] @@ -185,9 +191,9 @@ x = [x, x] y = copy.deepcopy(x) self.assertEqual(y, x) - self.assertTrue(y is not x) - self.assertTrue(y[0] is not x[0]) - self.assertTrue(y[0] is y[1]) + self.assertIsNot(y, x) + self.assertIsNot(y[0], x[0]) + self.assertIs(y[0], y[1]) def testdeepcopyissubclass(self): # XXX Note: there's no way to test the TypeError coming out of @@ -227,20 +233,26 @@ def testdeepcopyreduceex(self): class C(object): def reduceex(self, proto): + c.append(1) return "" def reduce(self): - raise support.TestFailed("shouldn't call this") + self.fail("shouldn't call this") + c = [] x = C() y = copy.deepcopy(x) - self.assertTrue(y is x) + self.assertIs(y, x) + self.assertEqual(c, [1]) def testdeepcopyreduce(self): class C(object): def reduce(self): + c.append(1) return "" + c = [] x = C() y = copy.deepcopy(x) - self.assertTrue(y is x) + self.assertIs(y, x) + self.assertEqual(c, [1]) def testdeepcopycant(self): class C(object): @@ -264,14 +276,14 @@ "hello", "hello\u1234", f.code, NewStyle, range(10), Classic, max] for x in tests: - self.assertTrue(copy.deepcopy(x) is x, repr(x)) + self.assertIs(copy.deepcopy(x), x) def testdeepcopylist(self): x = [[1, 2], 3] y = copy.deepcopy(x) self.assertEqual(y, x) - self.assertTrue(x is not y) - self.assertTrue(x[0] is not y[0]) + self.assertIsNot(x, y) + self.assertIsNot(x[0], y[0]) def testdeepcopyreflexivelist(self): x = [] @@ -279,16 +291,26 @@ y = copy.deepcopy(x) for op in comparisons: self.assertRaises(RuntimeError, op, y, x) - self.assertTrue(y is not x) - self.assertTrue(y[0] is y) + self.assertIsNot(y, x) + self.assertIs(y[0], y) self.assertEqual(len(y), 1) + def testdeepcopyemptytuple(self): + x = () + y = copy.deepcopy(x) + self.assertIs(x, y) + def testdeepcopytuple(self): x = ([1, 2], 3) y = copy.deepcopy(x) self.assertEqual(y, x) - self.assertTrue(x is not y) - self.assertTrue(x[0] is not y[0]) + self.assertIsNot(x, y) + self.assertIsNot(x[0], y[0]) + + def testdeepcopytupleofimmutables(self): + x = ((1, 2), 3) + y = copy.deepcopy(x) + self.assertIs(x, y) def testdeepcopyreflexivetuple(self): x = ([],) @@ -296,16 +318,16 @@ y = copy.deepcopy(x) for op in comparisons: self.assertRaises(RuntimeError, op, y, x) - self.assertTrue(y is not x) - self.assertTrue(y[0] is not x[0]) - self.assertTrue(y[0][0] is y) + self.assertIsNot(y, x) + self.assertIsNot(y[0], x[0]) + self.assertIs(y[0][0], y) def testdeepcopydict(self): x = {"foo": [1, 2], "bar": 3} y = copy.deepcopy(x) self.assertEqual(y, x) - self.assertTrue(x is not y) - self.assertTrue(x["foo"] is not y["foo"]) + self.assertIsNot(x, y) + self.assertIsNot(x["foo"], y["foo"]) def testdeepcopyreflexivedict(self): x = {} @@ -315,8 +337,8 @@ self.assertRaises(TypeError, op, y, x) for op in equalitycomparisons: self.assertRaises(RuntimeError, op, y, x) - self.assertTrue(y is not x) - self.assertTrue(y['foo'] is y) + self.assertIsNot(y, x) + self.assertIs(y['foo'], y) self.assertEqual(len(y), 1) def testdeepcopykeepalive(self): @@ -349,7 +371,7 @@ x = C([42]) y = copy.deepcopy(x) self.assertEqual(y, x) - self.assertTrue(y.foo is not x.foo) + self.assertIsNot(y.foo, x.foo) def testdeepcopyinstdeepcopy(self): class C: @@ -362,8 +384,8 @@ x = C([42]) y = copy.deepcopy(x) self.assertEqual(y, x) - self.assertTrue(y is not x) - self.assertTrue(y.foo is not x.foo) + self.assertIsNot(y, x) + self.assertIsNot(y.foo, x.foo) def testdeepcopyinstgetinitargs(self): class C: @@ -376,8 +398,8 @@ x = C([42]) y = copy.deepcopy(x) self.assertEqual(y, x) - self.assertTrue(y is not x) - self.assertTrue(y.foo is not x.foo) + self.assertIsNot(y, x) + self.assertIsNot(y.foo, x.foo) def testdeepcopyinstgetstate(self): class C: @@ -390,8 +412,8 @@ x = C([42]) y = copy.deepcopy(x) self.assertEqual(y, x) - self.assertTrue(y is not x) - self.assertTrue(y.foo is not x.foo) + self.assertIsNot(y, x) + self.assertIsNot(y.foo, x.foo) def testdeepcopyinstsetstate(self): class C: @@ -404,8 +426,8 @@ x = C([42]) y = copy.deepcopy(x) self.assertEqual(y, x) - self.assertTrue(y is not x) - self.assertTrue(y.foo is not x.foo) + self.assertIsNot(y, x) + self.assertIsNot(y.foo, x.foo) def testdeepcopyinstgetstatesetstate(self): class C: @@ -420,8 +442,8 @@ x = C([42]) y = copy.deepcopy(x) self.assertEqual(y, x) - self.assertTrue(y is not x) - self.assertTrue(y.foo is not x.foo) + self.assertIsNot(y, x) + self.assertIsNot(y.foo, x.foo) def testdeepcopyreflexiveinst(self): class C: @@ -429,8 +451,8 @@ x = C() x.foo = x y = copy.deepcopy(x) - self.assertTrue(y is not x) - self.assertTrue(y.foo is y) + self.assertIsNot(y, x) + self.assertIs(y.foo, y) # reconstruct() @@ -440,9 +462,9 @@ return "" x = C() y = copy.copy(x) - self.assertTrue(y is x) + self.assertIs(y, x) y = copy.deepcopy(x) - self.assertTrue(y is x) + self.assertIs(y, x) def testreconstructnostate(self): class C(object): @@ -451,9 +473,9 @@ x = C() x.foo = 42 y = copy.copy(x) - self.assertTrue(y.class is x.class) + self.assertIs(y.class, x.class) y = copy.deepcopy(x) - self.assertTrue(y.class is x.class) + self.assertIs(y.class, x.class) def testreconstructstate(self): class C(object): @@ -467,7 +489,7 @@ self.assertEqual(y, x) y = copy.deepcopy(x) self.assertEqual(y, x) - self.assertTrue(y.foo is not x.foo) + self.assertIsNot(y.foo, x.foo) def testreconstructstatesetstate(self): class C(object): @@ -483,7 +505,7 @@ self.assertEqual(y, x) y = copy.deepcopy(x) self.assertEqual(y, x) - self.assertTrue(y.foo is not x.foo) + self.assertIsNot(y.foo, x.foo) def testreconstructreflexive(self): class C(object): @@ -491,8 +513,8 @@ x = C() x.foo = x y = copy.deepcopy(x) - self.assertTrue(y is not x) - self.assertTrue(y.foo is y) + self.assertIsNot(y, x) + self.assertIs(y.foo, y) # Additions for Python 2.3 and pickle protocol 2 @@ -506,12 +528,12 @@ x = C([[1, 2], 3]) y = copy.copy(x) self.assertEqual(x, y) - self.assertTrue(x is not y) - self.assertTrue(x[0] is y[0]) + self.assertIsNot(x, y) + self.assertIs(x[0], y[0]) y = copy.deepcopy(x) self.assertEqual(x, y) - self.assertTrue(x is not y) - self.assertTrue(x[0] is not y[0]) + self.assertIsNot(x, y) + self.assertIsNot(x[0], y[0]) def testreduce5tuple(self): class C(dict): @@ -523,12 +545,12 @@ x = C([("foo", [1, 2]), ("bar", 3)]) y = copy.copy(x) self.assertEqual(x, y) - self.assertTrue(x is not y) - self.assertTrue(x["foo"] is y["foo"]) + self.assertIsNot(x, y) + self.assertIs(x["foo"], y["foo"]) y = copy.deepcopy(x) self.assertEqual(x, y) - self.assertTrue(x is not y) - self.assertTrue(x["foo"] is not y["foo"]) + self.assertIsNot(x, y) + self.assertIsNot(x["foo"], y["foo"]) def testcopyslots(self): class C(object): @@ -536,7 +558,7 @@ x = C() x.foo = [42] y = copy.copy(x) - self.assertTrue(x.foo is y.foo) + self.assertIs(x.foo, y.foo) def testdeepcopyslots(self): class C(object): @@ -545,7 +567,7 @@ x.foo = [42] y = copy.deepcopy(x) self.assertEqual(x.foo, y.foo) - self.assertTrue(x.foo is not y.foo) + self.assertIsNot(x.foo, y.foo) def testdeepcopydictsubclass(self): class C(dict): @@ -562,7 +584,7 @@ y = copy.deepcopy(x) self.assertEqual(x, y) self.assertEqual(x.keys, y.keys) - self.assertTrue(x is not y) + self.assertIsNot(x, y) x['bar'] = 1 self.assertNotEqual(x, y) self.assertNotEqual(x.keys, y.keys) @@ -575,8 +597,8 @@ y = copy.copy(x) self.assertEqual(list(x), list(y)) self.assertEqual(x.foo, y.foo) - self.assertTrue(x[0] is y[0]) - self.assertTrue(x.foo is y.foo) + self.assertIs(x[0], y[0]) + self.assertIs(x.foo, y.foo) def testdeepcopylistsubclass(self): class C(list): @@ -586,8 +608,8 @@ y = copy.deepcopy(x) self.assertEqual(list(x), list(y)) self.assertEqual(x.foo, y.foo) - self.assertTrue(x[0] is not y[0]) - self.assertTrue(x.foo is not y.foo) + self.assertIsNot(x[0], y[0]) + self.assertIsNot(x.foo, y.foo) def testcopytuplesubclass(self): class C(tuple): @@ -604,8 +626,8 @@ self.assertEqual(tuple(x), ([1, 2], 3)) y = copy.deepcopy(x) self.assertEqual(tuple(y), ([1, 2], 3)) - self.assertTrue(x is not y) - self.assertTrue(x[0] is not y[0]) + self.assertIsNot(x, y) + self.assertIsNot(x[0], y[0]) def testgetstateexc(self): class EvilState(object): @@ -633,10 +655,10 @@ obj = C() x = weakref.ref(obj) y = copy(x) - self.assertTrue(y is x) + self.assertIs(y, x) del obj y = copy(x) - self.assertTrue(y is x) + self.assertIs(y, x) def testcopyweakref(self): self.checkweakref(copy.copy) @@ -652,7 +674,7 @@ u[a] = b u[c] = d v = copy.copy(u) - self.assertFalse(v is u) + self.assertIsNot(v, u) self.assertEqual(v, u) self.assertEqual(v[a], b) self.assertEqual(v[c], d) @@ -682,8 +704,8 @@ v = copy.deepcopy(u) self.assertNotEqual(v, u) self.assertEqual(len(v), 2) - self.assertFalse(v[a] is b) - self.assertFalse(v[c] is d) + self.assertIsNot(v[a], b) + self.assertIsNot(v[c], d) self.assertEqual(v[a].i, b.i) self.assertEqual(v[c].i, d.i) del c @@ -702,12 +724,12 @@ self.assertNotEqual(v, u) self.assertEqual(len(v), 2) (x, y), (z, t) = sorted(v.items(), key=lambda pair: pair[0].i) - self.assertFalse(x is a) + self.assertIsNot(x, a) self.assertEqual(x.i, a.i) - self.assertTrue(y is b) - self.assertFalse(z is c) + self.assertIs(y, b) + self.assertIsNot(z, c) self.assertEqual(z.i, c.i) - self.assertTrue(t is d) + self.assertIs(t, d) del x, y, z, t del d self.assertEqual(len(v), 1) @@ -720,7 +742,7 @@ f.b = f.m g = copy.deepcopy(f) self.assertEqual(g.m, g.b) - self.assertTrue(g.b.self is g) + self.assertIs(g.b.self, g) g.b()
-- Repository URL: http://hg.python.org/cpython
Python-checkins mailing list Python-checkins at python.org http://mail.python.org/mailman/listinfo/python-checkins
- Previous message: [Python-Dev] cpython (2.7): note Ellipsis syntax
- Next message: [Python-Dev] [Python-checkins] cpython: #11572: improvements to copy module tests along with removal of old test suite
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]