Skip to content

Commit

Permalink
Merge pull request #133 from dwhswenson/pytest-setup-method
Browse files Browse the repository at this point in the history
tests: `setup`,`teardown` -> `setup_method`, etc
  • Loading branch information
dwhswenson committed Jan 29, 2024
2 parents f276750 + 9932e68 commit d80d300
Show file tree
Hide file tree
Showing 8 changed files with 17 additions and 16 deletions.
6 changes: 3 additions & 3 deletions contact_map/tests/test_concurrence.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def _test_getitem(self, concurrence, pair_to_expected):


class TestAtomContactConcurrence(ContactConcurrenceTester):
def setup(self):
def setup_method(self):
self.concurrence = AtomContactConcurrence(
trajectory=traj,
atom_contacts=contacts.atom_contacts.most_common(),
Expand Down Expand Up @@ -105,7 +105,7 @@ def test_set_labels(self):


class TestResidueContactConcurrence(ContactConcurrenceTester):
def setup(self):
def setup_method(self):
self.heavy_contact_concurrence = ResidueContactConcurrence(
trajectory=traj,
residue_contacts=contacts.residue_contacts.most_common(),
Expand Down Expand Up @@ -157,7 +157,7 @@ def test_getitem(self, conc_type):


class TestConcurrencePlotter(object):
def setup(self):
def setup_method(self):
self.concurrence = ResidueContactConcurrence(
trajectory=traj,
residue_contacts=contacts.residue_contacts.most_common(),
Expand Down
3 changes: 2 additions & 1 deletion contact_map/tests/test_contact_count.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
from contact_map.contact_count import *

class TestContactCount(object):
def setup(self):
def setup_method(self):
self.map = ContactFrequency(traj, cutoff=0.075,
n_neighbors_ignored=0)
self.topology = self.map.topology
Expand Down Expand Up @@ -65,6 +65,7 @@ def test_pixel_warning(self):
with warnings.catch_warnings():
warnings.simplefilter('error')
self.atom_contacts.plot(figsize=(5, 5), dpi=2)
# should convert to error if warning issued

# Now raise the warning as 4*2 < 10
with pytest.warns(RuntimeWarning) as record:
Expand Down
4 changes: 2 additions & 2 deletions contact_map/tests/test_contact_map.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ class TestContactObject(object):
# note: these used to be the tests for the separate single-frame
# ContactMap class; however, it includes a lot of good unit tests for
# ContactObject
def setup(self):
def setup_method(self):
self.topology = traj.topology
self.map0 = ContactFrequency(traj[0], cutoff=0.075,
n_neighbors_ignored=0)
Expand Down Expand Up @@ -336,7 +336,7 @@ def test_no_unitcell(self, idx):


class TestContactFrequency(object):
def setup(self):
def setup_method(self):
self.atoms = [0, 1, 4, 5, 6, 7, 8, 9]
self.map = ContactFrequency(trajectory=traj,
cutoff=0.075,
Expand Down
8 changes: 4 additions & 4 deletions contact_map/tests/test_contact_trajectory.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
]

class TestContactTrajectory(object):
def setup(self):
def setup_method(self):
self.traj = md.load(find_testfile("trajectory.pdb"))
self.map = ContactTrajectory(self.traj, cutoff=0.075,
n_neighbors_ignored=0)
Expand Down Expand Up @@ -175,7 +175,7 @@ def test_rolling_frequency(self):


class TestMutableContactTrajectory(object):
def setup(self):
def setup_method(self):
self.traj = md.load(find_testfile("trajectory.pdb"))
self.map = MutableContactTrajectory(self.traj, cutoff=0.075,
n_neighbors_ignored=0)
Expand Down Expand Up @@ -223,7 +223,7 @@ def test_hash_eq(self):


class TestWindowedIterator(object):
def setup(self):
def setup_method(self):
self.iter = WindowedIterator(length=10, width=3, step=2,
slow_build=False)

Expand Down Expand Up @@ -286,7 +286,7 @@ def test_next(self, length, width, step, slow_build, expected):


class TestRollingContactFrequency(object):
def setup(self):
def setup_method(self):
self.traj = md.load(find_testfile("trajectory.pdb"))
self.map = ContactTrajectory(self.traj, cutoff=0.075,
n_neighbors_ignored=0)
Expand Down
4 changes: 2 additions & 2 deletions contact_map/tests/test_dask_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def dask_setup_test_cluster(distributed, n_workers=4, n_attempts=3):


class TestDaskRunners(object):
def setup(self):
def setup_method(self):
dask = pytest.importorskip('dask') # pylint: disable=W0612
distributed = pytest.importorskip('dask.distributed')
self.distributed = distributed
Expand All @@ -39,7 +39,7 @@ def setup(self):
self.client = distributed.Client(self.cluster)
self.filename = find_testfile("trajectory.pdb")

def teardown(self):
def teardown_method(self):
self.client.shutdown()

@pytest.mark.parametrize("dask_cls", [DaskContactFrequency,
Expand Down
2 changes: 1 addition & 1 deletion contact_map/tests/test_frequency_task.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def test_default_slice_even_split(self, inputs, results):
assert default_slices(n_total, n_workers) == results

class TestTasks(object):
def setup(self):
def setup_method(self):
self.contact_freq_0_4 = ContactFrequency(traj[:4], cutoff=0.075,
n_neighbors_ignored=0)
self.contact_freq_4 = ContactFrequency(traj[4], cutoff=0.075,
Expand Down
4 changes: 2 additions & 2 deletions contact_map/tests/test_min_dist.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

@pytest.mark.parametrize("idx", [0, 4])
class TestNearestAtoms(object):
def setup(self):
def setup_method(self):
self.nearest_atoms = {
idx: NearestAtoms(traj, cutoff=0.075, frame_number=idx)
for idx in [0, 4]
Expand Down Expand Up @@ -107,7 +107,7 @@ def test_sorted_distances(self, idx):


class TestMinimumDistanceCounter(object):
def setup(self):
def setup_method(self):
self.topology = traj.topology
query = [4, 5]
haystack = list(set(range(10)) - set(query))
Expand Down
2 changes: 1 addition & 1 deletion contact_map/tests/test_plot_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def test_is_cmap_diverging(cmap):


class TestContactRange(object):
def setup(self):
def setup_method(self):
self.cr = _ContactPlotRange(5)

@pytest.mark.parametrize("case", [(_ContactPlotRange(5), True),
Expand Down

0 comments on commit d80d300

Please sign in to comment.