Skip to content

Commit

Permalink
unlink
Browse files Browse the repository at this point in the history
Signed-off-by: Cary Phillips <[email protected]>
  • Loading branch information
cary-ilm committed May 6, 2024
1 parent 6cf0974 commit a9191bc
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 37 deletions.
5 changes: 1 addition & 4 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,6 @@ filterwarnings = [
]
testpaths = ["tests"]

[tool.pytest]
rootdir = "src/wrappers/python/tests"

[tool.scikit-build]
wheel.expand-macos-universal-tags = true
sdist.exclude = [".github", "src/test", "src/examples", "website", "ASWF", "bazel", "share"]
Expand Down Expand Up @@ -70,7 +67,7 @@ CMAKE_POSITION_INDEPENDENT_CODE = 'ON'

[tool.cibuildwheel]
build-verbosity = "1"
test-command = "pytest -s --rootdir={project}/src/wrappers/python/tests {project}/src/wrappers/python/tests"
test-command = "pytest -s {project}/src/wrappers/python/tests"
test-requires = ["numpy"]
test-extras = ["test"]
test-skip = ["*universal2:arm64"]
Expand Down
14 changes: 5 additions & 9 deletions src/wrappers/python/tests/test_exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@

import OpenEXR

test_dir = os.path.dirname(__file__)

class TestExceptions(unittest.TestCase):

def test_File(self):
Expand All @@ -26,12 +28,12 @@ def test_File(self):
f = OpenEXR.File("foo", "bar")

# file not found
filename = "nonexistentfile.exr"
filename = "/nonexistentfile.exr"
with self.assertRaises(RuntimeError):
f = OpenEXR.File(filename)

# file exists but is not an image
filename = sys.argv[0]
filename = f"{test_dir}"
with self.assertRaises(RuntimeError):
f = OpenEXR.File(filename)

Expand All @@ -47,7 +49,7 @@ def test_File(self):
f.channels()

# 1-part file
filename = "test.exr"
filename = f"{test_dir}/test.exr"
f = OpenEXR.File(filename)
self.assertEqual(f.filename, filename)

Expand Down Expand Up @@ -184,11 +186,5 @@ def test_Channel(self):
with self.assertRaises(ValueError):
OpenEXR.Channel("C", np.array([0,0,0,0], dtype='uint8').reshape((height, width)), 2, 2)




test_dir = os.path.dirname(__file__)
os.chdir(test_dir)

if __name__ == '__main__':
unittest.main()
34 changes: 18 additions & 16 deletions src/wrappers/python/tests/test_old.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
import OpenEXR
import Imath

test_dir = os.path.dirname(__file__)

FLOAT = Imath.PixelType(Imath.PixelType.FLOAT)
UINT = Imath.PixelType(Imath.PixelType.UINT)
HALF = Imath.PixelType(Imath.PixelType.HALF)
Expand All @@ -35,7 +37,7 @@ def test_write_read():
'G' : Imath.Channel(FLOAT),
'B' : Imath.Channel(FLOAT),
'A' : Imath.Channel(FLOAT)}
o = OpenEXR.OutputFile("write.exr", h)
o = OpenEXR.OutputFile(f"{test_dir}/write.exr", h)
r = array('f', [n for n in range(size*0,size*1)]).tobytes()
g = array('f', [n for n in range(size*1,size*2)]).tobytes()
b = array('f', [n for n in range(size*2,size*3)]).tobytes()
Expand All @@ -44,7 +46,7 @@ def test_write_read():
o.writePixels(channels)
o.close()

i = OpenEXR.InputFile("write.exr")
i = OpenEXR.InputFile(f"{test_dir}/write.exr")
h = i.header()
assert r == i.channel('R')
assert g == i.channel('G')
Expand All @@ -70,11 +72,11 @@ def test_conversion():
for frm_code,to_code in [ ('f','I'), ('I','f') ]:
hdr = OpenEXR.Header(len(original), 1)
hdr['channels'] = {'L': Imath.Channel(codemap[frm_code])}
x = OpenEXR.OutputFile("out.exr", hdr)
x = OpenEXR.OutputFile(f"{test_dir}/out.exr", hdr)
x.writePixels({'L': array(frm_code, original).tobytes()})
x.close()

xin = OpenEXR.InputFile("out.exr")
xin = OpenEXR.InputFile(f"{test_dir}/out.exr")
assert array(to_code, xin.channel('L', codemap[to_code])).tolist() == original

testList.append(("test_conversion", test_conversion))
Expand Down Expand Up @@ -110,7 +112,7 @@ def test_invalid_output():
testList.append(("test_invalid_output", test_invalid_output))

def test_one():
oexr = OpenEXR.InputFile("write.exr")
oexr = OpenEXR.InputFile(f"{test_dir}/write.exr")

header = oexr.header()

Expand All @@ -131,7 +133,7 @@ def test_one():

data = b" " * (4 * 100 * 100)
h = OpenEXR.Header(100,100)
x = OpenEXR.OutputFile("out.exr", h)
x = OpenEXR.OutputFile(f"{test_dir}/out.exr", h)
x.writePixels({'R': data, 'G': data, 'B': data})
x.close()

Expand All @@ -143,7 +145,7 @@ def test_one():

def test_channel_channels():

aexr = OpenEXR.InputFile("write.exr")
aexr = OpenEXR.InputFile(f"{test_dir}/write.exr")
acl = sorted(aexr.header()['channels'].keys())
a = [aexr.channel(c) for c in acl]
b = aexr.channels(acl)
Expand All @@ -159,11 +161,11 @@ def test_types():
hdr = OpenEXR.Header(len(original), 1)
hdr['channels'] = {'L': Imath.Channel(t)}

