Skip to content

Commit

Permalink
refactor: move testfile parameters to datafiles
Browse files Browse the repository at this point in the history
This ensures that pyedr and panedr are tested on the same files with the
same parameters.
  • Loading branch information
ezavod committed Oct 27, 2023
1 parent 2281e57 commit 390ca2a
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 62 deletions.
33 changes: 2 additions & 31 deletions panedr/panedr/tests/test_edr.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,27 +8,14 @@
import pytest
import re
from collections import namedtuple
from pathlib import Path
import pickle

import numpy as np
from numpy.testing import assert_allclose
import pandas
import pyedr
from pyedr.tests.test_edr import read_xvg, redirect_stderr
from pyedr.tests.datafiles import (
EDR, EDR_XVG, EDR_UNITS, EDR_IRREG, EDR_IRREG_XVG,
EDR_IRREG_UNITS, EDR_DOUBLE, EDR_DOUBLE_XVG, EDR_DOUBLE_UNITS,
EDR_BLOCKS, EDR_BLOCKS_XVG, EDR_BLOCKS_UNITS,
EDR_V1, EDR_V1_XVG, EDR_V1_UNITS,
EDR_V1_DOUBLE, EDR_V1_DOUBLE_XVG, EDR_V1_DOUBLE_UNITS,
EDR_V2, EDR_V2_XVG, EDR_V2_UNITS,
EDR_V2_DOUBLE, EDR_V2_DOUBLE_XVG, EDR_V2_DOUBLE_UNITS,
EDR_V3, EDR_V3_XVG, EDR_V3_UNITS,
EDR_V3_DOUBLE, EDR_V3_DOUBLE_XVG, EDR_V3_DOUBLE_UNITS,
EDR_V4, EDR_V4_XVG, EDR_V4_UNITS,
EDR_V4_DOUBLE, EDR_V4_DOUBLE_XVG, EDR_V4_DOUBLE_UNITS
)
from pyedr.tests.datafiles import EDR, EDR_XVG, TESTFILE_PARAMS

import panedr

Expand Down Expand Up @@ -58,23 +45,7 @@ def check_version_warning(func, edrfile, version):


@pytest.fixture(scope='module',
params=[(EDR, EDR_XVG, EDR_UNITS, 5),
(EDR_IRREG, EDR_IRREG_XVG, EDR_IRREG_UNITS, 5),
(EDR_DOUBLE, EDR_DOUBLE_XVG, EDR_DOUBLE_UNITS, 5),
(EDR_BLOCKS, EDR_BLOCKS_XVG, EDR_BLOCKS_UNITS, 5),
(EDR_V1, EDR_V1_XVG, EDR_V1_UNITS, 1),
(EDR_V1_DOUBLE, EDR_V1_DOUBLE_XVG,
EDR_V1_DOUBLE_UNITS, 1),
(EDR_V2, EDR_V2_XVG, EDR_V2_UNITS, 2),
(EDR_V2_DOUBLE, EDR_V2_DOUBLE_XVG,
EDR_V2_DOUBLE_UNITS, 2),
(EDR_V3, EDR_V3_XVG, EDR_V3_UNITS, 3),
(EDR_V3_DOUBLE, EDR_V3_DOUBLE_XVG,
EDR_V3_DOUBLE_UNITS, 3),
(EDR_V4, EDR_V4_XVG, EDR_V4_UNITS, 4),
(EDR_V4_DOUBLE, EDR_V4_DOUBLE_XVG,
EDR_V4_DOUBLE_UNITS, 4),
(Path(EDR), EDR_XVG, EDR_UNITS, 5), ])
params=TESTFILE_PARAMS)
def edr(request):
edrfile, xvgfile, unitfile, version = request.param
df = check_version_warning(panedr.edr_to_df, edrfile, version)
Expand Down
21 changes: 21 additions & 0 deletions pyedr/pyedr/tests/datafiles.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
# Move to impportlib.resources when py>=3.7
from pkg_resources import resource_filename

from pathlib import Path


EDR = resource_filename(__name__, 'data/cat_small.edr')
EDR_XVG = resource_filename(__name__, 'data/cat_small.xvg')
Expand Down Expand Up @@ -86,3 +88,22 @@
EDR_V4_DOUBLE = resource_filename(__name__, 'data/4_d.edr')
EDR_V4_DOUBLE_XVG = resource_filename(__name__, 'data/4_d.xvg')
EDR_V4_DOUBLE_UNITS = resource_filename(__name__, 'data/234_units.p')

