Skip to content

Commit

Permalink
simplify python subprocess run usage
Browse files Browse the repository at this point in the history
  • Loading branch information
upsj committed Mar 11, 2024
1 parent 47c32a2 commit edd8735
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
9 changes: 5 additions & 4 deletions benchmark/test/test_framework.py.in
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ def compare_output_impl(
args=launcher_flags + args,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
text=True,
input=bytes(stdin, "utf-8"),
)
print(
Expand All @@ -160,22 +161,22 @@ def compare_output_impl(
]
if generate:
open(expected_stdout, "w").write(
"\n".join(sanitize_json_text(result.stdout.decode()))
"\n".join(sanitize_json_text(result.stdout))
)
open(expected_stderr, "w").write(
"\n".join(
sanitize_text(
result.stderr.decode(),
result.stderr.,
ignore_patterns=ignore_patterns,
replace_patterns=typename_patterns,
)
)
)
print("GENERATED")
return
result_stdout_processed = sanitize_json_text(result.stdout.decode())
result_stdout_processed = sanitize_json_text(result.stdout)
result_stderr_processed = sanitize_text(
result.stderr.decode(),
result.stderr,
ignore_patterns=ignore_patterns,
replace_patterns=typename_patterns,
)
Expand Down
11 changes: 8 additions & 3 deletions examples/compare-output.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,16 @@
env["LD_LIBRARY_PATH"] = ginkgo_path

result = subprocess.run(
args=args, cwd=cwd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, env=env
args=args,
cwd=cwd,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
text=True,
env=env,
)

stdout = result.stdout.decode().splitlines()
stderr = result.stderr.decode().splitlines()
stdout = result.stdout.splitlines()
stderr = result.stderr.splitlines()

if len(stderr) > 0:
print("FAIL: stderr not empty")
Expand Down

0 comments on commit edd8735

Please sign in to comment.