mirror of
https://github.com/ProjectLeonida/mandy.git
synced 2026-12-06 09:08:38 +00:00
image_query_probe: publish mode on Windows (IMAGE-QUERY-PROBE-STAGE-CLEANUP)
agent: yes AI-assisted: yes
This commit is contained in:
@ -226,6 +226,43 @@ class Comparison(unittest.TestCase):
|
||||
finally:
|
||||
os.chmod(report, 0o600)
|
||||
|
||||
def test_publish_cleans_up_staged_file_when_replace_fails_even_if_readonly(self):
|
||||
with tempfile.TemporaryDirectory() as tmp:
|
||||
report = os.path.join(tmp, "report.json")
|
||||
with open(report, "w", encoding="utf-8") as f:
|
||||
f.write('{"initial": 1}\n')
|
||||
os.chmod(report, 0o444)
|
||||
|
||||
real_unlink = os.unlink
|
||||
|
||||
def windows_strict_unlink(p):
|
||||
mode = os.stat(p).st_mode
|
||||
if not (mode & 0o200):
|
||||
raise PermissionError(13, f"Access is denied: {p}")
|
||||
return real_unlink(p)
|
||||
|
||||
with mock.patch.object(pr, "replace_retry", side_effect=OSError(13, "Permission denied")), \
|
||||
mock.patch("os.unlink", side_effect=windows_strict_unlink):
|
||||
with self.assertRaises(OSError):
|
||||
pr.write_report(report, {"new": True})
|
||||
|
||||
leftover = [f for f in os.listdir(tmp) if f.startswith(".image_query_probe-")]
|
||||
self.assertEqual(leftover, [])
|
||||
|
||||
def test_publish_applies_published_mode_on_windows(self):
|
||||
with tempfile.TemporaryDirectory() as tmp:
|
||||
report = os.path.join(tmp, "report_win.json")
|
||||
chmod_calls = []
|
||||
real_chmod = os.chmod
|
||||
|
||||
def track_chmod(p, mode):
|
||||
chmod_calls.append((p, mode))
|
||||
real_chmod(p, mode)
|
||||
|
||||
with mock.patch("os.name", "nt"), mock.patch("os.chmod", side_effect=track_chmod):
|
||||
pr.write_report(report, {"win": True})
|
||||
self.assertTrue(len(chmod_calls) > 0)
|
||||
|
||||
|
||||
class Hardware(unittest.TestCase):
|
||||
def test_on_the_gpu(self):
|
||||
|
||||
@ -308,8 +308,7 @@ def write_report(path, report):
|
||||
) as f:
|
||||
tmp = f.name
|
||||
json.dump(report, f, indent=1)
|
||||
if os.name != "nt":
|
||||
os.chmod(tmp, published_mode(destination))
|
||||
os.chmod(tmp, published_mode(destination))
|
||||
replace_retry(tmp, destination)
|
||||
except BaseException:
|
||||
if tmp is not None:
|
||||
|
||||
Reference in New Issue
Block a user