Skip to content

Commit

Permalink
Merge pull request #2 from talagayev/talagayev-patch-1_singleframe
Browse files Browse the repository at this point in the history
Adjusted the tests to be in base.py
  • Loading branch information
talagayev authored Apr 15, 2024
2 parents d85defc + 5558dda commit 2953310
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 28 deletions.
21 changes: 21 additions & 0 deletions testsuite/MDAnalysisTests/coordinates/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,14 @@

import numpy as np
import pytest
from pathlib import Path
from unittest import TestCase
from numpy.testing import (assert_equal, assert_almost_equal,
assert_array_almost_equal, assert_allclose)

import MDAnalysis as mda
from MDAnalysis.coordinates.timestep import Timestep
from MDAnalysis.coordinates.memory import MemoryReader
from MDAnalysis.transformations import translate


Expand Down Expand Up @@ -126,6 +128,12 @@ def test_pickle_singleframe_reader(self):
assert_equal(reader.ts, reader_p.ts,
"Single-frame timestep is changed after pickling")

def test_pathlib_input_single(self):
path = Path(self.filename)
u_str = mda.Universe(self.filename)
u_path = mda.Universe(path)
assert u_str.atoms.n_atoms == u_path.atoms.n_atoms


class BaseReference(object):
def __init__(self):
Expand Down Expand Up @@ -521,6 +529,19 @@ def test_timeseries_atomgroup_asel_mutex(self, reader):
atoms = mda.Universe(reader.filename).select_atoms("index 1")
with pytest.raises(ValueError, match="Cannot provide both"):
timeseries = reader.timeseries(atomgroup=atoms, asel=atoms, order='fac')

def test_pathlib_input_base(self, reader):
skip_formats = ["DCD", "TNG", "XTC", "TRR"]
if isinstance(reader, MemoryReader) or reader.format in skip_formats:
if isinstance(reader, MemoryReader):
skip_reason = "MemoryReader"
else:
skip_reason = f"{reader.format} file format"
pytest.skip(f"Skipping test for {skip_reason}")
path = Path(reader.filename)
u_str = mda.Universe(reader.filename)
u_path = mda.Universe(path)
assert u_str.atoms.n_atoms == u_path.atoms.n_atoms


class MultiframeReaderTest(BaseReaderTest):
Expand Down
14 changes: 0 additions & 14 deletions testsuite/MDAnalysisTests/coordinates/test_gro.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
# J. Comput. Chem. 32 (2011), 2319--2327, doi:10.1002/jcc.21787
#
from io import StringIO
from pathlib import Path

import MDAnalysis as mda
import numpy as np
Expand Down Expand Up @@ -529,16 +528,3 @@ def test_gro_empty_box_write_read(tmpdir):
with pytest.warns(UserWarning, match=wmsg):
u2 = mda.Universe('test.gro')
assert u2.dimensions is None


def test_gro_pathlib_singleframereaderbase():
top = Path(GRO)
assert isinstance(top, Path)
u = mda.Universe(top)
assert u.atoms.n_atoms == 47681


def test_gro_string_singleframereaderbase():
assert isinstance(GRO, str)
u = mda.Universe(GRO)
assert u.atoms.n_atoms == 47681
14 changes: 0 additions & 14 deletions testsuite/MDAnalysisTests/coordinates/test_lammps.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
from MDAnalysis import NoDataError

from numpy.testing import (assert_equal, assert_allclose)
from pathlib import Path

from MDAnalysisTests import make_Universe
from MDAnalysisTests.coordinates.reference import (
Expand Down Expand Up @@ -820,16 +819,3 @@ def test_box(self, u_dump, u_data, reference_box):
rtol=1e-5, atol=0)

assert_allclose(u_data.dimensions, reference_box, rtol=1e-5, atol=0)


def test_pathlib_lammps_singleframereaderbase():
top = Path(LAMMPSdata)
assert isinstance(top, Path)
u = mda.Universe(top)
assert u.atoms.n_atoms == 18364


def test_string_lammps_singleframereaderbase():
assert isinstance(LAMMPSdata, str)
u = mda.Universe(LAMMPSdata)
assert u.atoms.n_atoms == 18364

0 comments on commit 2953310

Please sign in to comment.