From 3d5119c66e5c4abbbd8b45516e919a2bcf7b245c Mon Sep 17 00:00:00 2001 From: R1kaB3rN <100738684+R1kaB3rN@users.noreply.github.com> Date: Wed, 21 Feb 2024 18:50:42 -0800 Subject: [PATCH] ulwgl_test: refactor filepaths in tests - Try to prefer using .joinpath when joining segments --- ulwgl_test.py | 26 ++++++++------------------ 1 file changed, 8 insertions(+), 18 deletions(-) diff --git a/ulwgl_test.py b/ulwgl_test.py index ff200ea..f36da71 100644 --- a/ulwgl_test.py +++ b/ulwgl_test.py @@ -907,12 +907,8 @@ class TestGameLauncher(unittest.TestCase): # Replaces the expanded path to unexpanded # Example: ~/some/path/to/this/file -> /home/foo/path/to/this/file - path_to_tmp = Path( - Path(__file__).cwd().as_posix() + "/" + self.test_file - ).as_posix() - path_to_exe = Path( - Path(__file__).cwd().as_posix() + "/" + self.test_exe - ).as_posix() + path_to_tmp = Path(__file__).cwd().joinpath(self.test_file).as_posix() + path_to_exe = Path(__file__).cwd().joinpath(self.test_exe).as_posix() # Replace /home/[a-zA-Z]+ substring in path with tilda unexpanded_path = re.sub( @@ -1281,9 +1277,7 @@ class TestGameLauncher(unittest.TestCase): unexpanded_path = re.sub( pattern, "~", - Path( - Path(self.test_file).cwd().as_posix() + "/" + self.test_file - ).as_posix(), + Path(self.test_file).cwd().joinpath(self.test_file).as_posix(), ) result = ulwgl_run.setup_pfx(unexpanded_path) @@ -1317,12 +1311,12 @@ class TestGameLauncher(unittest.TestCase): new_unexpanded_path = re.sub( pattern, "~", - Path(new_dir.cwd().as_posix() + "/" + "foo").as_posix(), + new_dir.cwd().joinpath("foo").as_posix(), ) ulwgl_run.setup_pfx(new_unexpanded_path) - new_link = Path("foo" + "/pfx").resolve() + new_link = Path("foo/pfx").resolve() self.assertTrue( old_link is not new_link, "Expected the symbolic link to change after moving the WINEPREFIX", @@ -1347,9 +1341,7 @@ class TestGameLauncher(unittest.TestCase): unexpanded_path = re.sub( pattern, "~", - Path( - Path(self.test_file).cwd().as_posix() + "/" + self.test_file - ).as_posix(), + Path(self.test_file).cwd().joinpath(self.test_file).as_posix(), ) result = ulwgl_run.setup_pfx(unexpanded_path) @@ -1386,7 +1378,7 @@ class TestGameLauncher(unittest.TestCase): unexpanded_path = re.sub( pattern, "~", - Path(Path(self.test_file).as_posix()).as_posix(), + Path(self.test_file).as_posix(), ) result = ulwgl_run.setup_pfx(unexpanded_path) @@ -1493,9 +1485,7 @@ class TestGameLauncher(unittest.TestCase): def test_env_vars_paths(self): """Test check_env when setting unexpanded paths for $WINEPREFIX and $PROTONPATH.""" pattern = r"^/home/[\w\d]+" # Expects only unicode decimals and alphanumerics - path_to_tmp = Path( - Path(__file__).cwd().as_posix() + "/" + self.test_file - ).as_posix() + path_to_tmp = Path(__file__).cwd().joinpath(self.test_file).as_posix() # Replace /home/[a-zA-Z]+ substring in path with tilda unexpanded_path = re.sub(