Skip to content

Commit

Permalink
Capture output file content
Browse files Browse the repository at this point in the history
  • Loading branch information
JanCBrammer committed Oct 15, 2024
1 parent e922950 commit 632f444
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 9 deletions.
23 changes: 17 additions & 6 deletions INCHI-1-TEST/tests/test_executable/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import subprocess
from typing import Callable
from pathlib import Path
from dataclasses import dataclass


def pytest_addoption(parser):
Expand All @@ -13,20 +14,30 @@ def pytest_addoption(parser):
)


@dataclass
class InchiResult:
stdout: str
output: str # InChI and AuxInfo


@pytest.fixture
def run_inchi_exe(request) -> Callable:
def _run_inchi_exe(
molfile_path: str, args: str = ""
) -> subprocess.CompletedProcess:
def run_inchi_exe(request, tmp_path: Path) -> Callable:
def _run_inchi_exe(molfile_path: str, args: str = "") -> InchiResult:

exe_path: str = request.config.getoption("--exe-path")
if not Path(exe_path).exists():
raise FileNotFoundError(f"InChI executable not found at {exe_path}.")

return subprocess.run(
[exe_path, molfile_path] + args.split(),
result = subprocess.run(
[exe_path, molfile_path, str(tmp_path.joinpath("output.txt"))]
+ args.split(),
capture_output=True,
text=True,
)

return InchiResult(
stdout=result.stderr,
output=Path(tmp_path.joinpath("output.txt")).read_text(),
)

return _run_inchi_exe
2 changes: 1 addition & 1 deletion INCHI-1-TEST/tests/test_executable/test_github_40.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,4 +110,4 @@ def molfile():
def test_spiro_compound_chiral(molfile, run_inchi_exe):
result = run_inchi_exe(molfile)

assert "Warning (Not chiral) structure #1." not in result.stderr
assert "Warning (Not chiral) structure #1." not in result.stdout
4 changes: 2 additions & 2 deletions INCHI-1-TEST/tests/test_executable/test_github_52.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def test_empty_bondblock(molfile_empty_bondblock, run_inchi_exe):

assert (
"Error 71 (no InChI; Error: No V3000 CTAB end marker) inp structure #1."
not in result.stderr
not in result.stdout
)


Expand All @@ -53,5 +53,5 @@ def test_no_bondblock(molfile_no_bondblock, run_inchi_exe):

assert (
"Error 71 (no InChI; Error: No V3000 CTAB end marker) inp structure #1."
not in result.stderr
not in result.stdout
)

0 comments on commit 632f444

Please sign in to comment.