-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
move stack serialization test to tests/ folder, out of source tree
- Loading branch information
1 parent
f471b36
commit 19cb544
Showing
1 changed file
with
36 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
from refl1d.names import Slab, Stack, SLD | ||
from copy import deepcopy | ||
from bumps.serialize import serialize, deserialize | ||
import pickle | ||
import dill | ||
|
||
|
||
def test_stack_serialization(): | ||
"""test that stack can be serialized and deserialized with all the methods we use, | ||
preserving the functioning of the Calculation object for the total thickness""" | ||
sample = Slab(SLD(rho=10), thickness=10) | Slab(SLD(rho=10), thickness=20) | Slab(SLD(rho=10), thickness=30) | ||
thickness_plus = sample.thickness + 100 # expression | ||
|
||
ser_t, ser_s = deserialize(serialize([thickness_plus, sample])) | ||
assert ser_t.value == 160 | ||
ser_s[0].thickness.value += 40 | ||
assert ser_t.value == 200 | ||
|
||
dc_t, dc_s = deepcopy([thickness_plus, sample]) | ||
assert dc_t.value == 160 | ||
dc_s[0].thickness.value += 40 | ||
assert dc_t.value == 200 | ||
|
||
pickle_t, pickle_s = pickle.loads(pickle.dumps([thickness_plus, sample])) | ||
assert pickle_t.value == 160 | ||
pickle_s[0].thickness.value += 40 | ||
assert pickle_t.value == 200 | ||
|
||
dill_t, dill_s = dill.loads(dill.dumps([thickness_plus, sample])) | ||
assert dill_t.value == 160 | ||
dill_s[0].thickness.value += 40 | ||
assert dill_t.value == 200 | ||
|
||
assert thickness_plus.value == 160 | ||
sample[0].thickness.value += 40 | ||
assert thickness_plus.value == 200 |