Skip to content

Commit

Permalink
Enable writing to standard output
Browse files Browse the repository at this point in the history
  • Loading branch information
JanCBrammer committed Oct 25, 2024
1 parent dd587af commit a3b7b02
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions INCHI-1-TEST/tests/test_executable/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ def pytest_addoption(parser):

@dataclass
class InchiResult:
stdout: str
stderr: str
inchi: str
aux_info: str
Expand Down Expand Up @@ -54,18 +55,24 @@ def _run_inchi_exe(molfile: str, args: str = "") -> InchiResult:
if not Path(exe_path).exists():
raise FileNotFoundError(f"InChI executable not found at {exe_path}.")

write_output_to_stdout = "-STDIO" in args

output_path = tmp_path.joinpath("output.txt")
molfile_path = tmp_path.joinpath("tmp.mol")
molfile_path.write_text(molfile)
paths = (
[molfile_path] if write_output_to_stdout else [molfile_path, output_path]
)

result = subprocess.run(
[exe_path, str(molfile_path), str(output_path)] + args.split(),
[exe_path, *paths, *args.split()],
capture_output=True,
text=True,
)
output = output_path.read_text()
output = result.stdout if write_output_to_stdout else output_path.read_text()

return InchiResult(
stdout=result.stdout,
stderr=result.stderr, # contains log
inchi=parse_inchi_from_executable_output(output),
aux_info=parse_aux_info_from_executable_output(output),
Expand Down

0 comments on commit a3b7b02

Please sign in to comment.