|
| 1 | +import pickle |
| 2 | + |
| 3 | +import pytest |
| 4 | + |
| 5 | +import sire as sr |
| 6 | + |
| 7 | + |
| 8 | +def test_dynamic_attribute_breaks_pickling(): |
| 9 | + """ |
| 10 | + General, still-open Sire issue: sire_pickle_suite<T> (wrapper/Qt/ |
| 11 | + qdatastream.hpp) never overrides pickle_suite::getstate_manages_dict(), |
| 12 | + so any object using it that also has a dynamic Python attribute set on |
| 13 | + it (populating __dict__) fails to pickle with 'Incomplete pickle support |
| 14 | + (__getstate_manages_dict__ not set)', even though the object's own |
| 15 | + QDataStream-based serialisation (sire.stream.save/load) is unaffected. |
| 16 | + """ |
| 17 | + from sire.mm import BoreschRestraint, BoreschRestraints |
| 18 | + |
| 19 | + b = BoreschRestraint( |
| 20 | + receptor=[1574, 1554, 1576], |
| 21 | + ligand=[4, 3, 5], |
| 22 | + r0=sr.u("7.687 A"), |
| 23 | + theta0=[sr.u("1.3031 rad"), sr.u("1.4777 rad")], |
| 24 | + phi0=[sr.u("2.5569 rad"), sr.u("2.9359 rad"), sr.u("1.4147 rad")], |
| 25 | + kr=sr.u("6.2012 kcal mol-1 A-2"), |
| 26 | + ktheta=[sr.u("28.7685 kcal mol-1 rad-2"), sr.u("24.8204 kcal mol-1 rad-2")], |
| 27 | + kphi=[ |
| 28 | + sr.u("59.8626 kcal mol-1 rad-2"), |
| 29 | + sr.u("0.7923 kcal mol-1 rad-2"), |
| 30 | + sr.u("55.1775 kcal mol-1 rad-2"), |
| 31 | + ], |
| 32 | + ) |
| 33 | + restraints = BoreschRestraints(b) |
| 34 | + |
| 35 | + # Pickles fine before any dynamic attribute is set. |
| 36 | + pickle.dumps(restraints) |
| 37 | + |
| 38 | + restraints._some_dynamic_attribute = True |
| 39 | + |
| 40 | + with pytest.raises(RuntimeError, match="Incomplete pickle support"): |
| 41 | + pickle.dumps(restraints) |
0 commit comments