x = OpenEXR.OutputFile("out.exr", hdr)
x = OpenEXR.OutputFile(f"{test_dir}/out.exr", hdr)
x.writePixels({'L': data})
x.close()

xin = OpenEXR.InputFile("out.exr")
xin = OpenEXR.InputFile(f"{test_dir}/out.exr")
# Implicit type
assert array(code, xin.channel('L')).tolist() == original
# Explicit typen
Expand All @@ -174,7 +176,7 @@ def test_types():
testList.append(("test_types", test_types))

def test_invalid_pixeltype():
oexr = OpenEXR.InputFile("write.exr")
oexr = OpenEXR.InputFile(f"{test_dir}/write.exr")
FLOAT = Imath.PixelType.FLOAT
try:
f.channel('R',FLOAT)
Expand All @@ -193,11 +195,11 @@ def test_write_mchannels():
hdr = OpenEXR.Header(100, 100)
for chans in [ set("a"), set(['foo', 'bar']), set("abcdefghijklmnopqstuvwxyz") ]:
hdr['channels'] = dict([(nm, Imath.Channel(Imath.PixelType(Imath.PixelType.FLOAT))) for nm in chans])
x = OpenEXR.OutputFile("out0.exr", hdr)
x = OpenEXR.OutputFile(f"{test_dir}/out0.exr", hdr)
data = array('f', [0] * (100 * 100)).tobytes()
x.writePixels(dict([(nm, data) for nm in chans]))
x.close()
assert set(OpenEXR.InputFile('out0.exr').header()['channels']) == chans
assert set(OpenEXR.InputFile(f"{test_dir}/out0.exr").header()['channels']) == chans

testList.append(("test_write_mchannels", test_write_mchannels))

Expand All @@ -215,19 +217,19 @@ def test_write_chunk():
data = array('f', [ random.random() for x in range(w * h) ]).tobytes()

hdr = OpenEXR.Header(w,h)
x = OpenEXR.OutputFile("out0.exr", hdr)
x = OpenEXR.OutputFile(f"{test_dir}/out0.exr", hdr)
x.writePixels({'R': data, 'G': data, 'B': data})
x.close()

hdr = OpenEXR.Header(w,h)
x = OpenEXR.OutputFile("out1.exr", hdr)
x = OpenEXR.OutputFile(f"{test_dir}/out1.exr", hdr)
for y in range(0, h, step):
subdata = data[y * w * 4:(y+step) * w * 4]
x.writePixels({'R': subdata, 'G': subdata, 'B': subdata}, step)
x.close()

oexr0 = load_red("out0.exr")
oexr1 = load_red("out1.exr")
oexr0 = load_red(f"{test_dir}/out0.exr")
oexr1 = load_red(f"{test_dir}/out1.exr")
assert oexr0 == oexr1

testList.append(("test_write_chunk", test_write_chunk))
Expand Down
30 changes: 22 additions & 8 deletions src/wrappers/python/tests/test_unittest.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@

import OpenEXR

test_dir = os.path.dirname(__file__)

def equalWithRelError (x1, x2, e):
return ((x1 - x2) if (x1 > x2) else (x2 - x1)) <= e * (x1 if (x1 > 0) else -x1)

Expand Down Expand Up @@ -130,7 +132,7 @@ def test_read_write(self):
# file to validate it's the same.
#

infilename = "test.exr"
infilename = f"{test_dir}/test.exr"
infile = OpenEXR.File(infilename)

infile.write(outfilename)
Expand All @@ -139,6 +141,8 @@ def test_read_write(self):

assert outfile == infile

os.unlink(outfilename)

def test_keycode(self):

filmMfcCode = 1
Expand Down Expand Up @@ -200,6 +204,8 @@ def test_write_uint(self):

assert infile == outfile

os.unlink(outfilename)

def test_write_half(self):

# Construct a file from scratch and write it.
Expand Down Expand Up @@ -231,14 +237,16 @@ def test_write_half(self):

assert infile == outfile

os.unlink(outfilename)

def test_modify_in_place(self):

#
# Test modifying header attributes in place
#

filename = "test.exr"
f = OpenEXR.File(filename)
infilename = f"{test_dir}/test.exr"
f = OpenEXR.File(infilename)

# set the value of an existing attribute
par = 2.3
Expand Down Expand Up @@ -280,6 +288,8 @@ def test_modify_in_place(self):
assert equalWithRelError(m.parts[0].channels["R"].pixels[0][1], 42.0, eps)
assert equalWithRelError(m.parts[0].channels["G"].pixels[2][3], 666.0, eps)

os.unlink(outfilename)

def test_preview_image(self):

dt = np.dtype({
Expand Down Expand Up @@ -314,6 +324,8 @@ def test_preview_image(self):

assert infile == outfile

os.unlink(outfilename)

def test_write_float(self):

# Construct a file from scratch and write it.
Expand Down Expand Up @@ -370,6 +382,8 @@ def test_write_float(self):

assert infile == outfile

os.unlink(outfilename)

def test_write_2part(self):

#
Expand Down Expand Up @@ -440,15 +454,15 @@ def test_write_2part(self):
i = OpenEXR.File(outfilename)
assert i == outfile2

test_dir = os.path.dirname(__file__)
os.chdir(test_dir)

os.unlink(outfilename)

fd, outfilename = tempfile.mkstemp(".exr")
os.close(fd)

def cleanup():
print(f"deleting {outfilename}")
os.unlink(outfilename)
if os.path.isfile(outfilename):
print(f"deleting {outfilename}")
os.unlink(outfilename)
atexit.register(cleanup)

if __name__ == '__main__':
Expand Down

0 comments on commit a9191bc

Please sign in to comment.