From 632f444eb13735fbdf56b6e129e71e8c7d82257d Mon Sep 17 00:00:00 2001 From: "Jan C. Brammer" Date: Tue, 15 Oct 2024 11:41:49 +0000 Subject: [PATCH] Capture output file content --- .../tests/test_executable/conftest.py | 23 ++++++++++++++----- .../tests/test_executable/test_github_40.py | 2 +- .../tests/test_executable/test_github_52.py | 4 ++-- 3 files changed, 20 insertions(+), 9 deletions(-) diff --git a/INCHI-1-TEST/tests/test_executable/conftest.py b/INCHI-1-TEST/tests/test_executable/conftest.py index b3166d6..6a717ba 100644 --- a/INCHI-1-TEST/tests/test_executable/conftest.py +++ b/INCHI-1-TEST/tests/test_executable/conftest.py @@ -2,6 +2,7 @@ import subprocess from typing import Callable from pathlib import Path +from dataclasses import dataclass def pytest_addoption(parser): @@ -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 diff --git a/INCHI-1-TEST/tests/test_executable/test_github_40.py b/INCHI-1-TEST/tests/test_executable/test_github_40.py index 381d32a..7a9c821 100644 --- a/INCHI-1-TEST/tests/test_executable/test_github_40.py +++ b/INCHI-1-TEST/tests/test_executable/test_github_40.py @@ -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 diff --git a/INCHI-1-TEST/tests/test_executable/test_github_52.py b/INCHI-1-TEST/tests/test_executable/test_github_52.py index 0bb1d4f..db6271b 100644 --- a/INCHI-1-TEST/tests/test_executable/test_github_52.py +++ b/INCHI-1-TEST/tests/test_executable/test_github_52.py @@ -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 ) @@ -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 )