Skip to content

Commit ae4b516

Browse files
authored
Use tempdir when testing align.AlignTraj (#2534)
1 parent aca26d2 commit ae4b516

File tree

1 file changed

+17
-18
lines changed

1 file changed

+17
-18
lines changed

testsuite/MDAnalysisTests/analysis/test_align.py

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -127,22 +127,22 @@ def test_nomatch_residues_raise_empty(self, universe, reference_small,
127127
with pytest.warns(SelectionWarning):
128128
with pytest.raises(SelectionError):
129129
groups = align.get_matching_atoms(ref, mobile, strict=strict)
130-
130+
131131
def test_toggle_atom_mismatch_default_error(self, universe, reference):
132132
selection = ('resname ALA and name CA', 'resname ALA and name O')
133133
with pytest.raises(SelectionError):
134134
rmsd = align.alignto(universe, reference, select=selection)
135-
135+
136136
def test_toggle_atom_mismatch_kwarg_error(self, universe, reference):
137137
selection = ('resname ALA and name CA', 'resname ALA and name O')
138138
with pytest.raises(SelectionError):
139139
rmsd = align.alignto(universe, reference, select=selection, match_atoms=True)
140-
140+
141141
def test_toggle_atom_nomatch(self, universe, reference):
142142
selection = ('resname ALA and name CA', 'resname ALA and name O')
143143
rmsd = align.alignto(universe, reference, select=selection, match_atoms=False)
144144
assert rmsd[0] > 0.01
145-
145+
146146
def test_toggle_atom_nomatch_mismatch_atoms(self, universe, reference):
147147
# mismatching number of atoms, but same number of residues
148148
u = universe.select_atoms('resname ALA and name CA')
@@ -151,9 +151,6 @@ def test_toggle_atom_nomatch_mismatch_atoms(self, universe, reference):
151151
with pytest.raises(SelectionError):
152152
align.alignto(u, ref, select='all', match_atoms=False)
153153

154-
155-
156-
157154

158155
class TestAlign(object):
159156
@staticmethod
@@ -226,14 +223,16 @@ def test_AlignTraj_outfile_default_exists(self, universe, reference, tmpdir):
226223
fitted = mda.Universe(PSF, outfile)
227224

228225
# ensure default file exists
229-
with mda.Writer(str(tmpdir.join('rmsfit_align_test.dcd')),
226+
with mda.Writer(str(tmpdir.join("rmsfit_align_test.dcd")),
230227
n_atoms=fitted.atoms.n_atoms) as w:
231228
w.write(fitted.atoms)
232229

233-
align.AlignTraj(fitted, reference)
234-
# we are careful now. The default does nothing
235-
with pytest.raises(IOError):
236-
align.AlignTraj(fitted, reference, force=False)
230+
with tempdir.in_tempdir():
231+
align.AlignTraj(fitted, reference)
232+
233+
# we are careful now. The default does nothing
234+
with pytest.raises(IOError):
235+
align.AlignTraj(fitted, reference, force=False)
237236

238237
def test_AlignTraj_step_works(self, universe, reference, tmpdir):
239238
reference.trajectory[-1]
@@ -359,6 +358,7 @@ def test_alignto_partial_universe(self, universe, reference):
359358
assert_array_almost_equal(segB_bound.positions, segB_free.positions,
360359
decimal=3)
361360

361+
362362
def _get_aligned_average_positions(ref_files, ref, select="all", **kwargs):
363363
u = mda.Universe(*ref_files, in_memory=True)
364364
prealigner = align.AlignTraj(u, ref, select=select, **kwargs).run()
@@ -370,7 +370,7 @@ def _get_aligned_average_positions(ref_files, ref, select="all", **kwargs):
370370
class TestAverageStructure(object):
371371

372372
ref_files = (PSF, DCD)
373-
373+
374374
@pytest.fixture
375375
def universe(self):
376376
return mda.Universe(*self.ref_files)
@@ -384,13 +384,13 @@ def test_average_structure(self, universe, reference):
384384
avg = align.AverageStructure(universe, reference).run()
385385
assert_almost_equal(avg.universe.atoms.positions, ref, decimal=4)
386386
assert_almost_equal(avg.rmsd, rmsd)
387-
387+
388388
def test_average_structure_mass_weighted(self, universe, reference):
389389
ref, rmsd = _get_aligned_average_positions(self.ref_files, reference, weights='mass')
390390
avg = align.AverageStructure(universe, reference, weights='mass').run()
391391
assert_almost_equal(avg.universe.atoms.positions, ref, decimal=4)
392392
assert_almost_equal(avg.rmsd, rmsd)
393-
393+
394394
def test_average_structure_select(self, universe, reference):
395395
select = 'protein and name CA and resid 3-5'
396396
ref, rmsd = _get_aligned_average_positions(self.ref_files, reference, select=select)
@@ -403,7 +403,7 @@ def test_average_structure_no_ref(self, universe):
403403
avg = align.AverageStructure(universe).run()
404404
assert_almost_equal(avg.universe.atoms.positions, ref, decimal=4)
405405
assert_almost_equal(avg.rmsd, rmsd)
406-
406+
407407
def test_average_structure_no_msf(self, universe):
408408
avg = align.AverageStructure(universe).run()
409409
assert not hasattr(avg, 'msf')
@@ -412,7 +412,7 @@ def test_mismatch_atoms(self, universe):
412412
u = mda.Merge(universe.atoms[:10])
413413
with pytest.raises(SelectionError):
414414
align.AverageStructure(universe, u)
415-
415+
416416
def test_average_structure_ref_frame(self, universe):
417417
ref_frame = 3
418418
u = mda.Merge(universe.atoms)
@@ -434,7 +434,6 @@ def test_average_structure_in_memory(self, universe):
434434
assert_almost_equal(avg.universe.atoms.positions, reference_coordinates, decimal=4)
435435
assert avg.filename is None
436436

437-
438437

439438
class TestAlignmentProcessing(object):
440439
seq = FASTA

0 commit comments

Comments
 (0)