Skip to content

Commit

Permalink
Add test for example python code in the pypi README.md (AcademySoftwa…
Browse files Browse the repository at this point in the history
…reFoundation#1716)

Signed-off-by: Cary Phillips <[email protected]>
  • Loading branch information
cary-ilm authored Apr 14, 2024
1 parent d669510 commit 67614ff
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 1 deletion.
12 changes: 11 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,16 @@ requires-python = ">=3.7"
[project.optional-dependencies]
test = ["pytest"]

[tool.pytest.ini_options]
minversion = "6.0"
addopts = ["-ra", "--showlocals", "--strict-markers", "--strict-config"]
xfail_strict = true
log_cli_level = "INFO"
filterwarnings = [
"error",
]
testpaths = ["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 @@ -56,7 +66,7 @@ BUILD_SHARED_LIBS = 'OFF'
CMAKE_POSITION_INDEPENDENT_CODE = 'ON'

[tool.cibuildwheel]
test-command = "ctest -R PyOpenEXR"
test-command = "pytest -s {project}/src/wrappers/python/tests"
test-extras = ["test"]
test-skip = ["*universal2:arm64"]
build-verbosity = 1
Expand Down
3 changes: 3 additions & 0 deletions src/wrappers/python/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@ for more information.

# Quick Start

<!-- this code is replicated as a test in -->
<!-- src/wrappers/python/test/test_readme.py -->

The "hello, world" image writer:

import OpenEXR
Expand Down
31 changes: 31 additions & 0 deletions src/wrappers/python/tests/test_readme.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!/usr/bin/env python3

#
# SPDX-License-Identifier: BSD-3-Clause
# Copyright Contributors to the OpenEXR Project.
#

# This is the example code from src/wrappers/python/README.md

def test_readme():

import OpenEXR, Imath
from array import array

width = 10
height = 10
size = width * height

h = OpenEXR.Header(width,height)
h['channels'] = {'R' : Imath.Channel(Imath.PixelType(Imath.PixelType.FLOAT)),
'G' : Imath.Channel(Imath.PixelType(Imath.PixelType.FLOAT)),
'B' : Imath.Channel(Imath.PixelType(Imath.PixelType.FLOAT)),
'A' : Imath.Channel(Imath.PixelType(Imath.PixelType.FLOAT))}
o = OpenEXR.OutputFile("hello.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()
a = array('f', [n for n in range(size*3,size*4)]).tobytes()
channels = {'R' : r, 'G' : g, 'B' : b, 'A' : a}
o.writePixels(channels)
o.close()

0 comments on commit 67614ff

Please sign in to comment.