Skip to content

Commit

Permalink
use mock to test cannot write offsets
Browse files Browse the repository at this point in the history
  • Loading branch information
yuxuanzhuang authored Jan 10, 2025
1 parent 3c5cb66 commit 2fb9b69
Showing 1 changed file with 2 additions and 13 deletions.
15 changes: 2 additions & 13 deletions testsuite/MDAnalysisTests/coordinates/test_xdr.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down

0 comments on commit 2fb9b69

Please sign in to comment.