Skip to content

Commit ea45f26

Browse files
committed
#137 Update test for datamodel module
1 parent dccb919 commit ea45f26

File tree

1 file changed

+79
-52
lines changed

1 file changed

+79
-52
lines changed

tests/test_datamodel.py

Lines changed: 79 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -53,73 +53,100 @@ class ColorImage:
5353

5454
# test functions
5555
def test_xaxis_attr() -> None:
56-
item = next(iter(xaxis_model.attr.values()))
57-
assert item.name == "units"
58-
assert item.value == "pixel"
59-
assert item.type == "builtins.str"
56+
units = xaxis_model.attrs[0]
57+
assert units.name == "units"
58+
assert units.tag == "attr"
59+
assert units.type is str
60+
assert units.value == "pixel"
61+
assert units.cast == False
6062

6163

6264
def test_xaxis_data() -> None:
63-
item = next(iter(xaxis_model.data.values()))
64-
assert item.name == "data"
65-
assert item.type == {"dims": ("x",), "dtype": "int"}
66-
assert item.factory is None
65+
data = xaxis_model.data_vars[0]
66+
assert data.name == "data"
67+
assert data.tag == "data"
68+
assert data.dims == ("x",)
69+
assert data.dtype == "int"
70+
assert data.base is None
71+
assert data.cast == True
6772

6873

6974
def test_yaxis_attr() -> None:
70-
item = next(iter(yaxis_model.attr.values()))
71-
assert item.name == "units"
72-
assert item.value == "pixel"
73-
assert item.type == "builtins.str"
75+
units = yaxis_model.attrs[0]
76+
assert units.name == "units"
77+
assert units.tag == "attr"
78+
assert units.type is str
79+
assert units.value == "pixel"
80+
assert units.cast == False
7481

7582

7683
def test_yaxis_data() -> None:
77-
item = next(iter(yaxis_model.data.values()))
78-
assert item.name == "data"
79-
assert item.type == {"dims": ("y",), "dtype": "int"}
80-
assert item.factory is None
84+
data = yaxis_model.data_vars[0]
85+
assert data.name == "data"
86+
assert data.tag == "data"
87+
assert data.dims == ("y",)
88+
assert data.dtype == "int"
89+
assert data.base is None
90+
assert data.cast == True
8191

8292

8393
def test_image_coord() -> None:
84-
items = iter(image_model.coord.values())
85-
86-
item = next(items)
87-
assert item.name == "mask"
88-
assert item.type == {"dims": ("x", "y"), "dtype": "bool"}
89-
assert item.factory is None
90-
91-
item = next(items)
92-
assert item.name == "x"
93-
assert item.type == {"dims": ("x",), "dtype": "int"}
94-
assert item.factory is XAxis
95-
96-
item = next(items)
97-
assert item.name == "y"
98-
assert item.type == {"dims": ("y",), "dtype": "int"}
99-
assert item.factory is YAxis
94+
mask = image_model.coords[0]
95+
assert mask.name == "mask"
96+
assert mask.tag == "coord"
97+
assert mask.dims == ("x", "y")
98+
assert mask.dtype == "bool"
99+
assert mask.base is None
100+
assert mask.cast == True
101+
102+
x = image_model.coords[1]
103+
assert x.name == "x"
104+
assert x.tag == "coord"
105+
assert x.dims == ("x",)
106+
assert x.dtype == "int"
107+
assert x.base is XAxis
108+
assert x.cast == True
109+
110+
y = image_model.coords[2]
111+
assert y.name == "y"
112+
assert y.tag == "coord"
113+
assert y.dims == ("y",)
114+
assert y.dtype == "int"
115+
assert y.base is YAxis
116+
assert y.cast == True
100117

101118

102119
def test_image_data() -> None:
103-
item = next(iter(image_model.data.values()))
104-
assert item.name == "data"
105-
assert item.type == {"dims": ("x", "y"), "dtype": "float"}
106-
assert item.factory is None
120+
data = image_model.data_vars[0]
121+
assert data.name == "data"
122+
assert data.tag == "data"
123+
assert data.dims == ("x", "y")
124+
assert data.dtype == "float"
125+
assert data.base is None
126+
assert data.cast == True
107127

108128

109129
def test_color_data() -> None:
110-
items = iter(color_model.data.values())
111-
112-
item = next(items)
113-
assert item.name == "red"
114-
assert item.type == {"dims": ("x", "y"), "dtype": "float"}
115-
assert item.factory is Image
116-
117-
item = next(items)
118-
assert item.name == "green"
119-
assert item.type == {"dims": ("x", "y"), "dtype": "float"}
120-
assert item.factory is Image
121-
122-
item = next(items)
123-
assert item.name == "blue"
124-
assert item.type == {"dims": ("x", "y"), "dtype": "float"}
125-
assert item.factory is Image
130+
red = color_model.data_vars[0]
131+
assert red.name == "red"
132+
assert red.tag == "data"
133+
assert red.dims == ("x", "y")
134+
assert red.dtype == "float"
135+
assert red.base is Image
136+
assert red.cast == True
137+
138+
green = color_model.data_vars[1]
139+
assert green.name == "green"
140+
assert green.tag == "data"
141+
assert green.dims == ("x", "y")
142+
assert green.dtype == "float"
143+
assert green.base is Image
144+
assert green.cast == True
145+
146+
blue = color_model.data_vars[2]
147+
assert blue.name == "blue"
148+
assert blue.tag == "data"
149+
assert blue.dims == ("x", "y")
150+
assert blue.dtype == "float"
151+
assert blue.base is Image
152+
assert blue.cast == True

0 commit comments

Comments
 (0)