Skip to content

Commit 6d97b2d

Browse files
committed
Unify READMEs about testing
1 parent 0102417 commit 6d97b2d

File tree

3 files changed

+75
-56
lines changed

3 files changed

+75
-56
lines changed
Lines changed: 75 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
# Library tests
1+
# Testing the InChI
22

33
## Test environment
44

55
### Docker container
66

7-
Use our [Dockerfile](../Dockerfile) to run the test suite.
7+
Use our [Dockerfile](Dockerfile) to run the test suite.
88
Build a Docker image by running the following command from the root of the repository:
99

1010
```Shell
@@ -22,14 +22,57 @@ You can now run the commands that are mentioned in the remainder of this README.
2222

2323
### Visual Studio Code devcontainer
2424

25-
If you prefer, run the tests in the [Visual Studio Code devcontainer](https://code.visualstudio.com/docs/devcontainers/containers)
26-
that's specified under [.devcontainer.json](../../.devcontainer.json).
27-
Note that in the devcontainer, you'll have to compile the InChI libraries yourself, see `INCHI-1-TEST/compile_inchi.sh` for details.
28-
The test pipeline expects the library under `INCHI-1-TEST/libs`, see for example `INCHI-1-TEST/tests/test_library/config/config.invariance.py`.
25+
As an alternative to the plain Docker container, you can run the tests in the [Visual Studio Code devcontainer](https://code.visualstudio.com/docs/devcontainers/containers) that's specified under [.devcontainer.json](../.devcontainer.json).
26+
Note that, in contrast to the plain container, in the devcontainer, you'll have to compile the InChI libraries yourself.
27+
Have a look at [the compilation script](compile_inchi.sh) for details.
2928

30-
## Datasets
29+
## Test data
3130

32-
In this README, `<dataset>` refers to either `ci`
31+
We follow two conventions for supplying molfiles as test data.
32+
33+
- Inline Python string in a testfile:
34+
35+
- Benefit of having entire test scenario on screen.
36+
- Only use with small(ish) molfiles, the benefit of overview is lost quickly with molfiles that require vertical scrolling.
37+
38+
- Compressed [SDF files](https://en.wikipedia.org/wiki/Chemical_table_file#SDF) (i.e., `testdata.sdf.gz`):
39+
40+
- Use when a test scenario requires many and/or large molfiles.
41+
- One or multiple SDF files live in a `data` directory inside the test directories (e.g. `tests/test_executable/data`)
42+
- If an SDF is only used in one place, name the SDF after testfile.
43+
44+
Where possible, stick to the following principles:
45+
46+
- Keep number of tests per file to a minimum.
47+
- When replicating a bug, reference the (GitHub) issue number in the file name (e.g., `test_github_42.py`).
48+
49+
Have a look at the existing tests for examples on how to write a test.
50+
51+
## Meta tests
52+
53+
The tests under `tests/test_meta` are testing the tests (e.g., does structure permutation work properly?)
54+
Run with `pytest INCHI-1-TEST/tests/test_meta`.
55+
56+
## Executable tests
57+
58+
The tests under `tests/test_executable` test specific behaviors of the executable.
59+
They ensure that specific input (e.g., molfile and arguments) elicits specific output (e.g., error).
60+
61+
Run with `pytest INCHI-1-TEST/tests/test_executable`.
62+
Note that by default, the tests expect the InChI executable to live at `INCHI-1-TEST/exes/inchi-1`.
63+
You can specify another InChI executable as argument to the `--exe-path` parameter:
64+
65+
```shell
66+
pytest INCHI-1-TEST/tests/test_executable --exe-path=path/to/executable
67+
```
68+
69+
## Library tests
70+
71+
Under `tests/test_library` we run tests against the InChI API.
72+
73+
### Datasets
74+
75+
In the following, `<dataset>` refers to either `ci`
3376
(i.e, continuous integration, aka the tests running on GitHub), or a `<subset>` of PubChem.
3477
`<subset>` can be either `compound`, `compound3d`, or `substance`.
3578
The `ci` data already lives in the repository (i.e., `mcule.sdf.gz` and `inchi.sdf.gz` under `INCHI-1-TEST/tests/test_library/data/ci`).
@@ -41,28 +84,28 @@ python -m INCHI-1-TEST.tests.test_library.data.pubchem.download <subset>
4184
```
4285

