From 08f73c9fe190d9cc64466c4c5f70ee8eeb23de04 Mon Sep 17 00:00:00 2001 From: R1kaB3rN <100738684+R1kaB3rN@users.noreply.github.com> Date: Tue, 13 Feb 2024 22:07:40 -0800 Subject: [PATCH] ulwgl_test.py: add test for setup_prefix - Test the case when the user runs the launcher again after moving the WINEPREFIX. An error should not be raised when creating a symbolic link. - Related to https://github.com/Open-Wine-Components/ULWGL-launcher/issues/27 --- ulwgl_test.py | 60 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) diff --git a/ulwgl_test.py b/ulwgl_test.py index 4969344..75fefdc 100644 --- a/ulwgl_test.py +++ b/ulwgl_test.py @@ -866,6 +866,66 @@ class TestGameLauncher(unittest.TestCase): "Expected STEAM_COMPAT_MOUNTS to be set", ) + def test_setup_pfx_mv(self): + """Test setup_pfx when moving the WINEPREFIX after creating it. + + After setting up the prefix then moving it to a different path, ensure that the symbolic link points to that new location + """ + result = None + pattern = r"^/home/[a-zA-Z]+" + unexpanded_path = re.sub( + pattern, + "~", + Path( + Path(self.test_file).cwd().as_posix() + "/" + self.test_file + ).as_posix(), + ) + result = ulwgl_run.setup_pfx(unexpanded_path) + + # Replaces the expanded path to unexpanded + # Example: ~/some/path/to/this/file -> /home/foo/path/to/this/file + self.assertIsNone( + result, + "Expected None when creating symbolic link to WINE prefix and tracked_files file", + ) + self.assertTrue( + Path(self.test_file + "/pfx").is_symlink(), "Expected pfx to be a symlink" + ) + self.assertTrue( + Path(self.test_file + "/tracked_files").is_file(), + "Expected tracked_files to be a file", + ) + self.assertTrue( + Path(self.test_file + "/pfx").is_symlink(), "Expected pfx to be a symlink" + ) + + # Check if the symlink is in its unexpanded form + self.assertEqual( + Path(self.test_file + "/pfx").readlink().as_posix(), + Path(unexpanded_path).expanduser().as_posix(), + ) + + old_link = Path(self.test_file + "/pfx").resolve() + + # Rename the dir and replicate passing a new WINEPREFIX + new_dir = Path(unexpanded_path).expanduser().rename("foo") + new_unexpanded_path = re.sub( + pattern, + "~", + Path(new_dir.cwd().as_posix() + "/" + "foo").as_posix(), + ) + + ulwgl_run.setup_pfx(new_unexpanded_path) + + new_link = Path("foo" + "/pfx").resolve() + self.assertTrue( + old_link is not new_link, + "Expected the symbolic link to change after moving the WINEPREFIX", + ) + + if new_link.exists(): + rmtree(new_link.as_posix()) + def test_setup_pfx_symlinks(self): """Test _setup_pfx for valid symlinks.