# Collection of testfiles and corresponding reference data as a tuple.
# A tuple contains paths for the testfile, expected values in a XVG file,
# a serialized unit dictionary, and the EDR version number in this order.
TESTFILE_PARAMS = [
(EDR, EDR_XVG, EDR_UNITS, 5),
(EDR_IRREG, EDR_IRREG_XVG, EDR_IRREG_UNITS, 5),
(EDR_DOUBLE, EDR_DOUBLE_XVG, EDR_DOUBLE_UNITS, 5),
(EDR_BLOCKS, EDR_BLOCKS_XVG, EDR_BLOCKS_UNITS, 5),
(EDR_V1, EDR_V1_XVG, EDR_V1_UNITS, 1),
(EDR_V1_DOUBLE, EDR_V1_DOUBLE_XVG, EDR_V1_DOUBLE_UNITS, 1),
(EDR_V2, EDR_V2_XVG, EDR_V2_UNITS, 2),
(EDR_V2_DOUBLE, EDR_V2_DOUBLE_XVG, EDR_V2_DOUBLE_UNITS, 2),
(EDR_V3, EDR_V3_XVG, EDR_V3_UNITS, 3),
(EDR_V3_DOUBLE, EDR_V3_DOUBLE_XVG, EDR_V3_DOUBLE_UNITS, 3),
(EDR_V4, EDR_V4_XVG, EDR_V4_UNITS, 4),
(EDR_V4_DOUBLE, EDR_V4_DOUBLE_XVG, EDR_V4_DOUBLE_UNITS, 4),
(Path(EDR), EDR_XVG, EDR_UNITS, 5),
]
33 changes: 2 additions & 31 deletions pyedr/pyedr/tests/test_edr.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
"""
from collections import namedtuple
import contextlib
from pathlib import Path
import re
import sys
import pickle
Expand All @@ -15,19 +14,7 @@
from numpy.testing import assert_allclose

import pyedr
from pyedr.tests.datafiles import (
EDR, EDR_XVG, EDR_UNITS, EDR_IRREG, EDR_IRREG_XVG,
EDR_IRREG_UNITS, EDR_DOUBLE, EDR_DOUBLE_XVG, EDR_DOUBLE_UNITS,
EDR_BLOCKS, EDR_BLOCKS_XVG, EDR_BLOCKS_UNITS,
EDR_V1, EDR_V1_XVG, EDR_V1_UNITS,
EDR_V1_DOUBLE, EDR_V1_DOUBLE_XVG, EDR_V1_DOUBLE_UNITS,
EDR_V2, EDR_V2_XVG, EDR_V2_UNITS,
EDR_V2_DOUBLE, EDR_V2_DOUBLE_XVG, EDR_V2_DOUBLE_UNITS,
EDR_V3, EDR_V3_XVG, EDR_V3_UNITS,
EDR_V3_DOUBLE, EDR_V3_DOUBLE_XVG, EDR_V3_DOUBLE_UNITS,
EDR_V4, EDR_V4_XVG, EDR_V4_UNITS,
EDR_V4_DOUBLE, EDR_V4_DOUBLE_XVG, EDR_V4_DOUBLE_UNITS
)
from pyedr.tests.datafiles import EDR, EDR_XVG, TESTFILE_PARAMS


# Constants for XVG parsing
Expand Down Expand Up @@ -55,23 +42,7 @@ def check_version_warning(func, edrfile, version):


@pytest.fixture(scope='module',
params=[(EDR, EDR_XVG, EDR_UNITS, 5),
(EDR_IRREG, EDR_IRREG_XVG, EDR_IRREG_UNITS, 5),
(EDR_DOUBLE, EDR_DOUBLE_XVG, EDR_DOUBLE_UNITS, 5),
(EDR_BLOCKS, EDR_BLOCKS_XVG, EDR_BLOCKS_UNITS, 5),
(EDR_V1, EDR_V1_XVG, EDR_V1_UNITS, 1),
(EDR_V1_DOUBLE, EDR_V1_DOUBLE_XVG,
EDR_V1_DOUBLE_UNITS, 1),
(EDR_V2, EDR_V2_XVG, EDR_V2_UNITS, 2),
(EDR_V2_DOUBLE, EDR_V2_DOUBLE_XVG,
EDR_V2_DOUBLE_UNITS, 2),
(EDR_V3, EDR_V3_XVG, EDR_V3_UNITS, 3),
(EDR_V3_DOUBLE, EDR_V3_DOUBLE_XVG,
EDR_V3_DOUBLE_UNITS, 3),
(EDR_V4, EDR_V4_XVG, EDR_V4_UNITS, 4),
(EDR_V4_DOUBLE, EDR_V4_DOUBLE_XVG,
EDR_V4_DOUBLE_UNITS, 4),
(Path(EDR), EDR_XVG, EDR_UNITS, 5), ])
params=TESTFILE_PARAMS)
def edr(request):
edrfile, xvgfile, unitfile, version = request.param
edr_dict = check_version_warning(pyedr.edr_to_dict, edrfile, version)
Expand Down

0 comments on commit 390ca2a

Please sign in to comment.