Skip to content

Commit 80fa501

Browse files
committed
chore: write tests for old syntax and specify future release deprecation
1 parent b766404 commit 80fa501

File tree

2 files changed

+24
-2
lines changed

2 files changed

+24
-2
lines changed

src/extensions/wrap_ScatteringFactorTable.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ Set internal ScatteringFactorTable according to specified string type.\n\
160160
tp -- string identifier of a registered ScatteringFactorTable type.\n\
161161
Use ScatteringFactorTable.getRegisteredTypes for the allowed values.\n\
162162
\n\
163-
Deprecated: This method is deprecated and will be removed in a future release.\n\
163+
Deprecated: This method is deprecated and will be removed in the 2.0.0 release.\n\
164164
Use direct assignment to the `scatteringfactortable` property instead, for example:\n\
165165
obj.scatteringfactortable = SFTNeutron()\n\
166166
No return value.\n\
@@ -414,7 +414,8 @@ void wrap_ScatteringFactorTable()
414414
bp::object DeprecationWarning = builtins.attr("DeprecationWarning");
415415
warnings.attr("warn")(
416416
std::string("setScatteringFactorTableByType is deprecated; "
417-
"assign the 'scatteringfactortable' property directly (for example, use SFTNeutron()/SFTXray())."),
417+
"assign the 'scatteringfactortable' property directly, for example:\n"
418+
"obj.scatteringfactortable = SFTNeutron()"),
418419
DeprecationWarning,
419420
2);
420421
}

tests/test_debyepdfcalculator.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,13 @@
55

66
import pickle
77
import unittest
8+
import warnings
89

910
import numpy
1011
from testutils import _maxNormDiff, loadDiffPyStructure, pickle_with_attr
1112

1213
from diffpy.srreal.pdfcalculator import DebyePDFCalculator, PDFCalculator
14+
from diffpy.srreal.scatteringfactortable import SFTNeutron
1315

1416

1517
##############################################################################
@@ -141,6 +143,25 @@ def test_partial_pdfs(self):
141143

142144
def test_pickling(self):
143145
"""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)
144165
dpdfc = self.dpdfc
145166
with self.assertWarns(DeprecationWarning):
146167
dpdfc.setScatteringFactorTableByType("N")

0 commit comments

Comments
 (0)