Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactoring the way data is returned in panedr #33

Merged
merged 14 commits into from
Jun 29, 2022
20 changes: 17 additions & 3 deletions tests/test_edr.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,20 @@
EDR_Data = namedtuple('EDR_Data', ['df', 'xvgdata', 'xvgtime', 'xvgnames',
'xvgprec', 'edrfile', 'xvgfile'])


def test_failed_import(monkeypatch):
# Putting this test first to avoid datafiles already being loaded
errmsg = "ERROR --- pandas was not found!"

monkeypatch.setitem(sys.modules, 'pandas', None)

if 'MDAnalysis.tests.datafiles' in sys.modules:
hmacdope marked this conversation as resolved.
Show resolved Hide resolved
monkeypatch.delitem(sys.modules, 'pandas')

with pytest.raises(ImportError, match=errmsg):
panedr.edr_to_df(EDR)


@pytest.fixture(scope='module',
params=[(EDR, EDR_XVG),
(EDR_IRREGULAR, EDR_IRREGULAR_XVG),
Expand All @@ -73,7 +87,7 @@ def edr(request):
xvgtime = xvgdata[:, 0]
xvgdata = xvgdata[:, 1:]
return EDR_Data(df, xvgdata, xvgtime, xvgnames, xvgprec, edrfile, xvgfile)


class TestEdrToDf(object):
"""
Expand Down Expand Up @@ -177,7 +191,7 @@ def test_edr_to_dict_matches_edr_to_df():
def read_xvg(path):
"""
Reads XVG file, returning the data, names, and precision.

The data is returned as a 2D numpy array. Column names are returned as an
array of string objects. Precision is an integer corresponding to the least
number of decimal places found, excluding the first (time) column.
Expand Down Expand Up @@ -216,7 +230,7 @@ def read_xvg(path):

def ndec(val):
"""Returns the number of decimal places of a string rep of a float

"""
try:
return len(re.split(NDEC_PATTERN, val)[1])
Expand Down