4386
On completion of the download you'll find the data in `INCHI-1-TEST/tests/test_library/data/pubchem/<subset>`.
44-
Validate the integrity of `<subset>` (i.e., make sure the downloads aren't corrupted) by running
87+
Validate the integrity of `<subset>` (i.e., make sure the downloads aren't corrupted) with the hashes provided by PubChem by running
4588

4689
```Shell
4790
python -m INCHI-1-TEST.tests.test_library.data.pubchem.validate <subset>
4891
```
4992

5093
Note that validation isn't available for `compound3d` (PubChem doesn't provide file hashes).
5194

52-
## Multithreading tests
95+
### Multithreading tests
5396

5497
Test the thread safety of the InChI library by running
5598

5699
`python INCHI-1-TEST/tests/test_library/test_multithreading.py`
57100

58-
The script triggers a segfault should the thread safety of the library be compromised.
101+
The script triggers a segfault in case the thread safety of the library is compromised.
59102

60-
## Invariance tests
103+
### Invariance tests
61104

62105
Invariance tests are meant to detect problems with InChI's canonicalization algorithm.
63106
During an invariance test, the atom indices of a structure are permuted repeatedly and each permutation is expected to result in the same InChI output.
64107

65-
<img src="./invariance.svg" alt="schematic" width="400"/>
108+
<img src="tests/test_library/invariance.svg" alt="schematic" width="400"/>
66109

67110
```Shell
68111
run-tests --test-config=INCHI-1-TEST/tests/test_library/config/config.invariance.py --data-config=INCHI-1-TEST/tests/test_library/config/config.<dataset>.py
@@ -74,18 +117,17 @@ If not all permutations produce the same InChI output,
74117
a test failure is logged under `<datetime>.invariance_<dataset>.log`
75118
(where `<datetime>` reflects the start of the test run).
76119

77-
## Regression tests
120+
### Regression tests
78121

79122
Regression tests investigate if the output of the current development version matches the reference output of a previous release.
80123
In other word, regression test are meant to detect problems with the stability of the InChI across versions.
81-
In the image below, the 1st and 2nd run represent tests runs
82-
that are conducted after some alternations to the codebase.
124+
In the image below, the 1st and 2nd run represent tests runs that are conducted after some alternations to the codebase.
83125
On the first run, the output matches the reference.
84126
The 2nd run results in a regression, since the output no longer matches the reference.
85127

86-
<img src="./regression.svg" alt="schematic" width="400"/>
128+
<img src="tests/test_library/regression.svg" alt="schematic" width="400"/>
87129

88-
### Compute references
130+
#### Compute references
89131

90132
```Shell
91133
run-tests --test-config=INCHI-1-TEST/tests/test_library/config/config.regression_reference.py --data-config=INCHI-1-TEST/tests/test_library/config/config.<dataset>.py
@@ -95,7 +137,7 @@ uses `libinchi.so.<version>`, the shared library specified with `--test-config`,
95137
and generates an `<SDF>.regression_reference.sqlite` file for each SDF under `INCHI-1-TEST/tests/test_library/data/<dataset>`.
96138
The `sqlite` file contains a table with the results for each molfile.
97139

98-
### Run tests against the references
140+
#### Run tests against the references
99141

100142
```Shell
101143
run-tests --test-config=INCHI-1-TEST/tests/test_library/config/config.regression.py --data-config=INCHI-1-TEST/tests/test_library/config/config.<dataset>.py
@@ -110,7 +152,7 @@ To convince yourself that the tests fail once a regression has been introduced,
110152
change `INCHI_NAME` in `INCHI-1-SRC/INCHI_BASE/src/mode.h` and re-run the tests.
111153
The tests should now fail and indicate that the difference between the reference results and the latest test run is the change you've made.
112154

113-
## Inspect test results
155+
### Inspect test results
114156

115157
In addition to inspecting the raw logs, you can review the results by running
116158

@@ -122,17 +164,17 @@ where `<test>` can be `regression` or `invariance`.
122164
The command generates an HTML report for each SDF under `INCHI-1-TEST/tests/test_library/data/<dataset>` that contains structures which failed the test.
123165
You can view the HTML report in your browser.
124166

125-
## Inspect `.sqlite` files
167+
### Inspect `.sqlite` files
126168

127169
For conveniently viewing `.sqlite` files, install the `SQLite Viewer` extension for VSCode: <https://marketplace.visualstudio.com/items?itemName=qwtel.sqlite-viewer>. Otherwise you can query the `.sqlite` files with the [sqlite command line utility](https://sqlite.org/cli.html).
128170

129-
## Test customization
171+
### Test customization
130172

131173
So far, we showed how to run the tests with our configuration against our datasets.
132174
Alternatively, you can run the tests against your own data and/or adapt the configuration.
133175

134176
Before showing examples of how to customize the tests, let's look at how we're configuring them.
135-
Our [docker-compose.yml](../docker-compose.yml) shows how to inject the data and configuration into the [container](#docker-container)
177+
Our [docker-compose.yml](docker-compose.yml) shows how to inject the data and configuration into the [container](#docker-container)
136178
via [volumes](https://docs.docker.com/compose/compose-file/05-services/#volumes):
137179

138180
```yml
@@ -162,7 +204,7 @@ services:
162204
Make sure to adapt `context` to your directory structure. `context` needs to be the path to the `InChI` repository,
163205
relative from `docker-compose.custom.yml`.
164206

165-
### Your own dataset
207+
#### Your own dataset
166208

167209
You can map a single SDF file or a directory containing SDF files into the container's `/inchi` directory by specifying a volume:
168210

@@ -180,7 +222,7 @@ services:
180222
target: /inchi/data
181223
```
182224
183-
### Your own configuration
225+
#### Your own configuration
184226
185227
Next, add a volume to inject your [configuration files](#configuration-files) into the container:
186228
@@ -201,32 +243,32 @@ services:
201243
target: /inchi/config
202244
```
203245
204-
### Configuration files
246+
#### Configuration files
205247
206248
The tests can be configured with Python files (e.g., `config.py`).
207249
We're not using other configuration formats (e.g., `config.yaml`),
208250
since the configuration needs to be powerful enough to enable dynamic customization (e.g., parsing molfile ID).
209-
We provide two [templates](INCHI-1-TEST/tests/test_library/inchi_tests/config_models.py) under `config_models.py` that allow you to customize the configuration:
251+
We provide two [templates](tests/test_library/inchi_tests/config_models.py) under `config_models.py` that allow you to customize the configuration:
210252

211-
#### `TestConfig`
253+
##### `TestConfig`
212254

213255
Lets you customize the test itself, e.g.,
214256
configuring what to run ("regression", "regression-reference", or "invariance"),
215257
which InChI library to use, and which parameters to pass to the InChI API.
216258
For details, have a look at the comments in the `TestConfig` class.
217259
Your configuration file, e.g., `config/custom-regression.py` must contain an instance of `TestConfig` called `config`.
218-
For an example of how to instantiate a `TestConfig` object, have a look at our [regression configuration](INCHI-1-TEST/tests/test_library/config/config.regression.py).
260+
For an example of how to instantiate a `TestConfig` object, have a look at our [regression configuration](tests/test_library/config/config.regression.py).
219261

220-
#### `DataConfig`
262+
##### `DataConfig`
221263

222264
Lets you configure your custom data, e.g., location of the data.
223265
For details, have a look at the comments in the `DataConfig` class.
224266
Your configuration file, e.g., `config/custom-data.py` must contain an instance of `DataConfig` called `config`.
225-
For an example of how to instantiate a `DataConfig` object, have a look at our [CI configuration](INCHI-1-TEST/tests/test_library/config/config.ci.py).
267+
For an example of how to instantiate a `DataConfig` object, have a look at our [CI configuration](tests/test_library/config/config.ci.py).
226268
Note that the `DataConfig` object must point to data that you've [mounted into the container](#your-own-dataset).
227-
For an example of how to instantiate a `DataConfig` object, have a look at our the configuration of our [CI data](INCHI-1-TEST/tests/test_library/config/config.ci.py).
269+
For an example of how to instantiate a `DataConfig` object, have a look at our the configuration of our [CI data](tests/test_library/config/config.ci.py).
228270

229-
### Run your custom tests
271+
#### Run your custom tests
230272

231273
Once you've written the `docker-compose.custom.yml` and your [configuration files](#configuration-files), build a custom image with
232274

INCHI-1-TEST/tests/test_executable/README.md

Lines changed: 0 additions & 19 deletions
This file was deleted.

INCHI-1-TEST/tests/test_meta/README.md

Lines changed: 0 additions & 4 deletions
This file was deleted.

0 commit comments

Comments
 (0)