Skip to content

Commit 7f46add

Browse files
committed
Fix broken auxdata interoperability test
1 parent b944879 commit 7f46add

File tree

2 files changed

+45
-24
lines changed

2 files changed

+45
-24
lines changed

.ci/test-interop.sh

Lines changed: 32 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,44 @@
1+
#!/bin/bash
12
set -e
23
cd build
34

5+
failures=0
6+
7+
check() {
8+
local creator=$1
9+
local auxdata=$2
10+
local consumer=$3
11+
shift 3
12+
13+
if "$@" ; then
14+
echo $creator $auxdata AuxData work in $consumer
15+
else
16+
failures=$(( failures + 1))
17+
fi
18+
}
19+
420
### floating-point compatiblity test
521

622
bin/test_floats -w floats_cpp.gtirb
723
python3 src/test/testInterop/test_floats.py -w floats_py.gtirb
824

9-
bin/test_floats -r floats_py.gtirb && \
10-
echo "python float AuxData work in c++"
11-
python3 src/test/testInterop/test_floats.py -r floats_cpp.gtirb && \
12-
echo "c++ float AuxData work in python"
13-
rm floats_*.gtirb
25+
check python float c++ \
26+
bin/test_floats -r floats_py.gtirb
27+
check c++ float python \
28+
python3 src/test/testInterop/test_floats.py -r floats_cpp.gtirb
29+
30+
rm floats_{cpp,py}.gtirb
1431

15-
# variant compatibility test
32+
### variant compatibility test
1633

1734
bin/test_variants -w variants_cpp.gtirb
1835
python3 src/test/testInterop/test_variants.py -w variants_py.gtirb
19-
python3 src/test/testInterop/test_variants.py -r variants_cpp.gtirb && \
20-
echo "c++ variant AuxData work in python"
21-
bin/test_variants -r variants_py.gtirb && \
22-
echo "python variant auxdata work in c++"
36+
37+
check c++ variant python \
38+
python3 src/test/testInterop/test_variants.py -r variants_cpp.gtirb
39+
check python variant c++ \
40+
bin/test_variants -r variants_py.gtirb
41+
42+
rm variants_{cpp,py}.gtirb
43+
44+
test $failures = 0

src/test/testInterop/test_variants.py

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1+
import dataclasses
12
import os
23
import tempfile
3-
from typing import Any
4+
from typing import Any, ClassVar
45

56
import gtirb
67

@@ -44,30 +45,25 @@ def test_mapvariant():
4445
compare_variant_maps(ad2, vmap)
4546

4647

48+
@dataclasses.dataclass
4749
class I1:
48-
GTIRB_TYPE = "int64_t"
50+
GTIRB_TYPE: ClassVar[str] = "int64_t"
4951
data: int
5052

51-
def __init__(self, data) -> None:
52-
self.data = data
53-
5453

54+
@dataclasses.dataclass
5555
class I2:
56-
GTIRB_TYPE = "int64_t"
56+
GTIRB_TYPE: ClassVar[str] = "int64_t"
5757
data: int
5858

59-
def __init__(self, data) -> None:
60-
self.data = data
61-
6259

60+
@dataclasses.dataclass
6361
class S1:
64-
GTIRB_TYPE = "string"
62+
GTIRB_TYPE: ClassVar[str] = "string"
6563
data: str
6664

67-
def __init__(self, data) -> None:
68-
self.data = data
69-
7065

66+
@dataclasses.dataclass
7167
class MyMap:
7268
TYPELIST = [
7369
I1,
@@ -84,6 +80,9 @@ def __eq__(self, __o: object) -> bool:
8480
return False
8581
return self._map == __o._map
8682

83+
def __repr__(self) -> str:
84+
return f"MyMap({self._map!r})"
85+
8786
def toAuxData(self):
8887
return {
8988
k: gtirb.Variant(self.TYPELIST.index(type(v)), v.data)
@@ -137,7 +136,7 @@ def check_ir(filename):
137136
compare_variant_maps(ir.aux_data["simpleVariantMap"].data, simple)
138137
my_map = MyMap.fromAuxData(ir.aux_data["complexVariantMap"])
139138
_, my_other_map = make_complex_variant_map()
140-
assert my_other_map == my_map
139+
assert my_other_map == my_map, (my_other_map, my_map)
141140

142141

143142
if __name__ == "__main__":

0 commit comments

Comments
 (0)