Skip to content

Commit a2fad92

Browse files
committed
handle ironpython
1 parent 868b113 commit a2fad92

File tree

1 file changed

+31
-10
lines changed

1 file changed

+31
-10
lines changed

tests/compas/datastructures/test_datastructure.py

Lines changed: 31 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import pytest
2+
import compas
23
from compas.datastructures import Datastructure
34
from compas.data import json_dumps, json_loads
45

@@ -85,17 +86,26 @@ def __from_data__(cls, data):
8586

8687

8788
def test_mro_fallback(level2):
88-
print(level2.__jsondump__())
89-
assert level2.__jsondump__()["dtype"] == "test_datastructure/Level2"
90-
# Level2 should serialize Level1 into the mro
91-
assert level2.__jsondump__()["mro"] == ["test_datastructure/Level1"]
89+
if not compas.IPY:
90+
assert level2.__jsondump__()["dtype"] == "test_datastructure/Level2"
91+
# Level2 should serialize Level1 into the mro
92+
assert level2.__jsondump__()["mro"] == ["test_datastructure/Level1"]
93+
else:
94+
# IronPython will append absolute path to the dtype like: "tests\\compas\\datastructures\\test_datastructure.py_72/Level2"
95+
# We avoide this complications for now by checking the end of the string.
96+
assert level2.__jsondump__()["dtype"].endswith("Level2")
97+
assert level2.__jsondump__()["mro"][0].endswith("Level1")
9298

9399
dumped = json_dumps(level2)
94100
loaded = json_loads(dumped)
95101

96102
# The loaded object should be deserialized as the closes available class: Level1
97103
assert loaded.__class__ == Level1
98-
assert loaded.__jsondump__()["dtype"] == "test_datastructure/Level1"
104+
105+
if not compas.IPY:
106+
assert loaded.__jsondump__()["dtype"] == "test_datastructure/Level1"
107+
else:
108+
assert loaded.__jsondump__()["dtype"].endswith("Level1")
99109
assert loaded.__jsondump__()["mro"] == []
100110

101111
# level1 attributes should still be available
@@ -105,17 +115,28 @@ def test_mro_fallback(level2):
105115

106116

107117
def test_mro_fallback_multi_level(level3):
108-
print(level3.__jsondump__())
109-
assert level3.__jsondump__()["dtype"] == "test_datastructure/Level3"
110-
# Level3 should serialize Level2 and Level1 into the mro
111-
assert level3.__jsondump__()["mro"] == ["test_datastructure/Level2", "test_datastructure/Level1"]
118+
if not compas.IPY:
119+
assert level3.__jsondump__()["dtype"] == "test_datastructure/Level3"
120+
# Level3 should serialize Level2 and Level1 into the mro
121+
assert level3.__jsondump__()["mro"] == ["test_datastructure/Level2", "test_datastructure/Level1"]
122+
else:
123+
# IronPython will append absolute path to the dtype like: "tests\\compas\\datastructures\\test_datastructure.py_72/Level2"
124+
# We avoide this complications for now by checking the end of the string.
125+
assert level3.__jsondump__()["dtype"].endswith("Level3")
126+
assert level3.__jsondump__()["mro"][0].endswith("Level2")
127+
assert level3.__jsondump__()["mro"][1].endswith("Level1")
112128

113129
dumped = json_dumps(level3)
114130
loaded = json_loads(dumped)
115131

116132
# The loaded object should be deserialized as the closes available class: Level1
117133
assert loaded.__class__ == Level1
118-
assert loaded.__jsondump__()["dtype"] == "test_datastructure/Level1"
134+
135+
if not compas.IPY:
136+
assert loaded.__jsondump__()["dtype"] == "test_datastructure/Level1"
137+
assert loaded.__jsondump__()["mro"] == []
138+
else:
139+
assert loaded.__jsondump__()["dtype"].endswith("Level1")
119140
assert loaded.__jsondump__()["mro"] == []
120141

121142
# level1 attributes should still be available

0 commit comments

Comments
 (0)