|
5 | 5 |
|
6 | 6 | import pickle |
7 | 7 | import unittest |
| 8 | +import warnings |
8 | 9 |
|
9 | 10 | import numpy |
10 | 11 | from testutils import _maxNormDiff, loadDiffPyStructure, pickle_with_attr |
11 | 12 |
|
12 | 13 | from diffpy.srreal.pdfcalculator import DebyePDFCalculator, PDFCalculator |
| 14 | +from diffpy.srreal.scatteringfactortable import SFTNeutron |
13 | 15 |
|
14 | 16 |
|
15 | 17 | ############################################################################## |
@@ -141,6 +143,25 @@ def test_partial_pdfs(self): |
141 | 143 |
|
142 | 144 | def test_pickling(self): |
143 | 145 | """Check pickling and unpickling of PDFCalculator.""" |
| 146 | + # New syntax: assign an SFT instance to the property (should not warn) |
| 147 | + dpdfc = self.dpdfc |
| 148 | + with warnings.catch_warnings(record=True) as w: |
| 149 | + warnings.simplefilter("always") |
| 150 | + dpdfc.scatteringfactortable = SFTNeutron() |
| 151 | + self.assertFalse( |
| 152 | + any(isinstance(x.message, DeprecationWarning) for x in w) |
| 153 | + ) |
| 154 | + |
| 155 | + dpdfc.scatteringfactortable.setCustomAs("Na", "Na", 7) |
| 156 | + spkl = pickle.dumps(dpdfc) |
| 157 | + dpdfc1_new = pickle.loads(spkl) |
| 158 | + self.assertEqual( |
| 159 | + dpdfc.scatteringfactortable.type(), |
| 160 | + dpdfc1_new.scatteringfactortable.type(), |
| 161 | + ) |
| 162 | + self.assertEqual(7.0, dpdfc1_new.scatteringfactortable.lookup("Na")) |
| 163 | + |
| 164 | + # Old syntax: call the deprecated method (should warn) |
144 | 165 | dpdfc = self.dpdfc |
145 | 166 | with self.assertWarns(DeprecationWarning): |
146 | 167 | dpdfc.setScatteringFactorTableByType("N") |
|
0 commit comments