Skip to content

Commit 4edfa96

Browse files
committed
TST: check PDFContribution.residual after pickling
Expose bug in #56.
1 parent 90d1e5d commit 4edfa96

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

src/diffpy/srfit/tests/testpdf.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
"""Tests for pdf package."""
1717

1818
import unittest
19+
import pickle
1920
import io
2021

2122
import numpy
@@ -248,6 +249,32 @@ def test_savetxt(self):
248249
self.assertEqual(1001, nlines)
249250
return
250251

252+
253+
def test_pickling(self):
254+
"validate PDFContribution.residual() after pickling."
255+
from itertools import chain
256+
from diffpy.structure import loadStructure
257+
pc = self.pc
258+
pc.loadData(datafile("ni-q27r100-neutron.gr"))
259+
ni = loadStructure(datafile("ni.cif"))
260+
ni.Uisoequiv = 0.003
261+
pc.addStructure('ni', ni)
262+
pc.setCalculationRange(0, 10)
263+
pc2 = pickle.loads(pickle.dumps(pc))
264+
res0 = pc.residual()
265+
self.assertTrue(numpy.array_equal(res0, pc2.residual()))
266+
for p in chain(pc.iterPars('Uiso'), pc2.iterPars('Uiso')):
267+
p.value = 0.004
268+
res1 = pc.residual()
269+
self.assertFalse(numpy.allclose(res0, res1))
270+
self.assertTrue(numpy.array_equal(res1, pc2.residual()))
271+
return
272+
273+
# TODO: remove after fixup release of diffpy.structure
274+
import sys
275+
if sys.version_info >= (3, 7):
276+
test_pickling = unittest.expectedFailure(test_pickling)
277+
251278
# End of class TestPDFContribution
252279

253280
# ----------------------------------------------------------------------------

0 commit comments

Comments
 (0)