diff options
| author | ItsNotRexed <300290919+ItsNotRexed@users.noreply.github.com> | 2026-11-22 23:09:22 -0500 |
|---|---|---|
| committer | ItsNotRexed <300290919+ItsNotRexed@users.noreply.github.com> | 2026-11-22 23:09:22 -0500 |
| commit | 3baa73a9130adb13d340a79299bd3fc7e8663473 (patch) | |
| tree | ec7b1923b1b36823f6030c3f19b4b1e8ce139d69 | |
| parent | 3561d32a3b3dc75aa993527821e6e13809ce91a5 (diff) | |
| parent | 62bce63d1cfd00007f17b5c8255c5350c58084d4 (diff) | |
Merge pull request #3899 from bbareth
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
| -rw-r--r-- | scripts/run_wine_tests.py | 23 | ||||
| -rw-r--r-- | tests/test_run_wine_tests.py | 32 |
2 files changed, 49 insertions, 6 deletions
diff --git a/scripts/run_wine_tests.py b/scripts/run_wine_tests.py index 8392c8121..6499eb74a 100644 --- a/scripts/run_wine_tests.py +++ b/scripts/run_wine_tests.py | |||
| @@ -80,15 +80,26 @@ class DriveMap: | |||
| 80 | if not os.path.isdir(dosdevices): | 80 | if not os.path.isdir(dosdevices): |
| 81 | self.note = f"no Wine prefix at {self.prefix}: drive {drive}: not mapped" | 81 | self.note = f"no Wine prefix at {self.prefix}: drive {drive}: not mapped" |
| 82 | return self | 82 | return self |
| 83 | already_set = f"drive {drive}: is already set in {dosdevices}: left as it is" | ||
| 83 | if os.path.lexists(link): | 84 | if os.path.lexists(link): |
| 84 | self.note = f"drive {drive}: is already set in {dosdevices}: left as it is" | 85 | self.note = already_set |
| 85 | return self | 86 | return self |
| 86 | self.scratch = tempfile.mkdtemp(prefix="wine-drive-") | 87 | self.scratch = tempfile.mkdtemp(prefix="wine-drive-") |
| 87 | parent = os.path.join(self.scratch, *rest[:-1]) | 88 | try: |
| 88 | os.makedirs(parent, exist_ok=True) | 89 | parent = os.path.join(self.scratch, *rest[:-1]) |
| 89 | os.symlink(self.root, os.path.join(parent, rest[-1])) | 90 | os.makedirs(parent, exist_ok=True) |
| 90 | os.symlink(self.scratch, link) | 91 | os.symlink(self.root, os.path.join(parent, rest[-1])) |
| 91 | self.link = link | 92 | try: |
| 93 | os.symlink(self.scratch, link) | ||
| 94 | except FileExistsError: | ||
| 95 | self.note = already_set | ||
| 96 | return self | ||
| 97 | self.link = link | ||
| 98 | finally: | ||
| 99 | # __exit__ only runs after a successful __enter__. | ||
| 100 | if self.link is None: | ||
| 101 | shutil.rmtree(self.scratch, ignore_errors=True) | ||
| 102 | self.scratch = None | ||
| 92 | self.note = f"drive {drive}: maps {self.windows_root} to {self.root} for this run" | 103 | self.note = f"drive {drive}: maps {self.windows_root} to {self.root} for this run" |
| 93 | return self | 104 | return self |
| 94 | 105 | ||
diff --git a/tests/test_run_wine_tests.py b/tests/test_run_wine_tests.py index c7bc52c7b..d13ddcd56 100644 --- a/tests/test_run_wine_tests.py +++ b/tests/test_run_wine_tests.py | |||
| @@ -338,6 +338,38 @@ class DriveMapTest(unittest.TestCase): | |||
| 338 | self.assertIn("already set", drive.note) | 338 | self.assertIn("already set", drive.note) |
| 339 | self.assertEqual(os.readlink(self.link), str(other)) | 339 | self.assertEqual(os.readlink(self.link), str(other)) |
| 340 | 340 | ||
| 341 | def test_drive_created_during_setup_is_left_alone(self): | ||
| 342 | other = self.prefix / "concurrent" | ||
| 343 | other.mkdir() | ||
| 344 | scratch = self.prefix / "scratch" | ||
| 345 | scratch.mkdir() | ||
| 346 | symlink = os.symlink | ||
| 347 | |||
| 348 | def add_mapping(target, link): | ||
| 349 | if Path(link) == self.link: | ||
| 350 | symlink(other, self.link) | ||
| 351 | symlink(target, link) | ||
| 352 | |||
| 353 | with mock.patch.object(rwt.tempfile, "mkdtemp", return_value=str(scratch)), \ | ||
| 354 | mock.patch.object(rwt.os, "symlink", side_effect=add_mapping): | ||
| 355 | with rwt.DriveMap(WINDOWS_ROOT, str(self.root), str(self.prefix)) as drive: | ||
| 356 | self.assertIn("already set", drive.note) | ||
| 357 | |||
| 358 | self.assertEqual(os.readlink(self.link), str(other)) | ||
| 359 | self.assertFalse(scratch.exists()) | ||
| 360 | |||
| 361 | def test_failed_drive_setup_removes_scratch_directory(self): | ||
| 362 | scratch = self.prefix / "scratch" | ||
| 363 | scratch.mkdir() | ||
| 364 | with mock.patch.object(rwt.tempfile, "mkdtemp", return_value=str(scratch)), \ | ||
| 365 | mock.patch.object(rwt.os, "symlink", side_effect=PermissionError("link denied")): | ||
| 366 | with self.assertRaisesRegex(PermissionError, "link denied"): | ||
| 367 | with rwt.DriveMap(WINDOWS_ROOT, str(self.root), str(self.prefix)): | ||
| 368 | self.fail("drive setup unexpectedly succeeded") | ||
| 369 | |||
| 370 | self.assertFalse(scratch.exists()) | ||
| 371 | self.assertFalse(os.path.lexists(self.link)) | ||
| 372 | |||
| 341 | def test_no_prefix_or_no_drive_letter_maps_nothing(self): | 373 | def test_no_prefix_or_no_drive_letter_maps_nothing(self): |
| 342 | with rwt.DriveMap("D:/a/b", str(self.root), str(self.prefix / "absent")) as drive: | 374 | with rwt.DriveMap("D:/a/b", str(self.root), str(self.prefix / "absent")) as drive: |
| 343 | self.assertIn("no Wine prefix", drive.note) | 375 | self.assertIn("no Wine prefix", drive.note) |