From fd370c0ef71a554fdc950305bb9eb418ca6805e0 Mon Sep 17 00:00:00 2001 From: "W. Trevor King" Date: Tue, 31 Aug 2010 08:44:49 -0400 Subject: [PATCH] Check data copying in Curve.__copy__ and .__deepcopy__ doctests. --- hooke/curve.py | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/hooke/curve.py b/hooke/curve.py index bc8138a..fc8701b 100644 --- a/hooke/curve.py +++ b/hooke/curve.py @@ -292,7 +292,12 @@ class Curve (object): >>> class Hooke (object): ... pass >>> h = Hooke() + >>> d = Data(shape=(3,2), info={'columns':['distance (m)', 'force (N)']}) + >>> for i in range(3): # initialize d + ... for j in range(2): + ... d[i,j] = i*10 + j >>> c = Curve(None) + >>> c.data = [d] >>> c.set_hooke(h) >>> c._hooke # doctest: +ELLIPSIS @@ -303,6 +308,14 @@ class Curve (object): >>> c2._hooke == h True + >>> c2.data + [Data([[ 0., 1.], + [ 10., 11.], + [ 20., 21.]])] + >>> d.info + {'columns': ['distance (m)', 'force (N)']} + >>> id(c2.data[0]) == id(d) + True """ copier = _copy_dispatch.get(type(self)) if copier: @@ -328,7 +341,12 @@ class Curve (object): >>> class Hooke (object): ... pass >>> h = Hooke() + >>> d = Data(shape=(3,2), info={'columns':['distance (m)', 'force (N)']}) + >>> for i in range(3): # initialize d + ... for j in range(2): + ... d[i,j] = i*10 + j >>> c = Curve(None) + >>> c.data = [d] >>> c.set_hooke(h) >>> c._hooke # doctest: +ELLIPSIS @@ -339,6 +357,14 @@ class Curve (object): >>> c2._hooke == h True + >>> c2.data + [Data([[ 0., 1.], + [ 10., 11.], + [ 20., 21.]])] + >>> d.info + {'columns': ['distance (m)', 'force (N)']} + >>> id(c2.data[0]) == id(d) + False """ reductor = dispatch_table.get(type(self)) if reductor: -- 2.26.2