Skip to content

Commit e7c47b5

Browse files
committed
online tests for all datasets
- add tests to test_datasets - fixed error in vesicles dataset - normalized description files - updated CHANGELOG
1 parent be44b96 commit e7c47b5

File tree

6 files changed

+94
-5
lines changed

6 files changed

+94
-5
lines changed

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,17 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
55
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
66

77
## [Unreleased]
8+
### Fixes
9+
- vesicles dataset: failed to get description
10+
811
### Added
912
- progressbar for downloads (#29)
1013

14+
### Changes (internal)
15+
- tests with full downloads can be performed with
16+
`pytest -m online`; by default `pytest -m 'not online'` is run,
17+
which skips downloading gigabytes of data (PR #18)
18+
1119

1220
## [0.4.0] - 2018-10-05
1321
### Added

MDAnalysisData/descr/adk_transitions_DIMS.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
.. -*- coding: utf-8 -*-
2+
23
.. _`adk-transitions-DIMS-dataset`:
34

45
AdK DIMS transitions ensemble dataset

MDAnalysisData/descr/adk_transitions_FRODA.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
.. -*- coding: utf-8 -*-
2+
23
.. _`adk-transitions-FRODA-dataset`:
34

45

MDAnalysisData/tests/test_base.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,14 +118,13 @@ def test_fetch_remote_sha_success(remote_topology, mocker, dirname):
118118
exp = os.path.join(dirname, remote_topology.filename)
119119
assert base._fetch_remote(remote_topology, dirname=dirname) == exp
120120

121-
def test_lazy_fetch(remote_topology, tmpdir, mocker):
121+
def test_lazy_fetch(tmpdir, mocker):
122122
mocker.patch('MDAnalysisData.adk_equilibrium.exists', return_value=True)
123123
fr = mocker.patch('MDAnalysisData.adk_equilibrium._fetch_remote')
124124
# check the laziness of grabbing a dataset
125125
# - mock exists to always say true
126126
# - grab the "dataset" then check no remote calls were done
127127
stuff = adk_equilibrium.fetch_adk_equilibrium()
128-
129128
assert not fr.called
130129

131130

MDAnalysisData/tests/test_datasets.py

Lines changed: 82 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,18 @@
1111
from __future__ import absolute_import, division
1212

1313
import os.path
14+
import glob
1415

1516
import pytest
1617

1718
from MDAnalysisData import base
1819
from MDAnalysisData import datasets
1920
from MDAnalysisData import adk_equilibrium
2021
from MDAnalysisData import ifabp_water
21-
22+
from MDAnalysisData import nhaa_equilibrium
23+
from MDAnalysisData import CG_fiber
24+
from MDAnalysisData import vesicles
25+
from MDAnalysisData import adk_transitions
2226

2327
# For filetype=topology, the data are downloaded and cached.
2428
# For filetype=trajectory the cached data are used.
@@ -38,7 +42,9 @@ def test_adk_equilibrium(filetype):
3842
assert os.path.exists(data[filetype])
3943

4044
@pytest.mark.online
41-
@pytest.mark.parametrize('filetype', ('topology', 'trajectory'))
45+
@pytest.mark.parametrize('filetype', ('topology',
46+
'trajectory',
47+
'structure'))
4248
def test_ifabp_water(filetype):
4349
data = datasets.fetch_ifabp_water()
4450

@@ -50,3 +56,77 @@ def test_ifabp_water(filetype):
5056
assert os.path.basename(data[filetype]) == metadata[filetype].filename
5157
assert os.path.exists(data[filetype])
5258

59+
60+
@pytest.mark.online
61+
@pytest.mark.parametrize('filetype', ('topology', 'trajectory'))
62+
def test_nhaa_equilibrium(filetype):
63+
data = datasets.fetch_nhaa_equilibrium()
64+
65+
metadata = nhaa_equilibrium.ARCHIVE
66+
67+
assert len(data.DESCR) == 1475
68+
assert data.DESCR.startswith(".. -*- coding: utf-8 -*-\n\n.. _`nhaa-equilibrium-dataset`:")
69+
70+
assert os.path.basename(data[filetype]) == metadata[filetype].filename
71+
assert os.path.exists(data[filetype])
72+
73+
74+
@pytest.mark.online
75+
@pytest.mark.parametrize('filetype', ('topology', 'trajectory'))
76+
def test_CG_fiber(filetype):
77+
data = datasets.fetch_CG_fiber()
78+
79+
metadata = CG_fiber.ARCHIVE
80+
81+
assert len(data.DESCR) == 535
82+
assert data.DESCR.startswith(".. -*- coding: utf-8 -*-\n\n.. _`CG_fiber-dataset`:")
83+
84+
assert os.path.basename(data[filetype]) == metadata[filetype].filename
85+
assert os.path.exists(data[filetype])
86+
87+
88+
@pytest.mark.online
89+
@pytest.mark.parametrize('filename',
90+
vesicles.METADATA['vesicle_lib']['CONTENTS']['structures'])
91+
def test_vesicles(filename):
92+
data = datasets.fetch_vesicle_lib()
93+
94+
metadata = vesicles.METADATA['vesicle_lib']
95+
96+
assert len(data.DESCR) == 1329
97+
assert data.DESCR.startswith(".. -*- coding: utf-8 -*-\n\n.. _`vesicle-library-dataset`:")
98+
99+
assert data.N_structures == metadata['CONTENTS']['N_structures']
100+
assert data.N_structures == len(metadata['CONTENTS']['structures'])
101+
assert any(path.endswith(filename) for path in data.structures)
102+
assert any(os.path.exists(path) for path in data.structures if path.endswith(filename))
103+
104+
105+
@pytest.mark.online
106+
@pytest.mark.parametrize('method,descr_length',
107+
(('DIMS', 1395),
108+
('FRODA', 1399)))
109+
@pytest.mark.parametrize('filetype', ('topology', 'trajectories'))
110+
def test_adk_transitions(method, descr_length, filetype):
111+
if method == "DIMS":
112+
data = datasets.fetch_adk_transitions_DIMS()
113+
elif method == "FRODA":
114+
data = datasets.fetch_adk_transitions_FRODA()
115+
else:
116+
raise ValueError("Unknown adk_transitions method '{}'".format(method))
117+
118+
metadata = adk_transitions.METADATA[method]['CONTENTS']
119+
120+
assert len(data.DESCR) == descr_length
121+
descr_header = (".. -*- coding: utf-8 -*-\n\n"
122+
".. _`adk-transitions-{}-dataset`:".format(
123+
method))
124+
assert data.DESCR.startswith(descr_header)
125+
126+
datafiles = data[filetype] if isinstance(data[filetype], list) \
127+
else [data[filetype]]
128+
pattern = os.path.join("*", metadata[filetype])
129+
130+
assert all(glob.fnmatch.fnmatch(path, pattern) for path in datafiles), \
131+
"not all datafiles {} match {}".format(datafiles, pattern)
132+
assert all(os.path.exists(path) for path in datafiles)

MDAnalysisData/vesicles.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,6 @@ def fetch_vesicle_lib(data_home=None, download_if_missing=True):
106106
len(records.structures),
107107
records.N_structures))
108108

109-
records.DESCR = _read_description(DESCRIPTION)
109+
records.DESCR = _read_description(metadata['DESCRIPTION'])
110110

111111
return records

0 commit comments

Comments
 (0)