Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adding better error reporting for bin tests #1578

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 13 additions & 13 deletions src/test/bin/test_exr2aces.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,31 +16,31 @@
# no args = usage message, error
result = run ([exr2aces], stdout=PIPE, stderr=PIPE, universal_newlines=True)
print(" ".join(result.args))
assert(result.returncode != 0)
assert(result.stderr.startswith ("Usage: "))
assert(result.returncode != 0), "\n"+result.stderr
assert(result.stderr.startswith ("Usage: ")), "\n"+result.stderr
Comment on lines +19 to +20
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not a very fluent Python speaker. What does this mean

assert(condition), string

?? Does the string print if the assertion fails? What about if the assertion succeeds? Is this an idiomatic usage that Python experts would use?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah basically it's just passing that string to the Exception. Same as if you did
Exception("This is my error message")
https://docs.python.org/3.9/reference/simple_stmts.html#the-assert-statement
I'm using "the extended form" here

So the string only prints if the assertion fails.

I think an alternative would be

try:
    assert(result.returncode != 0)
except AssertionError:
    print(result.stderr)
    raise

But that just felt like it took up too many lines for what it did.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, it's fine, it just wasn't a convention I was familiar with


# -h = usage message
result = run ([exr2aces, "-h"], stdout=PIPE, stderr=PIPE, universal_newlines=True)
print(" ".join(result.args))
assert(result.returncode == 0)
assert(result.stdout.startswith ("Usage: "))
assert(result.returncode == 0), "\n"+result.stderr
assert(result.stdout.startswith ("Usage: ")), "\n"+result.stdout

result = run ([exr2aces, "--help"], stdout=PIPE, stderr=PIPE, universal_newlines=True)
print(" ".join(result.args))
assert(result.returncode == 0)
assert(result.stdout.startswith ("Usage: "))
assert(result.returncode == 0), "\n"+result.stderr
assert(result.stdout.startswith ("Usage: ")), "\n"+result.stdout

# --version
result = run ([exr2aces, "--version"], stdout=PIPE, stderr=PIPE, universal_newlines=True)
print(" ".join(result.args))
assert(result.returncode == 0)
assert(result.stdout.startswith ("exr2aces"))
assert(version in result.stdout)
assert(result.returncode == 0), "\n"+result.stderr
assert(result.stdout.startswith ("exr2aces")), "\n"+result.stdout
assert(version in result.stdout), "\n"+result.stdout

# invalid arguments
result = run ([exr2aces, "foo.exr", "bar.exr"], stdout=PIPE, stderr=PIPE, universal_newlines=True)
print(" ".join(result.args))
assert(result.returncode != 0)
assert(result.returncode != 0), "\n"+result.stderr

def find_line(keyword, lines):
for line in lines:
Expand All @@ -58,14 +58,14 @@ def cleanup():
image = f"{image_dir}/TestImages/GrayRampsHorizontal.exr"
result = run ([exr2aces, "-v", image, outimage], stdout=PIPE, stderr=PIPE, universal_newlines=True)
print(" ".join(result.args))
assert(result.returncode == 0)
assert(result.returncode == 0), "\n"+result.stderr

result = run ([exrinfo, "-v", outimage], stdout=PIPE, stderr=PIPE, universal_newlines=True)
print(" ".join(result.args))
assert(result.returncode == 0)
assert(result.returncode == 0), "\n"+result.stderr

# confirm the output has the proper chromaticities
assert("chromaticities: chromaticities r[0.7347, 0.2653] g[0, 1] b[0.0001, -0.077] w[0.32168, 0.33767]" in result.stdout)
assert("chromaticities: chromaticities r[0.7347, 0.2653] g[0, 1] b[0.0001, -0.077] w[0.32168, 0.33767]" in result.stdout), "\n"+result.stdout

print("success")

Expand Down
17 changes: 6 additions & 11 deletions src/test/bin/test_exrcheck.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from subprocess import PIPE, run

print(f"testing exrcheck: {' '.join(sys.argv)}")

exrcheck = sys.argv[1]
image_dir = sys.argv[2]

Expand All @@ -17,28 +17,23 @@

result = run ([exrcheck, exr_path], stdout=PIPE, stderr=PIPE, universal_newlines=True)
print(" ".join(result.args))
print(result.stderr)
assert(result.returncode == 0)
assert(result.returncode == 0), "\n"+result.stderr

result = run ([exrcheck, "-m", exr_path], stdout=PIPE, stderr=PIPE, universal_newlines=True)
print(" ".join(result.args))
print(result.stderr)
assert(result.returncode == 0)
assert(result.returncode == 0), "\n"+result.stderr

result = run ([exrcheck, "-t", exr_path], stdout=PIPE, stderr=PIPE, universal_newlines=True)
print(" ".join(result.args))
print(result.stderr)
assert(result.returncode == 0)
assert(result.returncode == 0), "\n"+result.stderr

result = run ([exrcheck, "-s", exr_path], stdout=PIPE, stderr=PIPE, universal_newlines=True)
print(" ".join(result.args))
print(result.stderr)
assert(result.returncode == 0)
assert(result.returncode == 0), "\n"+result.stderr

result = run ([exrcheck, "-c", exr_path], stdout=PIPE, stderr=PIPE, universal_newlines=True)
print(" ".join(result.args))
print(result.stderr)
assert(result.returncode == 0)
assert(result.returncode == 0), "\n"+result.stderr


print("success.")
Expand Down
Loading