Skip to content

Commit 806ef7d

Browse files
authored
Expand test matrix to macOS (#32)
* expand test matrix * change directory for tempfile * fix python versions list * tempfile in current dir with os module * fix noxfile linting * revert change in noxfile * try to use tempdirs instead of tempfiles * remove temporary files * fix linting * fix linting * try to remove pytype * add back pytype * remove windows from ci matrix Signed-off-by: Rocco Meli <rocco.meli@biodtp.ox.ac.uk>
1 parent 91154dc commit 806ef7d

File tree

6 files changed

+173
-132
lines changed

6 files changed

+173
-132
lines changed

.github/workflows/tests.yml

+13-4
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,22 @@
11
# .github/workflows/tests.yml
22
name: Tests
3-
on: push
3+
4+
on:
5+
push:
6+
branches:
7+
- "master"
8+
pull_request:
9+
branches:
10+
- "*"
11+
412
jobs:
513
tests:
6-
runs-on: ubuntu-latest
14+
runs-on: ${{ matrix.os }}
715
strategy:
816
matrix:
9-
python-version: ['3.7', '3.8']
10-
name: Python ${{ matrix.python-version }}
17+
os: [ubuntu-latest, macOS-latest]
18+
python-version: ['3.7', '3.8', '3.9']
19+
name: Python ${{ matrix.python-version }} OS ${{ matrix.os }}
1120
steps:
1221
- uses: actions/checkout@v2
1322
- uses: actions/setup-python@v1

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ pip-log.txt
1717
.coverage
1818
.tox
1919
.pytest_cache
20+
.pytype
2021

2122
.DS_Store
2223
.idea/*

noxfile.py

+22-9
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# noxfile.py
22

3+
import os
34
import tempfile
45

56
import nox
@@ -10,7 +11,10 @@
1011
locations = "src", "tests", "noxfile.py"
1112

1213

13-
@nox.session(python=["3.8", "3.7"])
14+
python_versions = ["3.9", "3.8", "3.7"]
15+
16+
17+
@nox.session(python=python_versions)
1418
def tests(session: Session) -> None:
1519
args = session.posargs or ["--cov", "-m", "not e2e"]
1620
session.run("poetry", "install", "--no-dev", external=True)
@@ -20,7 +24,7 @@ def tests(session: Session) -> None:
2024
session.run("pytest", *args)
2125

2226

23-
@nox.session(python=["3.8", "3.7"])
27+
@nox.session(python=python_versions)
2428
def lint(session: Session) -> None:
2529
args = session.posargs or locations
2630
install_with_constraints(
@@ -43,21 +47,26 @@ def black(session: Session) -> None:
4347

4448
@nox.session(python="3.8")
4549
def safety(session: Session) -> None:
46-
with tempfile.NamedTemporaryFile() as requirements:
50+
with tempfile.TemporaryDirectory() as tmpdirname:
4751
session.run(
4852
"poetry",
4953
"export",
5054
"--dev",
5155
"--format=requirements.txt",
5256
"--without-hashes",
53-
f"--output={requirements.name}",
57+
f"--output={os.path.join(tmpdirname, 'poetry-export.out')}",
5458
external=True,
5559
)
5660
install_with_constraints(session, "safety")
57-
session.run("safety", "check", f"--file={requirements.name}", "--full-report")
61+
session.run(
62+
"safety",
63+
"check",
64+
f"--file={os.path.join(tmpdirname, 'safety-check.out')}",
65+
"--full-report",
66+
)
5867

5968

60-
@nox.session(python=["3.8", "3.7"])
69+
@nox.session(python=python_versions)
6170
def mypy(session: Session) -> None:
6271
args = session.posargs or locations
6372
install_with_constraints(session, "mypy")
@@ -81,14 +90,18 @@ def coverage(session: Session) -> None:
8190

8291

8392
def install_with_constraints(session: Session, *args, **kwargs) -> None:
84-
with tempfile.NamedTemporaryFile() as requirements:
93+
with tempfile.TemporaryDirectory() as tmpdirname:
8594
session.run(
8695
"poetry",
8796
"export",
8897
"--dev",
8998
"--format=requirements.txt",
9099
"--without-hashes",
91-
f"--output={requirements.name}",
100+
f"--output={os.path.join(tmpdirname, 'poetry-export.out')}",
92101
external=True,
93102
)
94-
session.install(f"--constraint={requirements.name}", *args, **kwargs)
103+
session.install(
104+
f"--constraint={os.path.join(tmpdirname, 'poetry-export.out')}",
105+
*args,
106+
**kwargs,
107+
)

tests/conftest.py

+82
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
# tests/conftest.py
22

3+
import os
4+
35
import pytest
46

57
from tests.store import acetylene, iridiumCatalyst, pyridine
68

9+
s = os.linesep
10+
711

812
@pytest.fixture(scope="session")
913
def pyridine_xyz(tmpdir_factory):
@@ -48,3 +52,81 @@ def iridiumcat_xyz(tmpdir_factory):
4852
mol.writeMolecule(name=name, path=dn)
4953

5054
return fn
55+
56+
57+
@pytest.fixture(scope="session")
58+
def fluoromethane_coord(tmpdir_factory):
59+
fn = tmpdir_factory.mktemp("data").join("fluoromethane.coord")
60+
61+
with open(fn, mode="w+", encoding="utf-8") as f:
62+
f.write("$coord" + s)
63+
f.write(" 1.87167924 -0.101043656 0.1596818582 c" + s)
64+
f.write(" 4.43543289 -0.101043656 0.1596818582 f" + s)
65+
f.write(" 1.20847986 -1.386321988 1.6312493924 h" + s)
66+
f.write(" 1.20847986 -0.732816897 -1.6891694984 h" + s)
67+
f.write(" 1.20846096 1.816007916 0.5369845779 h" + s)
68+
f.write("$end")
69+
f.flush()
70+
71+
return fn
72+
73+
74+
@pytest.fixture(scope="session")
75+
def lithium_hydride_coord(tmpdir_factory):
76+
fn = tmpdir_factory.mktemp("data").join("lithium_hydride.coord")
77+
78+
with open(fn, mode="w+", encoding="utf-8") as f:
79+
f.write("$coord" + s)
80+
f.write("0 0 0 li" + s)
81+
f.write("0 0 2 h" + s)
82+
f.write("0 0 4 h" + s)
83+
f.write("$end")
84+
f.flush()
85+
86+
return fn
87+
88+
89+
@pytest.fixture(scope="session")
90+
def ch_coord(tmpdir_factory):
91+
fn = tmpdir_factory.mktemp("data").join("ch.coord")
92+
93+
with open(fn, mode="w+", encoding="utf-8") as f:
94+
f.write("$coord" + s)
95+
f.write("0.00000000000000 0.00000000000000 -1.06176434496059 c" + s)
96+
f.write("0.00000000000000 0.00000000000000 1.06176434496059 h" + s)
97+
f.write("$end")
98+
f.flush()
99+
100+
return fn
101+
102+
103+
@pytest.fixture(scope="session")
104+
def ch_coord_2(tmpdir_factory):
105+
fn = tmpdir_factory.mktemp("data").join("ch-2.coord")
106+
107+
with open(fn, mode="w+", encoding="utf-8") as f:
108+
f.write("test" + s)
109+
f.write("test" + s)
110+
f.write("$coord" + s)
111+
f.write("0.00000000000000 0.00000000000000 -1.06176434496059 c" + s)
112+
f.write("0.00000000000000 0.00000000000000 1.06176434496059 h" + s)
113+
f.write("$end")
114+
f.flush()
115+
116+
return fn
117+
118+
119+
@pytest.fixture(scope="session")
120+
def ch_coord_ignore(tmpdir_factory):
121+
fn = tmpdir_factory.mktemp("data").join("ch_ignore.coord")
122+
123+
with open(fn, mode="w+", encoding="utf-8") as f:
124+
f.write("test" + s)
125+
f.write("$coord" + s)
126+
f.write("0.00000000000000 0.00000000000000 -1.06176434496059 c" + s)
127+
f.write("0.00000000000000 0.00000000000000 1.06176434496059 h" + s)
128+
f.write("$end")
129+
f.write("0.00000000000000 0.00000000000000 2.06176434496059 h" + s)
130+
f.flush()
131+
132+
return fn

tests/test_molecule.py

+19-36
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
# tests/test_molecule.py
22

33
import os
4-
import tempfile
54

65
import numpy as np
76
import pytest
@@ -20,41 +19,25 @@
2019

2120

2221
# turbomole coord files can be read
23-
def test_a_user_can_compute_coordination_numbers_for_molecule():
24-
with tempfile.NamedTemporaryFile(mode="w+", encoding="utf-8") as f:
25-
f.write("$coord" + s)
26-
f.write(" 1.87167924 -0.101043656 0.1596818582 c" + s)
27-
f.write(" 4.43543289 -0.101043656 0.1596818582 f" + s)
28-
f.write(" 1.20847986 -1.386321988 1.6312493924 h" + s)
29-
f.write(" 1.20847986 -0.732816897 -1.6891694984 h" + s)
30-
f.write(" 1.20846096 1.816007916 0.5369845779 h" + s)
31-
f.write("$end")
32-
f.flush()
33-
fileObject = open(f.name, "r+")
34-
atoms = ksr.read(fileObject)
35-
molecule = Molecule(symbols=atoms)
36-
cns = molecule.get_cns(cntype="exp")
37-
c1 = np.around(cns, decimals=1)
38-
got = c1[0]
39-
want = 4.0
40-
assert got == want
41-
42-
43-
def test_user_can_calculate_eeq_atomic_charges():
44-
with tempfile.NamedTemporaryFile(mode="w+", encoding="utf-8") as f:
45-
f.write("$coord" + s)
46-
f.write("0 0 0 li" + s)
47-
f.write("0 0 2 h" + s)
48-
f.write("0 0 4 h" + s)
49-
f.write("$end")
50-
f.flush()
51-
fileObject = open(f.name, "r+")
52-
atoms = ksr.read(fileObject)
53-
molecule = Molecule(symbols=atoms)
54-
eeq = molecule.get_eeq(charge=0)
55-
want = [0.51925854, -0.35007273, -0.16918582]
56-
difference = sum([a - b for a, b in zip(want, eeq)])
57-
assert difference < 1e-6
22+
def test_a_user_can_compute_coordination_numbers_for_molecule(fluoromethane_coord):
23+
fileObject = open(fluoromethane_coord, "r+")
24+
atoms = ksr.read(fileObject)
25+
molecule = Molecule(symbols=atoms)
26+
cns = molecule.get_cns(cntype="exp")
27+
c1 = np.around(cns, decimals=1)
28+
got = c1[0]
29+
want = 4.0
30+
assert got == want
31+
32+
33+
def test_user_can_calculate_eeq_atomic_charges(lithium_hydride_coord):
34+
fileObject = open(lithium_hydride_coord, "r+")
35+
atoms = ksr.read(fileObject)
36+
molecule = Molecule(symbols=atoms)
37+
eeq = molecule.get_eeq(charge=0)
38+
want = [0.51925854, -0.35007273, -0.16918582]
39+
difference = sum([a - b for a, b in zip(want, eeq)])
40+
assert difference < 1e-6
5841

5942

6043
def test_user_can_pass_information_from_mol_to_mol():

0 commit comments

Comments
 (0)