Skip to content

Commit 0e1cfe2

Browse files
authored
Merge pull request #39 from Becksteinlab/improve-coverage
Improve coverage — much more todo
2 parents 4abf1e5 + e6825a9 commit 0e1cfe2

File tree

5 files changed

+426
-48
lines changed

5 files changed

+426
-48
lines changed

.coverage

-52 KB
Binary file not shown.

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ dist/
66
# Test artifacts
77
basicrta-*/
88
*.pkl
9+
.coverage
910

1011
# editor files
1112
*~

basicrta/tests/test_contacts.py

Lines changed: 11 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55
import sys
66
import MDAnalysis as mda
77
import numpy as np
8-
import contextlib
98
from pathlib import Path
109
from basicrta.tests.datafiles import PDB, XTC
10+
from basicrta.tests.utils import work_in
1111
from basicrta.contacts import MapContacts
1212

1313
@pytest.fixture(scope="module")
@@ -18,13 +18,9 @@ def setup_mapcontacts(tmp_path_factory):
1818

1919
tmp_path_factory.mktemp("data")
2020
datadir = tmp_path_factory.mktemp("data")
21-
prev_cwd = Path.cwd()
22-
os.chdir(datadir)
2321

24-
try:
22+
with work_in(datadir):
2523
MapContacts(u, P88, chol, nslices=1).run()
26-
finally:
27-
os.chdir(prev_cwd)
2824

2925
fn = datadir / "contacts_max10.0.pkl"
3026
assert fn.exists(), "Failed to locate {str(fn)}"
@@ -33,14 +29,10 @@ def setup_mapcontacts(tmp_path_factory):
3329
@pytest.fixture
3430
def setup_processcontacts(setup_mapcontacts, tmp_path_factory):
3531
from basicrta.contacts import ProcessContacts
36-
prev_cwd = Path.cwd()
3732
datadir = setup_mapcontacts.parents[0]
38-
os.chdir(datadir)
3933

40-
try:
34+
with work_in(datadir):
4135
ProcessContacts(7.0, map_name='contacts_max10.0.pkl').run()
42-
finally:
43-
os.chdir(prev_cwd)
4436

4537
fn = datadir / "contacts_7.0.pkl"
4638
assert fn.exists(), "Failed to locate {str(fn)}"
@@ -58,16 +50,16 @@ def test_mapcontacts(setup_mapcontacts):
5850

5951
@pytest.mark.filterwarnings("ignore::UserWarning")
6052
def test_max_cutoff(tmp_path):
61-
os.chdir(tmp_path)
62-
u = mda.Universe(PDB, XTC)
63-
P88 = u.select_atoms('resname PRO and resid 88')
64-
chol = u.select_atoms('resname CHOL and resid 309')
65-
MapContacts(u, P88, chol, nslices=1, max_cutoff=12.0).run()
53+
with work_in(tmp_path):
54+
u = mda.Universe(PDB, XTC)
55+
P88 = u.select_atoms('resname PRO and resid 88')
56+
chol = u.select_atoms('resname CHOL and resid 309')
57+
MapContacts(u, P88, chol, nslices=1, max_cutoff=12.0).run()
6658

67-
with open('contacts_max12.0.pkl', 'rb') as p:
68-
contacts = pickle.load(p)
59+
with open('contacts_max12.0.pkl', 'rb') as p:
60+
contacts = pickle.load(p)
6961

70-
assert os.path.exists("contacts_max12.0.pkl"), "contacts_max12.0.pkl was not generated"
62+
assert os.path.exists("contacts_max12.0.pkl"), "contacts_max12.0.pkl was not generated"
7163
assert len(contacts) == 30
7264
assert (contacts[:, 0] == np.delete(np.arange(69,101), [4,5])).all()
7365

0 commit comments

Comments
 (0)