Skip to content

Commit

Permalink
test ALL AMBER files
Browse files Browse the repository at this point in the history
- fix #49
- add custom tests (with hacked accessors) for the AMBER BACE example
  and invalidfiles
  • Loading branch information
orbeckst committed Sep 27, 2022
1 parent 6eda6eb commit 0f259fa
Showing 1 changed file with 50 additions and 14 deletions.
64 changes: 50 additions & 14 deletions src/alchemtest/tests/test_amber.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
'''Tests for all the AMBER datasets'''
import pytest

from alchemtest import Bunch
from alchemtest.amber import (load_bace_improper, load_bace_example,
load_simplesolvated, load_invalidfiles, )

Expand All @@ -17,22 +18,57 @@ def dataset(self, request):
return super(TestAMBER, self).dataset(request)


# difficult -- has sub dicts under 'complex'/'solvated' -> 'decharge', 'recharge', 'vdw'
# class TestBACEexample(BaseDatasetTest):
# @pytest.fixture(scope="class",
# params = [(load_bace_example, ('complex',), (12,)),
# ])
# def dataset(self, request):
# return super().dataset(request)
# The BACE example dataset does not conform to the standard API because it
# contains sub dicts under 'complex'/'solvated' -> 'decharge', 'recharge',
# 'vdw' instead of lists of files. In order to use the same testing base class,
# we create a fake data set for "complex" and "solvated" separatedly and pass
# these accessor functions to the class.

# fake access to conform to expected API
def _load_bace_example_complex():
dset = load_bace_example()
return Bunch(data=dset.data['complex'],
DESCR="BACE example: complex")

# class TestInvalidFiles(BaseDatasetTest):
# # can't get the list of list in data
# @pytest.fixture(scope="class",
# params = [(load_invalidfiles, (slice(None),), (6,)),
# ])
# def dataset(self, request):
# return super().dataset(request)
def _load_bace_example_solvated():
dset = load_bace_example()
return Bunch(data=dset.data['solvated'],
DESCR="BACE example: solvated")

class TestBACEexample(BaseDatasetTest):
# use pytest.param to add the id for nicer pytest -v output
@pytest.fixture(scope="class",
params = [
pytest.param(
(_load_bace_example_complex,
('decharge', 'recharge', 'vdw'),
(5, 5, 12)),
id="complex"),
pytest.param(
(_load_bace_example_solvated,
('decharge', 'recharge', 'vdw'),
(5, 5, 12)),
id="solvated"),
])
def dataset(self, request):
return super().dataset(request)


# The invalidfiles dataset does not conform to the API. load_invalidfiles()
# returns a listv with just one element as data (and not a dict) so we create a
# fake dataset:
def _load_labelled_invalidfiles():
dset = load_invalidfiles()
return Bunch(data={'invalid_files': dset.data[0]},
DESCR=dset.DESCR)

class TestInvalidFiles(BaseDatasetTest):
@pytest.fixture(scope="class",
params = [(_load_labelled_invalidfiles,
('invalid_files',), (6,)),
])
def dataset(self, request):
return super().dataset(request)



0 comments on commit 0f259fa

Please sign in to comment.