Skip to content

Commit 900d20b

Browse files
Drop/Replace lock file test in test_xdr (#5237)
- Fixes #5236 - replacement lock file existing test to test_offset_lock_created - add Jeremy Leung to AUTHORS
1 parent 7da5f0a commit 900d20b

3 files changed

Lines changed: 22 additions & 14 deletions

File tree

package/AUTHORS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,7 @@ Chronological list of authors
271271
- Mohammad Ayaan
272272
- Khushi Phougat
273273
- Kushagar Garg
274+
- Jeremy M. G. Leung
274275

275276
External code
276277
-------------

package/CHANGELOG

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,12 @@ The rules for this file:
1515

1616
-------------------------------------------------------------------------------
1717
??/??/?? IAlibay, orbeckst, marinegor, tylerjereddy, ljwoods2, marinegor,
18-
spyke7, talagayev, tanii1125, BradyAJohnston, hejamu
18+
spyke7, talagayev, tanii1125, BradyAJohnston, hejamu, jeremyleung521
1919

2020
* 2.11.0
2121

2222
Fixes
23+
* Drop/Replace lock file test in test_xdr (Issue #5236, PR #5237)
2324
* HydrogenBondAnalysis: Fixed `count_by_time()` when using `run(FrameIterator)` that
2425
results in `self.start` and `self.end` being None (Issue #5200, PR #5202)
2526
* NoJump shows a more informative message and fails when applied

testsuite/MDAnalysisTests/coordinates/test_xdr.py

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,9 @@
2525

2626
import re
2727
import os
28-
import sys
2928
import shutil
30-
import subprocess
31-
import time
29+
import sys
30+
from filelock import FileLock
3231
from pathlib import Path
3332

3433
import numpy as np
@@ -59,10 +58,8 @@
5958
)
6059

6160
import MDAnalysis as mda
62-
from MDAnalysis.coordinates.base import Timestep
6361
from MDAnalysis.coordinates import XDR
6462
from MDAnalysisTests.util import get_userid
65-
from filelock import FileLock
6663

6764

6865
@pytest.mark.parametrize(
@@ -320,7 +317,7 @@ def test_with_statement(self):
320317
with XTCReader(XTC) as trj:
321318
N = trj.n_frames
322319
frames = [ts.frame for ts in trj]
323-
except:
320+
except Exception:
324321
raise AssertionError("with_statement not working for XTCReader")
325322
assert_equal(
326323
N,
@@ -1047,16 +1044,25 @@ def test_persistent_offsets_readonly(self, tmpdir, trajectory):
10471044
assert_equal(os.path.exists(XDR.offsets_filename(filename)), False)
10481045
# check the lock file is not created as well.
10491046
assert_equal(
1050-
os.path.exists(XDR.offsets_filename(filename, ending=".lock")),
1047+
os.path.exists(XDR.offsets_filename(filename, ending="lock")),
10511048
False,
10521049
)
10531050

1054-
@pytest.mark.skipif(
1055-
sys.platform.startswith("win"),
1056-
reason="The lock file only exists when it's locked in windows",
1057-
)
1058-
def test_offset_lock_created(self, traj):
1059-
assert os.path.exists(XDR.offsets_filename(traj, ending="lock"))
1051+
def test_offset_lock_created(self):
1052+
lock_file_path = XDR.offsets_filename(self.filename, ending="lock")
1053+
1054+
with FileLock(lock_file_path) as lock:
1055+
# Lock acquired in context manager, so lock file should exist
1056+
assert lock.is_locked
1057+
assert os.path.exists(lock_file_path)
1058+
1059+
# Explicitly release lock, file should be deleted on UNIX
1060+
lock.release()
1061+
assert not lock.is_locked
1062+
if not sys.platform.startswith("win"):
1063+
# As of filelock>=3.21.0, filelock explicitly deletes lockfile
1064+
# upon release on UNIX. filelock does not do that on windows.
1065+
assert not os.path.exists(lock_file_path)
10601066

10611067

10621068
class TestXTCReader_offsets(_GromacsReader_offsets):

0 commit comments

Comments
 (0)