diff --git a/package/AUTHORS b/package/AUTHORS index 1d7e164679..ce64724bae 100644 --- a/package/AUTHORS +++ b/package/AUTHORS @@ -271,6 +271,7 @@ Chronological list of authors - Mohammad Ayaan - Khushi Phougat - Kushagar Garg + - Jeremy M. G. Leung External code ------------- diff --git a/package/CHANGELOG b/package/CHANGELOG index fec72a9729..010bae54c1 100644 --- a/package/CHANGELOG +++ b/package/CHANGELOG @@ -15,11 +15,12 @@ The rules for this file: ------------------------------------------------------------------------------- ??/??/?? IAlibay, orbeckst, marinegor, tylerjereddy, ljwoods2, marinegor, - spyke7, talagayev, tanii1125, BradyAJohnston, hejamu + spyke7, talagayev, tanii1125, BradyAJohnston, hejamu, jeremyleung521 * 2.11.0 Fixes + * Drop/Replace lock file test in test_xdr (Issue #5236, PR #5237) * HydrogenBondAnalysis: Fixed `count_by_time()` when using `run(FrameIterator)` that results in `self.start` and `self.end` being None (Issue #5200, PR #5202) * NoJump shows a more informative message and fails when applied diff --git a/testsuite/MDAnalysisTests/coordinates/test_xdr.py b/testsuite/MDAnalysisTests/coordinates/test_xdr.py index 2a2f236924..c23fbf47da 100644 --- a/testsuite/MDAnalysisTests/coordinates/test_xdr.py +++ b/testsuite/MDAnalysisTests/coordinates/test_xdr.py @@ -25,10 +25,9 @@ import re import os -import sys import shutil -import subprocess -import time +import sys +from filelock import FileLock from pathlib import Path import numpy as np @@ -59,10 +58,8 @@ ) import MDAnalysis as mda -from MDAnalysis.coordinates.base import Timestep from MDAnalysis.coordinates import XDR from MDAnalysisTests.util import get_userid -from filelock import FileLock @pytest.mark.parametrize( @@ -320,7 +317,7 @@ def test_with_statement(self): with XTCReader(XTC) as trj: N = trj.n_frames frames = [ts.frame for ts in trj] - except: + except Exception: raise AssertionError("with_statement not working for XTCReader") assert_equal( N, @@ -1047,16 +1044,25 @@ def test_persistent_offsets_readonly(self, tmpdir, trajectory): assert_equal(os.path.exists(XDR.offsets_filename(filename)), False) # check the lock file is not created as well. assert_equal( - os.path.exists(XDR.offsets_filename(filename, ending=".lock")), + os.path.exists(XDR.offsets_filename(filename, ending="lock")), False, ) - @pytest.mark.skipif( - sys.platform.startswith("win"), - reason="The lock file only exists when it's locked in windows", - ) - def test_offset_lock_created(self, traj): - assert os.path.exists(XDR.offsets_filename(traj, ending="lock")) + def test_offset_lock_created(self): + lock_file_path = XDR.offsets_filename(self.filename, ending="lock") + + with FileLock(lock_file_path) as lock: + # Lock acquired in context manager, so lock file should exist + assert lock.is_locked + assert os.path.exists(lock_file_path) + + # Explicitly release lock, file should be deleted on UNIX + lock.release() + assert not lock.is_locked + if not sys.platform.startswith("win"): + # As of filelock>=3.21.0, filelock explicitly deletes lockfile + # upon release on UNIX. filelock does not do that on windows. + assert not os.path.exists(lock_file_path) class TestXTCReader_offsets(_GromacsReader_offsets):