-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
08dcd9c
commit a3c977d
Showing
11 changed files
with
272 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,5 +3,4 @@ INCHI-1-TEST/data/ | |
INCHI-1-TEST/docs/ | ||
INCHI-1-TEST/libs/ | ||
INCHI-1-TEST/exes/ | ||
INCHI-1-TEST/tests/ | ||
**/__pycache__/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
name: Compile InChI executable from triggering commit | ||
|
||
runs: | ||
using: "composite" | ||
steps: | ||
- run: | | ||
git config --global --add safe.directory "$GITHUB_WORKSPACE" # https://github.com/actions/runner-images/issues/6775 | ||
mkdir "$GITHUB_WORKSPACE/$EXE_DIR" | ||
./INCHI-1-TEST/compile_inchi.sh $COMMIT "$GITHUB_WORKSPACE/$EXE_DIR" exe | ||
shell: bash | ||
env: | ||
COMMIT: ${{ github.sha }} | ||
EXE_DIR: INCHI-1-TEST/exes |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# Executable tests | ||
|
||
Test specific behaviors of the executable. | ||
Ensure that specific input (molfile and arguments) elicits specific output (e.g., error). | ||
|
||
Where possible, stick to the following principles: | ||
- Define input inline rather than using external files (having entire test scenario on screen is nice). | ||
- Keep number of tests per file to a minimum. | ||
- When replicating a bug, reference the (GitHub) issue number in the file name (e.g., `test_github_42.py`). | ||
|
||
Have a look at the existing tests for examples on how to write a test. | ||
|
||
Run with `pytest INCHI-1-TEST/tests/test_executable`. | ||
Note that by default, the tests expect the InChI executable to live at `INCHI-1-TEST/exes/inchi-1`. | ||
You can specify another InChI executable like so: | ||
|
||
```shell | ||
pytest INCHI-1-TEST/tests/test_executable --exe-path=path/to/executable | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import pytest | ||
import subprocess | ||
from typing import Callable | ||
from pathlib import Path | ||
|
||
|
||
def pytest_addoption(parser): | ||
parser.addoption( | ||
"--exe-path", | ||
action="store", | ||
default="INCHI-1-TEST/exes/inchi-1", | ||
help="Absolute path to the InChI executable.", | ||
) | ||
|
||
|
||
@pytest.fixture | ||
def run_inchi_exe(request) -> Callable: | ||
def _run_inchi_exe( | ||
molfile_path: str, args: str = "" | ||
) -> subprocess.CompletedProcess: | ||
|
||
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], | ||
capture_output=True, | ||
) | ||
|
||
return _run_inchi_exe |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
from typing import Callable | ||
from pathlib import Path | ||
|
||
|
||
def tmp_molfile(molfile: Callable) -> Callable: | ||
""" | ||
Creates a temporary molfile and returns its path. | ||
`molfile` must return a string. | ||
""" | ||
|
||
def get_molfile_path(tmp_path: Path) -> str: | ||
molfile_path = tmp_path.joinpath("tmp.mol") | ||
molfile_path.write_text(molfile()) | ||
|
||
return str(molfile_path) | ||
|
||
return get_molfile_path |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
import pytest | ||
from helpers import tmp_molfile | ||
|
||
|
||
@pytest.fixture | ||
@tmp_molfile | ||
def molfile(): | ||
return """(R)-SDP | ||
ChemDraw08122419562D | ||
43 50 0 0 1 0 0 0 0 0999 V2000 | ||
-0.7846 -1.0799 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0 | ||
-1.4991 -1.4924 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0 | ||
-2.2136 -1.0799 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0 | ||
-2.2136 -0.2549 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0 | ||
-1.4991 0.1576 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0 | ||
-1.7813 0.9328 0.0000 P 0 0 0 0 0 0 0 0 0 0 0 0 | ||
-1.2510 1.5648 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0 | ||
-1.5331 2.3400 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0 | ||
-1.0028 2.9720 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0 | ||
-0.1904 2.8288 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0 | ||
0.0918 2.0535 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0 | ||
-0.4385 1.4215 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0 | ||
-2.5937 1.0761 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0 | ||
-3.1240 0.4441 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0 | ||
-3.9365 0.5873 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0 | ||
-4.2187 1.3626 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0 | ||
-3.6884 1.9946 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0 | ||
-2.8759 1.8513 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0 | ||
-0.7846 -0.2549 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0 | ||
0.0000 0.0000 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0 | ||
-0.4849 0.6674 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0 | ||
0.0000 1.3349 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0 | ||
0.7846 1.0799 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0 | ||
0.7846 0.2549 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0 | ||
1.4991 -0.1576 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0 | ||
1.7813 -0.9328 0.0000 P 0 0 0 0 0 0 0 0 0 0 0 0 | ||
2.5937 -1.0761 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0 | ||
2.8759 -1.8513 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0 | ||
3.6884 -1.9946 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0 | ||
4.2187 -1.3626 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0 | ||
3.9365 -0.5873 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0 | ||
3.1240 -0.4441 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0 | ||
1.2510 -1.5648 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0 | ||
0.4385 -1.4215 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0 | ||
-0.0918 -2.0535 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0 | ||
0.1904 -2.8288 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0 | ||
1.0028 -2.9720 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0 | ||
1.5331 -2.3400 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0 | ||
2.2136 0.2549 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0 | ||
2.2136 1.0799 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0 | ||
1.4991 1.4924 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0 | ||
0.4849 -0.6674 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0 | ||
0.0000 -1.3349 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0 | ||
1 2 2 0 0 | ||
2 3 1 0 0 | ||
3 4 2 0 0 | ||
4 5 1 0 0 | ||
5 6 1 0 0 | ||
6 7 1 0 0 | ||
7 8 2 0 0 | ||
8 9 1 0 0 | ||
9 10 2 0 0 | ||
10 11 1 0 0 | ||
11 12 2 0 0 | ||
7 12 1 0 0 | ||
6 13 1 0 0 | ||
13 14 2 0 0 | ||
14 15 1 0 0 | ||
15 16 2 0 0 | ||
16 17 1 0 0 | ||
17 18 2 0 0 | ||
13 18 1 0 0 | ||
5 19 2 0 0 | ||
1 19 1 0 0 | ||
20 19 1 1 0 | ||
20 21 1 0 0 | ||
21 22 1 0 0 | ||
22 23 1 0 0 | ||
23 24 2 0 0 | ||
20 24 1 0 0 | ||
24 25 1 0 0 | ||
25 26 1 0 0 | ||
26 27 1 0 0 | ||
27 28 2 0 0 | ||
28 29 1 0 0 | ||
29 30 2 0 0 | ||
30 31 1 0 0 | ||
31 32 2 0 0 | ||
27 32 1 0 0 | ||
26 33 1 0 0 | ||
33 34 2 0 0 | ||
34 35 1 0 0 | ||
35 36 2 0 0 | ||
36 37 1 0 0 | ||
37 38 2 0 0 | ||
33 38 1 0 0 | ||
25 39 2 0 0 | ||
39 40 1 0 0 | ||
40 41 2 0 0 | ||
23 41 1 0 0 | ||
20 42 1 6 0 | ||
42 43 1 0 0 | ||
1 43 1 0 0 | ||
M END | ||
""" | ||
|
||
|
||
@pytest.mark.xfail(strict=True, raises=AssertionError) | ||
def test_spiro_compound_chiral(molfile, run_inchi_exe): | ||
result = run_inchi_exe(molfile) | ||
|
||
assert "Warning (Not chiral) structure #1." not in result.stderr.decode() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import pytest | ||
from helpers import tmp_molfile | ||
|
||
|
||
@pytest.fixture | ||
@tmp_molfile | ||
def molfile_empty_bondblock(): | ||
return """ | ||
-INDIGO-08292417452D | ||
0 0 0 0 0 0 0 0 0 0 0 V3000 | ||
M V30 BEGIN CTAB | ||
M V30 COUNTS 1 0 0 0 0 | ||
M V30 BEGIN ATOM | ||
M V30 1 C 9.35 -4.8 0.0 0 | ||
M V30 END ATOM | ||
M V30 BEGIN BOND | ||
M V30 END BOND | ||
M V30 END CTAB | ||
M END | ||
""" | ||
|
||
|
||
@pytest.fixture | ||
@tmp_molfile | ||
def molfile_no_bondblock(): | ||
return """ | ||
-INDIGO-08292417452D | ||
0 0 0 0 0 0 0 0 0 0 0 V3000 | ||
M V30 BEGIN CTAB | ||
M V30 COUNTS 1 0 0 0 0 | ||
M V30 BEGIN ATOM | ||
M V30 1 C 9.35 -4.8 0.0 0 | ||
M V30 END ATOM | ||
M V30 END CTAB | ||
M END | ||
""" | ||
|
||
|
||
@pytest.mark.xfail(strict=True, raises=AssertionError) | ||
def test_empty_bondblock(molfile_empty_bondblock, run_inchi_exe): | ||
result = run_inchi_exe(molfile_empty_bondblock) | ||
|
||
assert ( | ||
"Error 71 (no InChI; Error: No V3000 CTAB end marker) inp structure #1." | ||
not in result.stderr.decode() | ||
) | ||
|
||
|
||
def test_no_bondblock(molfile_no_bondblock, run_inchi_exe): | ||
result = run_inchi_exe(molfile_no_bondblock) | ||
|
||
assert ( | ||
"Error 71 (no InChI; Error: No V3000 CTAB end marker) inp structure #1." | ||
not in result.stderr.decode() | ||
) |