Skip to content

Commit 76f0059

Browse files
committed
Fix: handle invalid dataWindow to prevent Python crash (#2023)
1 parent 310e3bd commit 76f0059

File tree

1 file changed

+11
-10
lines changed

1 file changed

+11
-10
lines changed

src/wrappers/python/tests/test_readme.py

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ def test_write_RGB():
3131

3232
# Generate a 3D NumPy array for RGB channels with random values
3333
height, width = (20, 10)
34-
RGB = np.random.rand(height, width, 3).astype('f')
35-
34+
RGB = np.random.rand(height, width, 3).astype(np.float32)
35+
3636
channels = { "RGB" : RGB }
3737
header = { "compression" : OpenEXR.ZIP_COMPRESSION,
3838
"type" : OpenEXR.scanlineimage }
@@ -122,27 +122,28 @@ def test_multipart_write():
122122

123123
height, width = (20, 10)
124124

125-
Z0 = np.zeros((height, width), dtype='f')
125+
Z0 = np.zeros((height, width), dtype=np.float32)
126126
P0 = OpenEXR.Part(header={"type" : OpenEXR.scanlineimage },
127127
channels={"Z" : Z0 })
128128

129-
Z1 = np.ones((height, width), dtype='f')
129+
Z1 = np.ones((height, width), dtype=np.float32)
130130
P1 = OpenEXR.Part(header={"type" : OpenEXR.scanlineimage },
131131
channels={"Z" : Z1 })
132132

133-
f = OpenEXR.File(parts=[P0, P1])
134-
f.write("readme_2part.exr")
133+
with OpenEXR.File(parts=[P0, P1]) as f:
134+
f.write("readme_2part.exr")
135135

136136
with OpenEXR.File("readme_2part.exr") as o:
137137
assert o.parts[0].name() == "Part0"
138138
assert o.parts[0].type() == OpenEXR.scanlineimage
139-
assert o.parts[0].width() == 10
140-
assert o.parts[0].height() == 20
139+
assert o.parts[0].width() == width
140+
assert o.parts[0].height() == height
141141
assert np.array_equal(o.parts[0].channels["Z"].pixels, Z0)
142+
142143
assert o.parts[1].name() == "Part1"
143144
assert o.parts[1].type() == OpenEXR.scanlineimage
144-
assert o.parts[1].width() == 10
145-
assert o.parts[1].height() == 20
145+
assert o.parts[1].width() == width
146+
assert o.parts[1].height() == height
146147
assert np.array_equal(o.parts[1].channels["Z"].pixels, Z1)
147148

148149
print("ok")

0 commit comments

Comments
 (0)