mirror of
https://github.com/ProjectLeonida/mandy.git
synced 2026-12-06 09:18:37 +00:00
run_wine_tests: note and carry on when the drive cannot be mapped (WINE-DRIVE-MAP-OSERROR)
DriveMap.__enter__ handled only FileExistsError. A prefix whose dosdevices folder cannot be written aborted the run with a traceback before any test. Any OSError while mapping now sets a note and leaves the drive unmapped; the scratch folder is removed as before. Tests: the old drive-setup test asserted the traceback; it now checks the note, the cleanup and that __enter__ does not raise. A second test covers a scratch folder that cannot be created.
This commit is contained in:
@ -67,7 +67,8 @@ class DriveMap:
|
||||
<root>/runtime/build/generated/x.spv. The drive is a dosdevices link to a scratch folder holding a/Leonida/Leonida
|
||||
as a link to the root. If the Windows checkout is the drive root itself, the drive links directly to the
|
||||
Linux checkout. Temporary links and scratch folders are removed afterwards. A drive the prefix already has
|
||||
(c:, z:, or one set up by hand) is left alone, and so is a root without an absolute drive path.
|
||||
(c:, z:, or one set up by hand) is left alone, and so is a root without an absolute drive path. A prefix that
|
||||
cannot take the link (read-only, permission denied) also leaves the drive unmapped; the note says why.
|
||||
"""
|
||||
|
||||
def __init__(self, windows_root: str, root: str, prefix: str):
|
||||
@ -104,6 +105,10 @@ class DriveMap:
|
||||
self.note = already_set
|
||||
return self
|
||||
self.link = link
|
||||
except OSError as e:
|
||||
# A read-only or otherwise unwritable prefix: run the tests without the drive, and say so.
|
||||
self.note = f"cannot map drive {drive}: {e.strerror or e}: the run goes on without it"
|
||||
return self
|
||||
finally:
|
||||
# __exit__ only runs after a successful __enter__.
|
||||
if self.link is None and self.scratch is not None:
|
||||
|
||||
@ -426,18 +426,25 @@ class DriveMapTest(unittest.TestCase):
|
||||
self.assertEqual(os.readlink(self.link), str(other))
|
||||
self.assertFalse(scratch.exists())
|
||||
|
||||
def test_failed_drive_setup_removes_scratch_directory(self):
|
||||
def test_an_unwritable_prefix_is_noted_and_the_run_goes_on_unmapped(self):
|
||||
scratch = self.prefix / "scratch"
|
||||
scratch.mkdir()
|
||||
with mock.patch.object(rwt.tempfile, "mkdtemp", return_value=str(scratch)), \
|
||||
mock.patch.object(rwt.os, "symlink", side_effect=PermissionError("link denied")):
|
||||
with self.assertRaisesRegex(PermissionError, "link denied"):
|
||||
with rwt.DriveMap(WINDOWS_ROOT, str(self.root), str(self.prefix)):
|
||||
self.fail("drive setup unexpectedly succeeded")
|
||||
mock.patch.object(rwt.os, "symlink", side_effect=PermissionError(13, "Permission denied")):
|
||||
with rwt.DriveMap(WINDOWS_ROOT, str(self.root), str(self.prefix)) as drive:
|
||||
self.assertIn("cannot map drive d: Permission denied", drive.note)
|
||||
self.assertIsNone(drive.link)
|
||||
|
||||
self.assertFalse(scratch.exists())
|
||||
self.assertFalse(os.path.lexists(self.link))
|
||||
|
||||
def test_a_scratch_folder_that_cannot_be_made_is_noted_too(self):
|
||||
with mock.patch.object(rwt.tempfile, "mkdtemp", side_effect=OSError(28, "No space left on device")):
|
||||
with rwt.DriveMap(WINDOWS_ROOT, str(self.root), str(self.prefix)) as drive:
|
||||
self.assertIn("cannot map drive d: No space left on device", drive.note)
|
||||
self.assertIsNone(drive.scratch)
|
||||
self.assertFalse(os.path.lexists(self.link))
|
||||
|
||||
def test_no_prefix_or_no_drive_letter_maps_nothing(self):
|
||||
with rwt.DriveMap("D:/a/b", str(self.root), str(self.prefix / "absent")) as drive:
|
||||
self.assertIn("no Wine prefix", drive.note)
|
||||
|
||||
Reference in New Issue
Block a user