Skip to content

Commit 34b7c5b

Browse files
committed
Work around weird py2.7 rwops issue with SVG
1 parent ec6cdd5 commit 34b7c5b

File tree

1 file changed

+15
-13
lines changed

1 file changed

+15
-13
lines changed

sdl2/test/sdlimage_test.py

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,10 @@ def _get_image_path(fmt):
7979
testdir = os.path.dirname(os.path.abspath(__file__))
8080
return os.path.join(testdir, "resources", fname)
8181

82+
def _get_image_rw(fmt):
83+
fpath = _get_image_path(fmt).encode('utf-8')
84+
return sdl2.SDL_RWFromFile(fpath, b"r")
85+
8286
def _verify_img_load(surf):
8387
if not surf:
8488
assert sdlimage.IMG_GetError() == b""
@@ -132,9 +136,9 @@ def test_IMG_Load_RW(with_sdl_image):
132136
for fmt in formats:
133137
if fmt in skip:
134138
continue
135-
fpath = _get_image_path(fmt)
136-
with open(fpath, "rb") as fp:
137-
sf = sdlimage.IMG_Load_RW(rwops.rw_from_object(fp), False)
139+
rw = _get_image_rw(fmt)
140+
sf = sdlimage.IMG_Load_RW(rw, False)
141+
sdl2.SDL_RWclose(rw)
138142
_verify_img_load(sf)
139143
surface.SDL_FreeSurface(sf)
140144

@@ -189,13 +193,11 @@ def test_IMG_LoadTyped_RW(with_sdl_image):
189193
for fmt in formats:
190194
if fmt in skip:
191195
continue
192-
fpath = _get_image_path(fmt)
193-
with open(fpath, "rb") as fp:
194-
sf = sdlimage.IMG_LoadTyped_RW(
195-
rwops.rw_from_object(fp), False, fmt.upper().encode("utf-8")
196-
)
197-
_verify_img_load(sf)
198-
surface.SDL_FreeSurface(sf)
196+
rw = _get_image_rw(fmt)
197+
sf = sdlimage.IMG_LoadTyped_RW(rw, False, fmt.upper().encode("utf-8"))
198+
sdl2.SDL_RWclose(rw)
199+
_verify_img_load(sf)
200+
surface.SDL_FreeSurface(sf)
199201

200202
def test_IMG_LoadBMP_RW(with_sdl_image):
201203
fp = open(_get_image_path("bmp"), "rb")
@@ -263,9 +265,9 @@ def test_IMG_LoadPNM_RW(with_sdl_image):
263265
@pytest.mark.skipif(sdlimage.dll.version < 2002, reason="Added in 2.0.2")
264266
@pytest.mark.xfail(isconda and iswindows, reason="Broken w/ win64 Conda")
265267
def test_IMG_LoadSVG_RW(with_sdl_image):
266-
fp = open(_get_image_path("svg"), "rb")
267-
sf = sdlimage.IMG_LoadSVG_RW(rwops.rw_from_object(fp))
268-
fp.close()
268+
rw = _get_image_rw("svg")
269+
sf = sdlimage.IMG_LoadSVG_RW(rw)
270+
sdl2.SDL_RWclose(rw)
269271
_verify_img_load(sf)
270272
surface.SDL_FreeSurface(sf)
271273

0 commit comments

Comments
 (0)