From 0d022180bf0fbdf4939668196d1f25b9fede6d16 Mon Sep 17 00:00:00 2001 From: Valerij Talagayev <82884038+talagayev@users.noreply.github.com> Date: Sat, 23 Nov 2024 00:30:13 +0100 Subject: [PATCH 01/49] Update pyproject.toml changes fasteners to filelock dependency --- package/pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package/pyproject.toml b/package/pyproject.toml index 4dc2275df4..52275513d4 100644 --- a/package/pyproject.toml +++ b/package/pyproject.toml @@ -38,7 +38,7 @@ dependencies = [ 'tqdm>=4.43.0', 'threadpoolctl', 'packaging', - 'fasteners', + 'filelock', 'mda-xdrlib', 'waterdynamics', 'pathsimanalysis', From 833f58beb007f5a90f8a56e4368d30191d6e2342 Mon Sep 17 00:00:00 2001 From: Valerij Talagayev <82884038+talagayev@users.noreply.github.com> Date: Sat, 23 Nov 2024 00:30:52 +0100 Subject: [PATCH 02/49] Update requirements.txt changes fasteners to filelock dependency --- package/requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package/requirements.txt b/package/requirements.txt index accac1b49f..a196a9fe0f 100644 --- a/package/requirements.txt +++ b/package/requirements.txt @@ -1,7 +1,7 @@ biopython>=1.80 codecov cython -fasteners +filelock griddataformats gsd hypothesis From 0e45f80a8840db83896a386e6cc950d472178ae9 Mon Sep 17 00:00:00 2001 From: Valerij Talagayev <82884038+talagayev@users.noreply.github.com> Date: Sat, 23 Nov 2024 00:32:47 +0100 Subject: [PATCH 03/49] Update action.yaml changes in the action the fasteners dependency to filelock --- .github/actions/setup-deps/action.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/actions/setup-deps/action.yaml b/.github/actions/setup-deps/action.yaml index cbfd91df7e..3e34d24870 100644 --- a/.github/actions/setup-deps/action.yaml +++ b/.github/actions/setup-deps/action.yaml @@ -21,8 +21,8 @@ inputs: default: 'codecov' cython: default: 'cython' - fasteners: - default: 'fasteners' + filelock: + default: 'filelock' griddataformats: default: 'griddataformats' gsd: From 0505cc5ed34445874be308a0891a02e97b659ca5 Mon Sep 17 00:00:00 2001 From: Valerij Talagayev <82884038+talagayev@users.noreply.github.com> Date: Sat, 23 Nov 2024 00:33:32 +0100 Subject: [PATCH 04/49] Update action.yaml adjusted input fasteners to filelock --- .github/actions/setup-deps/action.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/actions/setup-deps/action.yaml b/.github/actions/setup-deps/action.yaml index 3e34d24870..91dd56b6d7 100644 --- a/.github/actions/setup-deps/action.yaml +++ b/.github/actions/setup-deps/action.yaml @@ -110,7 +110,7 @@ runs: CONDA_MIN_DEPS: | ${{ inputs.codecov }} ${{ inputs.cython }} - ${{ inputs.fasteners }} + ${{ inputs.filelock }} ${{ inputs.griddataformats }} ${{ inputs.hypothesis }} ${{ inputs.matplotlib }} From ea5a61c9e19d8bb804076a20ca29869577b6f25f Mon Sep 17 00:00:00 2001 From: Valerij Talagayev <82884038+talagayev@users.noreply.github.com> Date: Sat, 23 Nov 2024 00:37:47 +0100 Subject: [PATCH 05/49] Update environment.yml changed fasteners to filelock --- maintainer/conda/environment.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/maintainer/conda/environment.yml b/maintainer/conda/environment.yml index cd324d25cd..3ceeeadb2d 100644 --- a/maintainer/conda/environment.yml +++ b/maintainer/conda/environment.yml @@ -7,7 +7,7 @@ dependencies: - codecov - cython - docutils - - fasteners + - filelock - griddataformats - gsd - h5py>=2.10 From 40251b68325e9f6b83fb0be7f2adf626dc3609a5 Mon Sep 17 00:00:00 2001 From: Valerij Talagayev <82884038+talagayev@users.noreply.github.com> Date: Sat, 23 Nov 2024 00:38:13 +0100 Subject: [PATCH 06/49] Update azure-pipelines.yml changed fasteners to filelock --- azure-pipelines.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/azure-pipelines.yml b/azure-pipelines.yml index 27b1c0db3f..20a32d103e 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -90,7 +90,7 @@ jobs: scikit-learn tqdm threadpoolctl - fasteners + filelock displayName: 'Install dependencies' # for wheel install testing, we pin to an # older NumPy, the oldest version we support and that From c98a11fd706b615bd7987e1214f7dd52232c0dc1 Mon Sep 17 00:00:00 2001 From: Valerij Talagayev <82884038+talagayev@users.noreply.github.com> Date: Sat, 23 Nov 2024 00:41:25 +0100 Subject: [PATCH 07/49] Update XDR.py changed fasteners to filelock --- package/MDAnalysis/coordinates/XDR.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/package/MDAnalysis/coordinates/XDR.py b/package/MDAnalysis/coordinates/XDR.py index 6fe75982cc..0596241533 100644 --- a/package/MDAnalysis/coordinates/XDR.py +++ b/package/MDAnalysis/coordinates/XDR.py @@ -38,7 +38,7 @@ import numpy as np from os.path import getctime, getsize, isfile, split, join import warnings -import fasteners +from filelock import FileLock from . import base from ..lib.mdamath import triclinic_box @@ -121,6 +121,8 @@ class XDRBaseReader(base.ReaderBase): Add a InterProcessLock when generating offsets .. versionchanged:: 2.4.0 Use a direct read into ts attributes + .. versionchanged:: 2.9.0 + Changed fasteners.InterProcessLock() to filelock.FileLock """ @store_init_arguments def __init__(self, filename, convert_units=True, sub=None, @@ -195,7 +197,7 @@ def _load_offsets(self): # check if the location of the lock is writable. try: - with fasteners.InterProcessLock(lock_name) as filelock: + with FileLock(lock_name) as filelock: pass except OSError as e: if isinstance(e, PermissionError) or e.errno == errno.EROFS: @@ -206,7 +208,7 @@ def _load_offsets(self): else: raise - with fasteners.InterProcessLock(lock_name) as filelock: + with FileLock(lock_name) as filelock: if not isfile(fname): self._read_offsets(store=True) return From 97927bb681d6a41cbeec272eb884a9c3591a16dc Mon Sep 17 00:00:00 2001 From: Valerij Talagayev <82884038+talagayev@users.noreply.github.com> Date: Sat, 23 Nov 2024 01:49:31 +0100 Subject: [PATCH 08/49] Update XDR.py test _read_offsets adjustment --- package/MDAnalysis/coordinates/XDR.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/package/MDAnalysis/coordinates/XDR.py b/package/MDAnalysis/coordinates/XDR.py index 0596241533..dbdfe68ab6 100644 --- a/package/MDAnalysis/coordinates/XDR.py +++ b/package/MDAnalysis/coordinates/XDR.py @@ -201,9 +201,7 @@ def _load_offsets(self): pass except OSError as e: if isinstance(e, PermissionError) or e.errno == errno.EROFS: - warnings.warn(f"Cannot write lock/offset file in same location as " - f"{self.filename}. Using slow offset calculation.") - self._read_offsets(store=True) + self._read_offsets(store=False) return else: raise From f8f05f29afbf0f14e8b08b5ee36ae89c9328b93f Mon Sep 17 00:00:00 2001 From: Valerij Talagayev <82884038+talagayev@users.noreply.github.com> Date: Sat, 23 Nov 2024 02:08:41 +0100 Subject: [PATCH 09/49] Update test_xdr.py modification of test_offset_lock_created to adjust to new dependency --- testsuite/MDAnalysisTests/coordinates/test_xdr.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/testsuite/MDAnalysisTests/coordinates/test_xdr.py b/testsuite/MDAnalysisTests/coordinates/test_xdr.py index efb15d7825..f3277b6174 100644 --- a/testsuite/MDAnalysisTests/coordinates/test_xdr.py +++ b/testsuite/MDAnalysisTests/coordinates/test_xdr.py @@ -923,8 +923,7 @@ def test_persistent_offsets_readonly(self, tmpdir): shutil.rmtree(tmpdir) def test_offset_lock_created(self): - assert os.path.exists(XDR.offsets_filename(self.filename, - ending='lock')) + assert os.path.exists(XDR.offsets_filename(self.filename)) class TestXTCReader_offsets(_GromacsReader_offsets): From 3cd7307878899d39bb4fdc03b3b76c98fd3091ba Mon Sep 17 00:00:00 2001 From: Valerij Talagayev <82884038+talagayev@users.noreply.github.com> Date: Sat, 23 Nov 2024 02:48:55 +0100 Subject: [PATCH 10/49] Update XDR.py returned the warning and read_offsets for tests --- package/MDAnalysis/coordinates/XDR.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/package/MDAnalysis/coordinates/XDR.py b/package/MDAnalysis/coordinates/XDR.py index dbdfe68ab6..0596241533 100644 --- a/package/MDAnalysis/coordinates/XDR.py +++ b/package/MDAnalysis/coordinates/XDR.py @@ -201,7 +201,9 @@ def _load_offsets(self): pass except OSError as e: if isinstance(e, PermissionError) or e.errno == errno.EROFS: - self._read_offsets(store=False) + warnings.warn(f"Cannot write lock/offset file in same location as " + f"{self.filename}. Using slow offset calculation.") + self._read_offsets(store=True) return else: raise From b66e3d21680909f4b4a15379d77602090f879fd0 Mon Sep 17 00:00:00 2001 From: Valerij Talagayev <82884038+talagayev@users.noreply.github.com> Date: Sat, 23 Nov 2024 03:28:00 +0100 Subject: [PATCH 11/49] Update test_xdr.py required removal of asser_equal to not get the error, since now the files, dont't end with lock and the removal of the end would be a duplicate of the other assert_equal --- testsuite/MDAnalysisTests/coordinates/test_xdr.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/testsuite/MDAnalysisTests/coordinates/test_xdr.py b/testsuite/MDAnalysisTests/coordinates/test_xdr.py index f3277b6174..908c9be9a8 100644 --- a/testsuite/MDAnalysisTests/coordinates/test_xdr.py +++ b/testsuite/MDAnalysisTests/coordinates/test_xdr.py @@ -907,9 +907,6 @@ def test_persistent_offsets_readonly(self, tmpdir): pytest.warns(UserWarning, match="Cannot write")): self._reader(filename) 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')), False) # pre-teardown permission fix - leaving permission blocked dir # is problematic on py3.9 + Windows it seems. See issue From e71943f64fa3fafe9029d39b6d2a7f7101c2e649 Mon Sep 17 00:00:00 2001 From: Valerij Talagayev <82884038+talagayev@users.noreply.github.com> Date: Tue, 26 Nov 2024 13:04:06 +0100 Subject: [PATCH 12/49] Update XDR.py changed read offsets from True to False, retained the warning --- package/MDAnalysis/coordinates/XDR.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package/MDAnalysis/coordinates/XDR.py b/package/MDAnalysis/coordinates/XDR.py index 0596241533..bf036e34e5 100644 --- a/package/MDAnalysis/coordinates/XDR.py +++ b/package/MDAnalysis/coordinates/XDR.py @@ -203,7 +203,7 @@ def _load_offsets(self): if isinstance(e, PermissionError) or e.errno == errno.EROFS: warnings.warn(f"Cannot write lock/offset file in same location as " f"{self.filename}. Using slow offset calculation.") - self._read_offsets(store=True) + self._read_offsets(store=False) return else: raise From ce3656a0ccfe8e70bcffc61acc14e70498bc1b94 Mon Sep 17 00:00:00 2001 From: Valerij Talagayev <82884038+talagayev@users.noreply.github.com> Date: Tue, 26 Nov 2024 13:51:09 +0100 Subject: [PATCH 13/49] Update test_xdr.py changed and to or pytest warning in test --- testsuite/MDAnalysisTests/coordinates/test_xdr.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/testsuite/MDAnalysisTests/coordinates/test_xdr.py b/testsuite/MDAnalysisTests/coordinates/test_xdr.py index 908c9be9a8..6f768cd6e1 100644 --- a/testsuite/MDAnalysisTests/coordinates/test_xdr.py +++ b/testsuite/MDAnalysisTests/coordinates/test_xdr.py @@ -903,7 +903,7 @@ def test_persistent_offsets_readonly(self, tmpdir): filename = str(tmpdir.join(os.path.basename(self.filename))) # try to write a offsets file - with (pytest.warns(UserWarning, match="Couldn't save offsets") and + with (pytest.warns(UserWarning, match="Couldn't save offsets") or pytest.warns(UserWarning, match="Cannot write")): self._reader(filename) assert_equal(os.path.exists(XDR.offsets_filename(filename)), False) From 307027b3fbc4dfcca5f3269c5ce8a3e6fcb96812 Mon Sep 17 00:00:00 2001 From: Valerij Talagayev <82884038+talagayev@users.noreply.github.com> Date: Sun, 8 Dec 2024 20:02:37 +0100 Subject: [PATCH 14/49] Update test_xdr.py test path --- testsuite/MDAnalysisTests/coordinates/test_xdr.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/testsuite/MDAnalysisTests/coordinates/test_xdr.py b/testsuite/MDAnalysisTests/coordinates/test_xdr.py index 6f768cd6e1..dfec4a9582 100644 --- a/testsuite/MDAnalysisTests/coordinates/test_xdr.py +++ b/testsuite/MDAnalysisTests/coordinates/test_xdr.py @@ -892,7 +892,9 @@ def test_unsupported_format(self, traj): @pytest.mark.skipif(get_userid() == 0, reason="cannot readonly as root") def test_persistent_offsets_readonly(self, tmpdir): - shutil.copy(self.filename, str(tmpdir)) + test_file = Path(self.filename) + tmp_path = Path(tmpdir) + shutil.copy(test_file, tmp_path) if os.name == 'nt': # Windows platform has a unique way to deny write access From 77abba0a53236294d6ddf6a5104a4c235511867b Mon Sep 17 00:00:00 2001 From: Valerij Talagayev <82884038+talagayev@users.noreply.github.com> Date: Sun, 8 Dec 2024 22:39:58 +0100 Subject: [PATCH 15/49] Update test_xdr.py test path modification --- testsuite/MDAnalysisTests/coordinates/test_xdr.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/testsuite/MDAnalysisTests/coordinates/test_xdr.py b/testsuite/MDAnalysisTests/coordinates/test_xdr.py index dfec4a9582..5de0447eb9 100644 --- a/testsuite/MDAnalysisTests/coordinates/test_xdr.py +++ b/testsuite/MDAnalysisTests/coordinates/test_xdr.py @@ -893,7 +893,7 @@ def test_unsupported_format(self, traj): @pytest.mark.skipif(get_userid() == 0, reason="cannot readonly as root") def test_persistent_offsets_readonly(self, tmpdir): test_file = Path(self.filename) - tmp_path = Path(tmpdir) + tmp_path = str(tmpdir) shutil.copy(test_file, tmp_path) if os.name == 'nt': From fc52a18b8037c6afe26b9cf03c54bc0d84148b86 Mon Sep 17 00:00:00 2001 From: Valerij Talagayev <82884038+talagayev@users.noreply.github.com> Date: Sun, 8 Dec 2024 23:08:43 +0100 Subject: [PATCH 16/49] Update test_xdr.py moved back --- testsuite/MDAnalysisTests/coordinates/test_xdr.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/testsuite/MDAnalysisTests/coordinates/test_xdr.py b/testsuite/MDAnalysisTests/coordinates/test_xdr.py index 5de0447eb9..6f768cd6e1 100644 --- a/testsuite/MDAnalysisTests/coordinates/test_xdr.py +++ b/testsuite/MDAnalysisTests/coordinates/test_xdr.py @@ -892,9 +892,7 @@ def test_unsupported_format(self, traj): @pytest.mark.skipif(get_userid() == 0, reason="cannot readonly as root") def test_persistent_offsets_readonly(self, tmpdir): - test_file = Path(self.filename) - tmp_path = str(tmpdir) - shutil.copy(test_file, tmp_path) + shutil.copy(self.filename, str(tmpdir)) if os.name == 'nt': # Windows platform has a unique way to deny write access From e1fe6fb6e71154ed85bbded6b766e0768ece97b6 Mon Sep 17 00:00:00 2001 From: Valerij Talagayev <82884038+talagayev@users.noreply.github.com> Date: Sun, 8 Dec 2024 23:11:55 +0100 Subject: [PATCH 17/49] Update test_xdr.py add skip exception for azure --- testsuite/MDAnalysisTests/coordinates/test_xdr.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/testsuite/MDAnalysisTests/coordinates/test_xdr.py b/testsuite/MDAnalysisTests/coordinates/test_xdr.py index 6f768cd6e1..8de2f5de12 100644 --- a/testsuite/MDAnalysisTests/coordinates/test_xdr.py +++ b/testsuite/MDAnalysisTests/coordinates/test_xdr.py @@ -891,6 +891,10 @@ def test_unsupported_format(self, traj): reader[idx_frame] @pytest.mark.skipif(get_userid() == 0, reason="cannot readonly as root") + @pytest.mark.skipif( + os.name == 'nt' and "AGENT_NAME" in os.environ, + reason="Windows Azure CI environment does not support directory locking or permission modification" + ) def test_persistent_offsets_readonly(self, tmpdir): shutil.copy(self.filename, str(tmpdir)) From fbcd0603f0d20ffdedcf6039b45f99c467a07ad5 Mon Sep 17 00:00:00 2001 From: Valerij Talagayev <82884038+talagayev@users.noreply.github.com> Date: Sun, 8 Dec 2024 23:43:42 +0100 Subject: [PATCH 18/49] Update test_xdr.py --- testsuite/MDAnalysisTests/coordinates/test_xdr.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/testsuite/MDAnalysisTests/coordinates/test_xdr.py b/testsuite/MDAnalysisTests/coordinates/test_xdr.py index 8de2f5de12..2f0a183815 100644 --- a/testsuite/MDAnalysisTests/coordinates/test_xdr.py +++ b/testsuite/MDAnalysisTests/coordinates/test_xdr.py @@ -893,8 +893,10 @@ def test_unsupported_format(self, traj): @pytest.mark.skipif(get_userid() == 0, reason="cannot readonly as root") @pytest.mark.skipif( os.name == 'nt' and "AGENT_NAME" in os.environ, - reason="Windows Azure CI environment does not support directory locking or permission modification" + reason="Windows Azure CI environment does not support + directory locking or permission modification" ) + def test_persistent_offsets_readonly(self, tmpdir): shutil.copy(self.filename, str(tmpdir)) From 9c2ed873ce4383b0b32de6cbac34a75479c5347f Mon Sep 17 00:00:00 2001 From: Valerij Talagayev <82884038+talagayev@users.noreply.github.com> Date: Sun, 8 Dec 2024 23:44:26 +0100 Subject: [PATCH 19/49] Update test_xdr.py --- testsuite/MDAnalysisTests/coordinates/test_xdr.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/testsuite/MDAnalysisTests/coordinates/test_xdr.py b/testsuite/MDAnalysisTests/coordinates/test_xdr.py index 2f0a183815..abedbfc2c3 100644 --- a/testsuite/MDAnalysisTests/coordinates/test_xdr.py +++ b/testsuite/MDAnalysisTests/coordinates/test_xdr.py @@ -893,9 +893,9 @@ def test_unsupported_format(self, traj): @pytest.mark.skipif(get_userid() == 0, reason="cannot readonly as root") @pytest.mark.skipif( os.name == 'nt' and "AGENT_NAME" in os.environ, - reason="Windows Azure CI environment does not support + reason="Windows Azure CI environment does not support directory locking or permission modification" - ) + ) def test_persistent_offsets_readonly(self, tmpdir): shutil.copy(self.filename, str(tmpdir)) From 2d3cf13e601780efd7a0e1bc289cad9a5e5e3143 Mon Sep 17 00:00:00 2001 From: Valerij Talagayev <82884038+talagayev@users.noreply.github.com> Date: Sun, 8 Dec 2024 23:44:40 +0100 Subject: [PATCH 20/49] Update test_xdr.py --- testsuite/MDAnalysisTests/coordinates/test_xdr.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/testsuite/MDAnalysisTests/coordinates/test_xdr.py b/testsuite/MDAnalysisTests/coordinates/test_xdr.py index abedbfc2c3..619a840061 100644 --- a/testsuite/MDAnalysisTests/coordinates/test_xdr.py +++ b/testsuite/MDAnalysisTests/coordinates/test_xdr.py @@ -896,7 +896,7 @@ def test_unsupported_format(self, traj): reason="Windows Azure CI environment does not support directory locking or permission modification" ) - + def test_persistent_offsets_readonly(self, tmpdir): shutil.copy(self.filename, str(tmpdir)) From 78b61e9c2d1152bb2497bfd54b974916ae595910 Mon Sep 17 00:00:00 2001 From: Valerij Talagayev <82884038+talagayev@users.noreply.github.com> Date: Mon, 9 Dec 2024 00:01:36 +0100 Subject: [PATCH 21/49] Update test_xdr.py --- testsuite/MDAnalysisTests/coordinates/test_xdr.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/testsuite/MDAnalysisTests/coordinates/test_xdr.py b/testsuite/MDAnalysisTests/coordinates/test_xdr.py index 619a840061..82543931d2 100644 --- a/testsuite/MDAnalysisTests/coordinates/test_xdr.py +++ b/testsuite/MDAnalysisTests/coordinates/test_xdr.py @@ -893,8 +893,7 @@ def test_unsupported_format(self, traj): @pytest.mark.skipif(get_userid() == 0, reason="cannot readonly as root") @pytest.mark.skipif( os.name == 'nt' and "AGENT_NAME" in os.environ, - reason="Windows Azure CI environment does not support - directory locking or permission modification" + reason="Windows Azure CI does not support locking or permission modification" ) def test_persistent_offsets_readonly(self, tmpdir): From 30e45616f84e953964c712d1d3676d5be4561dfa Mon Sep 17 00:00:00 2001 From: Valerij Talagayev <82884038+talagayev@users.noreply.github.com> Date: Mon, 9 Dec 2024 00:02:07 +0100 Subject: [PATCH 22/49] Update test_xdr.py --- testsuite/MDAnalysisTests/coordinates/test_xdr.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/testsuite/MDAnalysisTests/coordinates/test_xdr.py b/testsuite/MDAnalysisTests/coordinates/test_xdr.py index 82543931d2..b74f214dd7 100644 --- a/testsuite/MDAnalysisTests/coordinates/test_xdr.py +++ b/testsuite/MDAnalysisTests/coordinates/test_xdr.py @@ -893,7 +893,7 @@ def test_unsupported_format(self, traj): @pytest.mark.skipif(get_userid() == 0, reason="cannot readonly as root") @pytest.mark.skipif( os.name == 'nt' and "AGENT_NAME" in os.environ, - reason="Windows Azure CI does not support locking or permission modification" + reason="Windows Azure does not support locking or permission modification" ) def test_persistent_offsets_readonly(self, tmpdir): From 947966c5f2fd2536f5c68d3d9a57e4bb56275d9f Mon Sep 17 00:00:00 2001 From: Valerij Talagayev <82884038+talagayev@users.noreply.github.com> Date: Mon, 9 Dec 2024 00:02:57 +0100 Subject: [PATCH 23/49] Update test_xdr.py --- testsuite/MDAnalysisTests/coordinates/test_xdr.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/testsuite/MDAnalysisTests/coordinates/test_xdr.py b/testsuite/MDAnalysisTests/coordinates/test_xdr.py index b74f214dd7..597ad6378b 100644 --- a/testsuite/MDAnalysisTests/coordinates/test_xdr.py +++ b/testsuite/MDAnalysisTests/coordinates/test_xdr.py @@ -893,7 +893,7 @@ def test_unsupported_format(self, traj): @pytest.mark.skipif(get_userid() == 0, reason="cannot readonly as root") @pytest.mark.skipif( os.name == 'nt' and "AGENT_NAME" in os.environ, - reason="Windows Azure does not support locking or permission modification" + reason="Windows Azure does not support locking/permission modification" ) def test_persistent_offsets_readonly(self, tmpdir): From 33c0ea4e26b175a2df8ab9b95ea88f926b677c5e Mon Sep 17 00:00:00 2001 From: Valerij Talagayev <82884038+talagayev@users.noreply.github.com> Date: Thu, 12 Dec 2024 23:30:25 +0100 Subject: [PATCH 24/49] Update CHANGELOG added change of fasteners to filelock --- package/CHANGELOG | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/package/CHANGELOG b/package/CHANGELOG index 83bff74002..c1c686fb82 100644 --- a/package/CHANGELOG +++ b/package/CHANGELOG @@ -14,7 +14,7 @@ The rules for this file: ------------------------------------------------------------------------------- -??/??/?? IAlibay, ChiahsinChu, RMeli +??/??/?? IAlibay, ChiahsinChu, RMeli, talagayev * 2.9.0 @@ -25,6 +25,7 @@ Enhancements * Added `precision` for XYZWriter (Issue #4775, PR #4771) Changes + * Changed `fasteners` dependency to `filelock` (Issue #4797, PR #4800) Deprecations From 16132f269d98e46d642586af592bd9fb19c4038b Mon Sep 17 00:00:00 2001 From: Valerij Talagayev <82884038+talagayev@users.noreply.github.com> Date: Tue, 17 Dec 2024 21:59:35 +0100 Subject: [PATCH 25/49] Update test_xdr.py --- testsuite/MDAnalysisTests/coordinates/test_xdr.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/testsuite/MDAnalysisTests/coordinates/test_xdr.py b/testsuite/MDAnalysisTests/coordinates/test_xdr.py index 597ad6378b..45a196848a 100644 --- a/testsuite/MDAnalysisTests/coordinates/test_xdr.py +++ b/testsuite/MDAnalysisTests/coordinates/test_xdr.py @@ -908,7 +908,7 @@ def test_persistent_offsets_readonly(self, tmpdir): filename = str(tmpdir.join(os.path.basename(self.filename))) # try to write a offsets file - with (pytest.warns(UserWarning, match="Couldn't save offsets") or + with (pytest.warns(UserWarning, match="Couldn't save offsets") and pytest.warns(UserWarning, match="Cannot write")): self._reader(filename) assert_equal(os.path.exists(XDR.offsets_filename(filename)), False) From b100232ec52eedb92b4dce940e6f0ce8d8b69fcb Mon Sep 17 00:00:00 2001 From: Valerij Talagayev <82884038+talagayev@users.noreply.github.com> Date: Tue, 17 Dec 2024 22:36:09 +0100 Subject: [PATCH 26/49] Update test_xdr.py test this option to see if only this appears, locally both worked and/or --- testsuite/MDAnalysisTests/coordinates/test_xdr.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/testsuite/MDAnalysisTests/coordinates/test_xdr.py b/testsuite/MDAnalysisTests/coordinates/test_xdr.py index 45a196848a..e66593dc21 100644 --- a/testsuite/MDAnalysisTests/coordinates/test_xdr.py +++ b/testsuite/MDAnalysisTests/coordinates/test_xdr.py @@ -908,8 +908,7 @@ def test_persistent_offsets_readonly(self, tmpdir): filename = str(tmpdir.join(os.path.basename(self.filename))) # try to write a offsets file - with (pytest.warns(UserWarning, match="Couldn't save offsets") and - pytest.warns(UserWarning, match="Cannot write")): + with (pytest.warns(UserWarning, match="Cannot write"): self._reader(filename) assert_equal(os.path.exists(XDR.offsets_filename(filename)), False) From 8de3f27f0b6e597bda682ba54225650e46cb8950 Mon Sep 17 00:00:00 2001 From: Valerij Talagayev <82884038+talagayev@users.noreply.github.com> Date: Tue, 17 Dec 2024 23:06:21 +0100 Subject: [PATCH 27/49] Update test_xdr.py syntax error fix --- testsuite/MDAnalysisTests/coordinates/test_xdr.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/testsuite/MDAnalysisTests/coordinates/test_xdr.py b/testsuite/MDAnalysisTests/coordinates/test_xdr.py index e66593dc21..5ba95e8a90 100644 --- a/testsuite/MDAnalysisTests/coordinates/test_xdr.py +++ b/testsuite/MDAnalysisTests/coordinates/test_xdr.py @@ -908,7 +908,7 @@ def test_persistent_offsets_readonly(self, tmpdir): filename = str(tmpdir.join(os.path.basename(self.filename))) # try to write a offsets file - with (pytest.warns(UserWarning, match="Cannot write"): + with pytest.warns(UserWarning, match="Cannot write"): self._reader(filename) assert_equal(os.path.exists(XDR.offsets_filename(filename)), False) From 8ca889343c9b88f042c833abbceb290450ce80fc Mon Sep 17 00:00:00 2001 From: Valerij Talagayev <82884038+talagayev@users.noreply.github.com> Date: Wed, 18 Dec 2024 01:01:26 +0100 Subject: [PATCH 28/49] Update test_xdr.py added comment due to change --- testsuite/MDAnalysisTests/coordinates/test_xdr.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/testsuite/MDAnalysisTests/coordinates/test_xdr.py b/testsuite/MDAnalysisTests/coordinates/test_xdr.py index 5ba95e8a90..bb929206f2 100644 --- a/testsuite/MDAnalysisTests/coordinates/test_xdr.py +++ b/testsuite/MDAnalysisTests/coordinates/test_xdr.py @@ -907,7 +907,7 @@ def test_persistent_offsets_readonly(self, tmpdir): os.chmod(str(tmpdir), 0o555) filename = str(tmpdir.join(os.path.basename(self.filename))) - # try to write a offsets file + # try to write a offsets file, obtain Cannot write due to FileLock with pytest.warns(UserWarning, match="Cannot write"): self._reader(filename) assert_equal(os.path.exists(XDR.offsets_filename(filename)), False) From 86c3db2148e2a71d333a709d3434276d2af65a62 Mon Sep 17 00:00:00 2001 From: Valerij Talagayev <82884038+talagayev@users.noreply.github.com> Date: Thu, 19 Dec 2024 16:35:31 +0100 Subject: [PATCH 29/49] Update test_xdr.py --- testsuite/MDAnalysisTests/coordinates/test_xdr.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/testsuite/MDAnalysisTests/coordinates/test_xdr.py b/testsuite/MDAnalysisTests/coordinates/test_xdr.py index bb929206f2..956e8db782 100644 --- a/testsuite/MDAnalysisTests/coordinates/test_xdr.py +++ b/testsuite/MDAnalysisTests/coordinates/test_xdr.py @@ -891,6 +891,7 @@ def test_unsupported_format(self, traj): reader[idx_frame] @pytest.mark.skipif(get_userid() == 0, reason="cannot readonly as root") + # skip test in Windows Azure, due to different permission in Azure @pytest.mark.skipif( os.name == 'nt' and "AGENT_NAME" in os.environ, reason="Windows Azure does not support locking/permission modification" @@ -924,6 +925,7 @@ def test_persistent_offsets_readonly(self, tmpdir): shutil.rmtree(tmpdir) def test_offset_lock_created(self): + # File is created, but without .lock ending assert os.path.exists(XDR.offsets_filename(self.filename)) From c1436b9ac5e07ba8ff9dba17327a81cfafecd506 Mon Sep 17 00:00:00 2001 From: Valerij Talagayev <82884038+talagayev@users.noreply.github.com> Date: Fri, 20 Dec 2024 23:46:36 +0100 Subject: [PATCH 30/49] Update test_xdr.py test if it works --- .../MDAnalysisTests/coordinates/test_xdr.py | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/testsuite/MDAnalysisTests/coordinates/test_xdr.py b/testsuite/MDAnalysisTests/coordinates/test_xdr.py index 956e8db782..3215d618a0 100644 --- a/testsuite/MDAnalysisTests/coordinates/test_xdr.py +++ b/testsuite/MDAnalysisTests/coordinates/test_xdr.py @@ -909,9 +909,22 @@ def test_persistent_offsets_readonly(self, tmpdir): filename = str(tmpdir.join(os.path.basename(self.filename))) # try to write a offsets file, obtain Cannot write due to FileLock - with pytest.warns(UserWarning, match="Cannot write"): - self._reader(filename) - assert_equal(os.path.exists(XDR.offsets_filename(filename)), False) + ref_offset = XDR.read_numpy_offsets(self.filename) # Assuming this is the reference you want to use + # Mock np.load to raise an error when trying to load offsets + with patch.object(np, "load") as np_load_mock: + np_load_mock.side_effect = ValueError # Simulate failure in loading offsets + + # Use pytest.warns to check for the expected warnings when loading offsets fails + with pytest.warns(UserWarning, match="Failed to load offsets"): + # Now using the XDR.read_numpy_offsets method to read the offsets + saved_offsets = XDR.read_numpy_offsets(filename) + + # Check if the offsets are handled properly and match the expected reference offsets + assert_almost_equal( + saved_offsets, # Compare the saved offsets with the reference offsets + ref_offset, + err_msg="error loading frame offsets" + ) # pre-teardown permission fix - leaving permission blocked dir # is problematic on py3.9 + Windows it seems. See issue From 1fd23745678bf22dc7acc8f994bc0fdd3c6c776f Mon Sep 17 00:00:00 2001 From: Valerij Talagayev <82884038+talagayev@users.noreply.github.com> Date: Sat, 21 Dec 2024 00:02:14 +0100 Subject: [PATCH 31/49] Update test_xdr.py try to remove hack --- testsuite/MDAnalysisTests/coordinates/test_xdr.py | 5 ----- 1 file changed, 5 deletions(-) diff --git a/testsuite/MDAnalysisTests/coordinates/test_xdr.py b/testsuite/MDAnalysisTests/coordinates/test_xdr.py index 3215d618a0..6f74975a3a 100644 --- a/testsuite/MDAnalysisTests/coordinates/test_xdr.py +++ b/testsuite/MDAnalysisTests/coordinates/test_xdr.py @@ -892,11 +892,6 @@ def test_unsupported_format(self, traj): @pytest.mark.skipif(get_userid() == 0, reason="cannot readonly as root") # skip test in Windows Azure, due to different permission in Azure - @pytest.mark.skipif( - os.name == 'nt' and "AGENT_NAME" in os.environ, - reason="Windows Azure does not support locking/permission modification" - ) - def test_persistent_offsets_readonly(self, tmpdir): shutil.copy(self.filename, str(tmpdir)) From b7150e2aa6fee71d40a2fba250985762940058a6 Mon Sep 17 00:00:00 2001 From: Valerij Talagayev <82884038+talagayev@users.noreply.github.com> Date: Sat, 21 Dec 2024 00:50:17 +0100 Subject: [PATCH 32/49] Update test_xdr.py lets test this one --- testsuite/MDAnalysisTests/coordinates/test_xdr.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/testsuite/MDAnalysisTests/coordinates/test_xdr.py b/testsuite/MDAnalysisTests/coordinates/test_xdr.py index 6f74975a3a..2d0d471b96 100644 --- a/testsuite/MDAnalysisTests/coordinates/test_xdr.py +++ b/testsuite/MDAnalysisTests/coordinates/test_xdr.py @@ -921,6 +921,11 @@ def test_persistent_offsets_readonly(self, tmpdir): err_msg="error loading frame offsets" ) + 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')), False) + # pre-teardown permission fix - leaving permission blocked dir # is problematic on py3.9 + Windows it seems. See issue # [4123](https://github.com/MDAnalysis/mdanalysis/issues/4123) From b038a217b5713c695dd90144f60d87278b3bee9b Mon Sep 17 00:00:00 2001 From: Valerij Talagayev <82884038+talagayev@users.noreply.github.com> Date: Sat, 21 Dec 2024 02:19:58 +0100 Subject: [PATCH 33/49] Update test_xdr.py --- .../MDAnalysisTests/coordinates/test_xdr.py | 32 +++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/testsuite/MDAnalysisTests/coordinates/test_xdr.py b/testsuite/MDAnalysisTests/coordinates/test_xdr.py index 2d0d471b96..5d8de657c4 100644 --- a/testsuite/MDAnalysisTests/coordinates/test_xdr.py +++ b/testsuite/MDAnalysisTests/coordinates/test_xdr.py @@ -27,6 +27,7 @@ import os import shutil import subprocess +import time from pathlib import Path import numpy as np @@ -938,8 +939,35 @@ def test_persistent_offsets_readonly(self, tmpdir): shutil.rmtree(tmpdir) def test_offset_lock_created(self): - # File is created, but without .lock ending - assert os.path.exists(XDR.offsets_filename(self.filename)) + lock_file_path = XDR.offsets_filename(self.filename, ending='lock') + lock = FileLock(lock_file_path) + + # Start a count to release lock after 5 seconds + def release_lock_after_delay(): + time.sleep(5) + lock.release() + + # Acquire the lock + lock.acquire() + try: + # Start count + release_lock_after_delay() + + # Start timing to ensure the reader waits for the lock + start_time = time.time() + + with pytest.warns(UserWarning, match="Waiting for lock file"): + self._reader(self.filename) + + elapsed_time = time.time() - start_time + + # Ensure the function waited for the lock + assert elapsed_time >= 5, "read_offsets did not wait for the lock to be released." + + finally: + # Ensure the lock is released to avoid hanging + if lock.is_locked: + lock.release() class TestXTCReader_offsets(_GromacsReader_offsets): From db46e40412544216d6f0b51159e36a280e53e205 Mon Sep 17 00:00:00 2001 From: Valerij Talagayev <82884038+talagayev@users.noreply.github.com> Date: Sat, 21 Dec 2024 02:31:41 +0100 Subject: [PATCH 34/49] Update test_xdr.py --- testsuite/MDAnalysisTests/coordinates/test_xdr.py | 1 + 1 file changed, 1 insertion(+) diff --git a/testsuite/MDAnalysisTests/coordinates/test_xdr.py b/testsuite/MDAnalysisTests/coordinates/test_xdr.py index 5d8de657c4..356f560466 100644 --- a/testsuite/MDAnalysisTests/coordinates/test_xdr.py +++ b/testsuite/MDAnalysisTests/coordinates/test_xdr.py @@ -47,6 +47,7 @@ from MDAnalysis.coordinates.base import Timestep from MDAnalysis.coordinates import XDR from MDAnalysisTests.util import get_userid +from filelock import FileLock @pytest.mark.parametrize("filename,kwargs,reference", [ From 497f14e624bb69558532d707539c9cef44fa2980 Mon Sep 17 00:00:00 2001 From: Valerij Talagayev <82884038+talagayev@users.noreply.github.com> Date: Sat, 21 Dec 2024 03:03:05 +0100 Subject: [PATCH 35/49] Update test_xdr.py almost --- testsuite/MDAnalysisTests/coordinates/test_xdr.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/testsuite/MDAnalysisTests/coordinates/test_xdr.py b/testsuite/MDAnalysisTests/coordinates/test_xdr.py index 356f560466..dde64b009d 100644 --- a/testsuite/MDAnalysisTests/coordinates/test_xdr.py +++ b/testsuite/MDAnalysisTests/coordinates/test_xdr.py @@ -913,7 +913,6 @@ def test_persistent_offsets_readonly(self, tmpdir): # Use pytest.warns to check for the expected warnings when loading offsets fails with pytest.warns(UserWarning, match="Failed to load offsets"): - # Now using the XDR.read_numpy_offsets method to read the offsets saved_offsets = XDR.read_numpy_offsets(filename) # Check if the offsets are handled properly and match the expected reference offsets @@ -957,7 +956,7 @@ def release_lock_after_delay(): # Start timing to ensure the reader waits for the lock start_time = time.time() - with pytest.warns(UserWarning, match="Waiting for lock file"): + with pytest.warns(UserWarning): self._reader(self.filename) elapsed_time = time.time() - start_time From c271f6b483ca587b1ad70fabd9dbc0c3082eb826 Mon Sep 17 00:00:00 2001 From: Valerij Talagayev <82884038+talagayev@users.noreply.github.com> Date: Wed, 8 Jan 2025 20:13:28 +0100 Subject: [PATCH 36/49] Update test_xdr.py adjusting file lock checking pytest --- .../MDAnalysisTests/coordinates/test_xdr.py | 28 +++---------------- 1 file changed, 4 insertions(+), 24 deletions(-) diff --git a/testsuite/MDAnalysisTests/coordinates/test_xdr.py b/testsuite/MDAnalysisTests/coordinates/test_xdr.py index acbe0f6652..7c0db0ac97 100644 --- a/testsuite/MDAnalysisTests/coordinates/test_xdr.py +++ b/testsuite/MDAnalysisTests/coordinates/test_xdr.py @@ -1031,32 +1031,12 @@ def test_offset_lock_created(self): lock_file_path = XDR.offsets_filename(self.filename, ending='lock') lock = FileLock(lock_file_path) - # Start a count to release lock after 5 seconds - def release_lock_after_delay(): - time.sleep(5) - lock.release() - # Acquire the lock lock.acquire() - try: - # Start count - release_lock_after_delay() - - # Start timing to ensure the reader waits for the lock - start_time = time.time() - - with pytest.warns(UserWarning): - self._reader(self.filename) - - elapsed_time = time.time() - start_time - - # Ensure the function waited for the lock - assert elapsed_time >= 5, "read_offsets did not wait for the lock to be released." - - finally: - # Ensure the lock is released to avoid hanging - if lock.is_locked: - lock.release() + time.sleep(5) # wait 5 seconds before checking if the file is locked + assert lock.is_locked # check if file is locked + lock.release() + assert not lock.is_locked # check if file is unlocked class TestXTCReader_offsets(_GromacsReader_offsets): From 332f8cacd0f596855f9d7415fc317637b2359dbc Mon Sep 17 00:00:00 2001 From: Valerij Talagayev <82884038+talagayev@users.noreply.github.com> Date: Wed, 8 Jan 2025 21:04:53 +0100 Subject: [PATCH 37/49] Update test_xdr.py pep fixes --- testsuite/MDAnalysisTests/coordinates/test_xdr.py | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/testsuite/MDAnalysisTests/coordinates/test_xdr.py b/testsuite/MDAnalysisTests/coordinates/test_xdr.py index 7c0db0ac97..373a527950 100644 --- a/testsuite/MDAnalysisTests/coordinates/test_xdr.py +++ b/testsuite/MDAnalysisTests/coordinates/test_xdr.py @@ -994,18 +994,17 @@ def test_persistent_offsets_readonly(self, tmpdir): filename = str(tmpdir.join(os.path.basename(self.filename))) # try to write a offsets file, obtain Cannot write due to FileLock - ref_offset = XDR.read_numpy_offsets(self.filename) # Assuming this is the reference you want to use + ref_offset = XDR.read_numpy_offsets(self.filename) # Reference # Mock np.load to raise an error when trying to load offsets with patch.object(np, "load") as np_load_mock: - np_load_mock.side_effect = ValueError # Simulate failure in loading offsets - - # Use pytest.warns to check for the expected warnings when loading offsets fails + np_load_mock.side_effect = ValueError # Simulate failure + # Use pytest.warns to check for warnings with pytest.warns(UserWarning, match="Failed to load offsets"): saved_offsets = XDR.read_numpy_offsets(filename) - # Check if the offsets are handled properly and match the expected reference offsets + # Check if the offsets are handled properly and match reference offsets assert_almost_equal( - saved_offsets, # Compare the saved offsets with the reference offsets + saved_offsets, # Compare with reference offsets ref_offset, err_msg="error loading frame offsets" ) From 73e1d0398749085a1b906d06c0525ab130b90854 Mon Sep 17 00:00:00 2001 From: Valerij Talagayev <82884038+talagayev@users.noreply.github.com> Date: Wed, 8 Jan 2025 21:12:19 +0100 Subject: [PATCH 38/49] Update test_xdr.py pep --- testsuite/MDAnalysisTests/coordinates/test_xdr.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/testsuite/MDAnalysisTests/coordinates/test_xdr.py b/testsuite/MDAnalysisTests/coordinates/test_xdr.py index 373a527950..d785199d9e 100644 --- a/testsuite/MDAnalysisTests/coordinates/test_xdr.py +++ b/testsuite/MDAnalysisTests/coordinates/test_xdr.py @@ -1002,9 +1002,9 @@ def test_persistent_offsets_readonly(self, tmpdir): with pytest.warns(UserWarning, match="Failed to load offsets"): saved_offsets = XDR.read_numpy_offsets(filename) - # Check if the offsets are handled properly and match reference offsets + # Check if offsets are handled properly and match reference offsets assert_almost_equal( - saved_offsets, # Compare with reference offsets + saved_offsets, # Compare with reference offsets ref_offset, err_msg="error loading frame offsets" ) @@ -1012,8 +1012,8 @@ def test_persistent_offsets_readonly(self, tmpdir): 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')), - False, + os.path.exists(XDR.offsets_filename(filename, ending='.lock')), + False, ) # pre-teardown permission fix - leaving permission blocked dir # is problematic on py3.9 + Windows it seems. See issue @@ -1032,10 +1032,10 @@ def test_offset_lock_created(self): # Acquire the lock lock.acquire() - time.sleep(5) # wait 5 seconds before checking if the file is locked - assert lock.is_locked # check if file is locked + time.sleep(5) # wait 5 seconds before checking if the file is locked + assert lock.is_locked # check if file is locked lock.release() - assert not lock.is_locked # check if file is unlocked + assert not lock.is_locked # check if file is unlocked class TestXTCReader_offsets(_GromacsReader_offsets): From a6bb5fe0a92f8b846b04becedcf0d764b1798f28 Mon Sep 17 00:00:00 2001 From: Valerij Talagayev <82884038+talagayev@users.noreply.github.com> Date: Wed, 8 Jan 2025 22:10:05 +0100 Subject: [PATCH 39/49] Update test_xdr.py --- testsuite/MDAnalysisTests/coordinates/test_xdr.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/testsuite/MDAnalysisTests/coordinates/test_xdr.py b/testsuite/MDAnalysisTests/coordinates/test_xdr.py index d785199d9e..5a306589a6 100644 --- a/testsuite/MDAnalysisTests/coordinates/test_xdr.py +++ b/testsuite/MDAnalysisTests/coordinates/test_xdr.py @@ -1029,11 +1029,13 @@ def test_persistent_offsets_readonly(self, tmpdir): def test_offset_lock_created(self): lock_file_path = XDR.offsets_filename(self.filename, ending='lock') lock = FileLock(lock_file_path) - + # Acquire the lock lock.acquire() + time.sleep(5) # wait 5 seconds before checking if the file is locked assert lock.is_locked # check if file is locked + lock.release() assert not lock.is_locked # check if file is unlocked From a5d0f3adabfc805a13ec6d7bcb92cc86b0c7e7a7 Mon Sep 17 00:00:00 2001 From: Valerij Talagayev <82884038+talagayev@users.noreply.github.com> Date: Wed, 8 Jan 2025 22:17:29 +0100 Subject: [PATCH 40/49] Update test_xdr.py small black adjustments --- testsuite/MDAnalysisTests/coordinates/test_xdr.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/testsuite/MDAnalysisTests/coordinates/test_xdr.py b/testsuite/MDAnalysisTests/coordinates/test_xdr.py index 5a306589a6..5d820522f0 100644 --- a/testsuite/MDAnalysisTests/coordinates/test_xdr.py +++ b/testsuite/MDAnalysisTests/coordinates/test_xdr.py @@ -1006,13 +1006,13 @@ def test_persistent_offsets_readonly(self, tmpdir): assert_almost_equal( saved_offsets, # Compare with reference offsets ref_offset, - err_msg="error loading frame offsets" + err_msg="error loading frame offsets", ) 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, ) # pre-teardown permission fix - leaving permission blocked dir From fe59638fb27efdb0164ff174a31ccd82f397e01e Mon Sep 17 00:00:00 2001 From: Valerij Talagayev <82884038+talagayev@users.noreply.github.com> Date: Thu, 9 Jan 2025 20:25:53 +0100 Subject: [PATCH 41/49] Update test_xdr.py remove sleep --- testsuite/MDAnalysisTests/coordinates/test_xdr.py | 1 - 1 file changed, 1 deletion(-) diff --git a/testsuite/MDAnalysisTests/coordinates/test_xdr.py b/testsuite/MDAnalysisTests/coordinates/test_xdr.py index 5d820522f0..480390ca96 100644 --- a/testsuite/MDAnalysisTests/coordinates/test_xdr.py +++ b/testsuite/MDAnalysisTests/coordinates/test_xdr.py @@ -1033,7 +1033,6 @@ def test_offset_lock_created(self): # Acquire the lock lock.acquire() - time.sleep(5) # wait 5 seconds before checking if the file is locked assert lock.is_locked # check if file is locked lock.release() From d1df5ac14b92c70a1a6b4270ca88d7ba258bb2b7 Mon Sep 17 00:00:00 2001 From: Valerij Talagayev <82884038+talagayev@users.noreply.github.com> Date: Thu, 9 Jan 2025 21:23:40 +0100 Subject: [PATCH 42/49] Update test_xdr.py reverted to pytest in develop --- testsuite/MDAnalysisTests/coordinates/test_xdr.py | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/testsuite/MDAnalysisTests/coordinates/test_xdr.py b/testsuite/MDAnalysisTests/coordinates/test_xdr.py index 480390ca96..b8eb68364e 100644 --- a/testsuite/MDAnalysisTests/coordinates/test_xdr.py +++ b/testsuite/MDAnalysisTests/coordinates/test_xdr.py @@ -1027,16 +1027,9 @@ def test_persistent_offsets_readonly(self, tmpdir): shutil.rmtree(tmpdir) def test_offset_lock_created(self): - lock_file_path = XDR.offsets_filename(self.filename, ending='lock') - lock = FileLock(lock_file_path) - - # Acquire the lock - lock.acquire() - - assert lock.is_locked # check if file is locked - - lock.release() - assert not lock.is_locked # check if file is unlocked + assert os.path.exists( + XDR.offsets_filename(self.filename, ending="lock") + ) class TestXTCReader_offsets(_GromacsReader_offsets): From 8bb1c7768d347c71f571e9e32f6e617421a8299f Mon Sep 17 00:00:00 2001 From: Valerij Talagayev <82884038+talagayev@users.noreply.github.com> Date: Thu, 9 Jan 2025 22:34:55 +0100 Subject: [PATCH 43/49] Update test_xdr.py check without lock --- testsuite/MDAnalysisTests/coordinates/test_xdr.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/testsuite/MDAnalysisTests/coordinates/test_xdr.py b/testsuite/MDAnalysisTests/coordinates/test_xdr.py index b8eb68364e..1f267efc8d 100644 --- a/testsuite/MDAnalysisTests/coordinates/test_xdr.py +++ b/testsuite/MDAnalysisTests/coordinates/test_xdr.py @@ -1028,7 +1028,7 @@ def test_persistent_offsets_readonly(self, tmpdir): def test_offset_lock_created(self): assert os.path.exists( - XDR.offsets_filename(self.filename, ending="lock") + XDR.offsets_filename(self.filename) ) From 42539bdb49b94a6e05793f14dde941070789b44b Mon Sep 17 00:00:00 2001 From: Valerij Talagayev <82884038+talagayev@users.noreply.github.com> Date: Thu, 9 Jan 2025 23:28:25 +0100 Subject: [PATCH 44/49] Update test_xdr.py return ending="lock" --- testsuite/MDAnalysisTests/coordinates/test_xdr.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/testsuite/MDAnalysisTests/coordinates/test_xdr.py b/testsuite/MDAnalysisTests/coordinates/test_xdr.py index 1f267efc8d..b8eb68364e 100644 --- a/testsuite/MDAnalysisTests/coordinates/test_xdr.py +++ b/testsuite/MDAnalysisTests/coordinates/test_xdr.py @@ -1028,7 +1028,7 @@ def test_persistent_offsets_readonly(self, tmpdir): def test_offset_lock_created(self): assert os.path.exists( - XDR.offsets_filename(self.filename) + XDR.offsets_filename(self.filename, ending="lock") ) From 3c5cb668651189ad8b26bbcdae34bc6d2dadb3fc Mon Sep 17 00:00:00 2001 From: Yuxuan Zhuang Date: Thu, 9 Jan 2025 17:56:11 -0800 Subject: [PATCH 45/49] check lock file exists for traj --- testsuite/MDAnalysisTests/coordinates/test_xdr.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/testsuite/MDAnalysisTests/coordinates/test_xdr.py b/testsuite/MDAnalysisTests/coordinates/test_xdr.py index b8eb68364e..ccd7709d4b 100644 --- a/testsuite/MDAnalysisTests/coordinates/test_xdr.py +++ b/testsuite/MDAnalysisTests/coordinates/test_xdr.py @@ -1026,9 +1026,9 @@ def test_persistent_offsets_readonly(self, tmpdir): shutil.rmtree(tmpdir) - def test_offset_lock_created(self): + def test_offset_lock_created(self, traj): assert os.path.exists( - XDR.offsets_filename(self.filename, ending="lock") + XDR.offsets_filename(traj, ending="lock") ) From 2fb9b69cf701b1a9177bdaa1bd44f76289b62f5c Mon Sep 17 00:00:00 2001 From: Yuxuan Zhuang Date: Thu, 9 Jan 2025 18:01:04 -0800 Subject: [PATCH 46/49] use mock to test cannot write offsets --- testsuite/MDAnalysisTests/coordinates/test_xdr.py | 15 ++------------- 1 file changed, 2 insertions(+), 13 deletions(-) diff --git a/testsuite/MDAnalysisTests/coordinates/test_xdr.py b/testsuite/MDAnalysisTests/coordinates/test_xdr.py index ccd7709d4b..b6b45f9822 100644 --- a/testsuite/MDAnalysisTests/coordinates/test_xdr.py +++ b/testsuite/MDAnalysisTests/coordinates/test_xdr.py @@ -980,25 +980,14 @@ def test_unsupported_format(self, traj): reader[idx_frame] @pytest.mark.skipif(get_userid() == 0, reason="cannot readonly as root") - # skip test in Windows Azure, due to different permission in Azure - def test_persistent_offsets_readonly(self, tmpdir): + def test_persistent_offsets_readonly(self, tmpdir, traj): shutil.copy(self.filename, str(tmpdir)) - if os.name == "nt": - # Windows platform has a unique way to deny write access - subprocess.call( - "icacls {fname} /deny Users:W".format(fname=tmpdir), shell=True - ) - else: - os.chmod(str(tmpdir), 0o555) - filename = str(tmpdir.join(os.path.basename(self.filename))) - # try to write a offsets file, obtain Cannot write due to FileLock - ref_offset = XDR.read_numpy_offsets(self.filename) # Reference + ref_offset = XDR.read_numpy_offsets(traj) # Reference # Mock np.load to raise an error when trying to load offsets with patch.object(np, "load") as np_load_mock: np_load_mock.side_effect = ValueError # Simulate failure - # Use pytest.warns to check for warnings with pytest.warns(UserWarning, match="Failed to load offsets"): saved_offsets = XDR.read_numpy_offsets(filename) From 9b8209a448e023208adc4007f9ab3c01a41d7dde Mon Sep 17 00:00:00 2001 From: Yuxuan Zhuang Date: Fri, 10 Jan 2025 14:23:03 -0800 Subject: [PATCH 47/49] skip lock file test for windows --- testsuite/MDAnalysisTests/coordinates/test_xdr.py | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/testsuite/MDAnalysisTests/coordinates/test_xdr.py b/testsuite/MDAnalysisTests/coordinates/test_xdr.py index b6b45f9822..946e3e0002 100644 --- a/testsuite/MDAnalysisTests/coordinates/test_xdr.py +++ b/testsuite/MDAnalysisTests/coordinates/test_xdr.py @@ -979,7 +979,6 @@ def test_unsupported_format(self, traj): reader = self._reader(traj) reader[idx_frame] - @pytest.mark.skipif(get_userid() == 0, reason="cannot readonly as root") def test_persistent_offsets_readonly(self, tmpdir, traj): shutil.copy(self.filename, str(tmpdir)) @@ -1004,17 +1003,12 @@ def test_persistent_offsets_readonly(self, tmpdir, traj): os.path.exists(XDR.offsets_filename(filename, ending=".lock")), False, ) - # pre-teardown permission fix - leaving permission blocked dir - # is problematic on py3.9 + Windows it seems. See issue - # [4123](https://github.com/MDAnalysis/mdanalysis/issues/4123) - # for more details. - if os.name == "nt": - subprocess.call(f"icacls {tmpdir} /grant Users:W", shell=True) - else: - os.chmod(str(tmpdir), 0o777) - shutil.rmtree(tmpdir) + @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") From fd537cc7ef5f44b03845709f5633b5567b71e3da Mon Sep 17 00:00:00 2001 From: Yuxuan Zhuang Date: Fri, 10 Jan 2025 14:31:12 -0800 Subject: [PATCH 48/49] import sys --- testsuite/MDAnalysisTests/coordinates/test_xdr.py | 1 + 1 file changed, 1 insertion(+) diff --git a/testsuite/MDAnalysisTests/coordinates/test_xdr.py b/testsuite/MDAnalysisTests/coordinates/test_xdr.py index 946e3e0002..e9b3d7fdc0 100644 --- a/testsuite/MDAnalysisTests/coordinates/test_xdr.py +++ b/testsuite/MDAnalysisTests/coordinates/test_xdr.py @@ -25,6 +25,7 @@ import re import os +import sys import shutil import subprocess import time From 7b580c17ee823889f6b8090e69cb6b353d96194f Mon Sep 17 00:00:00 2001 From: Yuxuan Zhuang Date: Sat, 11 Jan 2025 07:59:29 -0800 Subject: [PATCH 49/49] test filelock permission error --- .../MDAnalysisTests/coordinates/test_xdr.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/testsuite/MDAnalysisTests/coordinates/test_xdr.py b/testsuite/MDAnalysisTests/coordinates/test_xdr.py index e9b3d7fdc0..2ca76580fc 100644 --- a/testsuite/MDAnalysisTests/coordinates/test_xdr.py +++ b/testsuite/MDAnalysisTests/coordinates/test_xdr.py @@ -980,16 +980,17 @@ def test_unsupported_format(self, traj): reader = self._reader(traj) reader[idx_frame] - def test_persistent_offsets_readonly(self, tmpdir, traj): + def test_persistent_offsets_readonly(self, tmpdir, trajectory): shutil.copy(self.filename, str(tmpdir)) filename = str(tmpdir.join(os.path.basename(self.filename))) - ref_offset = XDR.read_numpy_offsets(traj) # Reference - # Mock np.load to raise an error when trying to load offsets - with patch.object(np, "load") as np_load_mock: - np_load_mock.side_effect = ValueError # Simulate failure - with pytest.warns(UserWarning, match="Failed to load offsets"): - saved_offsets = XDR.read_numpy_offsets(filename) + print('filename', filename) + ref_offset = trajectory._xdr.offsets + # Mock filelock acquire to raise an error + with patch.object(FileLock, "acquire", side_effect=PermissionError): # Simulate failure + with pytest.warns(UserWarning, match="Cannot write lock"): + reader = self._reader(filename) + saved_offsets = reader._xdr.offsets # Check if offsets are handled properly and match reference offsets assert_almost_equal( @@ -1004,7 +1005,6 @@ def test_persistent_offsets_readonly(self, tmpdir, traj): os.path.exists(XDR.offsets_filename(filename, ending=".lock")), False, ) - shutil.rmtree(tmpdir) @pytest.mark.skipif( sys.platform.startswith("win"),