Skip to content

Commit

Permalink
gamelauncher_test.py: update tests to assert reference
Browse files Browse the repository at this point in the history
- There's never a case where the reference stays the same when the data type of the variable changes. By asserting the reference, we effectively check both the data type and the reference.
  • Loading branch information
R1kaB3rN committed Feb 9, 2024
1 parent adfb58a commit a8f3e26
Showing 1 changed file with 22 additions and 53 deletions.
75 changes: 22 additions & 53 deletions gamelauncher_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,7 @@ def test_game_drive_empty(self):
)
# Check if required env var are set
result_check_env = gamelauncher.check_env(self.env)
self.assertIsInstance(
result_check_env, dict, "Expected a Dictionary from set_env_toml"
)
self.assertTrue(result_check_env is self.env, "Expected the same reference")
self.assertEqual(
self.env["WINEPREFIX"], self.test_file, "Expected WINEPREFIX to be set"
)
Expand All @@ -102,9 +100,7 @@ def test_game_drive_empty(self):

# Set the required environment variables
result_set_env = gamelauncher.set_env(self.env, result)
self.assertIsInstance(
result_set_env, dict, "Expected a Dictionary from set_env_toml"
)
self.assertTrue(result_set_env is self.env, "Expected the same reference")

# Check for expected changes
# We only check the required ones
Expand Down Expand Up @@ -134,17 +130,13 @@ def test_game_drive_empty(self):
)
self.env["STEAM_COMPAT_MOUNTS"] = self.env["STEAM_COMPAT_TOOL_PATHS"]

# Create an empty Proton prefix when asked
if not getattr(result, "exe", None) and not getattr(result, "config", None):
self.env["EXE"] = ""
self.env["STEAM_COMPAT_INSTALL_PATH"] = ""
self.verb = "waitforexitandrun"

# Game Drive
result_gamedrive = gamelauncher_plugins.enable_steam_game_drive(self.env)
self.assertIsInstance(
result_gamedrive, dict, "Expected a Dictionary from enable_steam_game_drive"
)
self.assertTrue(result_gamedrive is self.env, "Expected the same reference")

self.assertTrue(
Expand Down Expand Up @@ -219,9 +211,7 @@ def test_build_command_verb(self):
# Check if a verb was passed
self.assertTrue(vars(result).get("verb"), "Expected a value for --verb")
result_set_env = gamelauncher.set_env_toml(self.env, result)
self.assertIsInstance(
result_set_env, dict, "Expected a Dictionary from set_env_toml"
)
self.assertTrue(result_set_env is self.env, "Expected the same reference")
# Check for changes after calling
self.assertEqual(
result_set_env["EXE"],
Expand Down Expand Up @@ -298,9 +288,7 @@ def test_build_command_nofile(self):
)
self.assertTrue(vars(result).get("config"), "Expected a value for --config")
result_set_env = gamelauncher.set_env_toml(self.env, result)
self.assertIsInstance(
result_set_env, dict, "Expected a Dictionary from set_env_toml"
)
self.assertTrue(result_set_env is self.env, "Expected the same reference")
# Check for changes after calling
self.assertEqual(
result_set_env["EXE"],
Expand Down Expand Up @@ -376,9 +364,7 @@ def test_build_command_toml(self):
)
self.assertTrue(vars(result).get("config"), "Expected a value for --config")
result_set_env = gamelauncher.set_env_toml(self.env, result)
self.assertIsInstance(
result_set_env, dict, "Expected a Dictionary from set_env_toml"
)
self.assertTrue(result_set_env is self.env, "Expected the same reference")
# Check for changes after calling
self.assertEqual(
result_set_env["EXE"],
Expand Down Expand Up @@ -460,9 +446,7 @@ def test_build_command(self):
result_args, Namespace, "parse_args did not return a Namespace"
)
result_check_env = gamelauncher.check_env(self.env)
self.assertIsInstance(
result_check_env, dict, "Expected a Dictionary from set_env_toml"
)
self.assertTrue(result_check_env is self.env, "Expected the same reference")
self.assertEqual(
self.env["WINEPREFIX"], self.test_file, "Expected WINEPREFIX to be set"
)
Expand Down Expand Up @@ -520,6 +504,9 @@ def test_build_command(self):
self.env, test_command, self.test_verb
)
self.assertIsInstance(test_command, list, "Expected a List from build_command")
self.assertEqual(
len(test_command), 7, "Expected 7 elements in the list from build_command"
)
# Verify contents
entry_point, opt1, verb, opt2, proton, verb2, exe = [*test_command]
# The entry point dest could change. Just check if there's a value
Expand Down Expand Up @@ -822,9 +809,7 @@ def test_set_env_toml_paths(self):
)
self.assertTrue(vars(result).get("config"), "Expected a value for --config")
result_set_env = gamelauncher.set_env_toml(self.env, result)
self.assertIsInstance(
result_set_env, dict, "Expected a Dictionary from set_env_toml"
)
self.assertTrue(result_set_env is self.env, "Expected the same reference")
# Check that the paths are still in the unexpanded form
# In main, we only expand them after this function exits to prepare for building the command
self.assertEqual(
Expand Down Expand Up @@ -875,9 +860,7 @@ def test_set_env_toml(self):
)
self.assertTrue(vars(result).get("config"), "Expected a value for --config")
result_set_env = gamelauncher.set_env_toml(self.env, result)
self.assertIsInstance(
result_set_env, dict, "Expected a Dictionary from set_env_toml"
)
self.assertTrue(result_set_env is self.env, "Expected the same reference")

def test_set_env_exe_nofile(self):
"""Test set_env when setting no options via --options and appending options to --exe.
Expand Down Expand Up @@ -905,9 +888,7 @@ def test_set_env_exe_nofile(self):
result_args, Namespace, "parse_args did not return a Namespace"
)
result_check_env = gamelauncher.check_env(self.env)
self.assertIsInstance(
result_check_env, dict, "Expected a Dictionary from check_env"
)
self.assertTrue(result_check_env is self.env, "Expected the same reference")
self.assertEqual(
self.env["WINEPREFIX"], self.test_file, "Expected WINEPREFIX to be set"
)
Expand All @@ -918,9 +899,7 @@ def test_set_env_exe_nofile(self):
self.env["PROTONPATH"], self.test_file, "Expected PROTONPATH to be set"
)
result_set_env = gamelauncher.set_env(self.env, result_args)
self.assertIsInstance(
result_set_env, dict, "Expected a Dictionary from set_env"
)
self.assertTrue(result_set_env is self.env, "Expected the same reference")
self.assertEqual(
self.env["EXE"],
self.test_exe + " foo",
Expand Down Expand Up @@ -960,9 +939,7 @@ def test_set_env_opts_nofile(self):
result_args, Namespace, "parse_args did not return a Namespace"
)
result_check_env = gamelauncher.check_env(self.env)
self.assertIsInstance(
result_check_env, dict, "Expected a Dictionary from check_env"
)
self.assertTrue(result_check_env is self.env, "Expected the same reference")
self.assertEqual(
self.env["WINEPREFIX"], self.test_file, "Expected WINEPREFIX to be set"
)
Expand All @@ -973,9 +950,7 @@ def test_set_env_opts_nofile(self):
self.env["PROTONPATH"], self.test_file, "Expected PROTONPATH to be set"
)
result_set_env = gamelauncher.set_env(self.env, result_args)
self.assertIsInstance(
result_set_env, dict, "Expected a Dictionary from set_env"
)
self.assertTrue(result_set_env is self.env, "Expected the same reference")
self.assertEqual(
self.env["EXE"],
self.test_exe + " " + test_opts_file,
Expand Down Expand Up @@ -1019,9 +994,7 @@ def test_set_env_opts(self):
result_args, Namespace, "parse_args did not return a Namespace"
)
result_check_env = gamelauncher.check_env(self.env)
self.assertIsInstance(
result_check_env, dict, "Expected a Dictionary from check_env"
)
self.assertTrue(result_check_env is self.env, "Expected the same reference")
self.assertEqual(
self.env["WINEPREFIX"], self.test_file, "Expected WINEPREFIX to be set"
)
Expand Down Expand Up @@ -1062,9 +1035,7 @@ def test_set_env_exe(self):
result_args, Namespace, "parse_args did not return a Namespace"
)
result_check_env = gamelauncher.check_env(self.env)
self.assertIsInstance(
result_check_env, dict, "Expected a Dictionary from check_env"
)
self.assertTrue(result_check_env is self.env, "Expected the same reference")
self.assertEqual(
self.env["WINEPREFIX"], self.test_file, "Expected WINEPREFIX to be set"
)
Expand All @@ -1075,7 +1046,7 @@ def test_set_env_exe(self):
self.env["PROTONPATH"], self.test_file, "Expected PROTONPATH to be set"
)
result = gamelauncher.set_env(self.env, result_args)
self.assertIsInstance(result, dict, "Expected a Dictionary from set_env")
self.assertTrue(result is self.env, "Expected the same reference")
self.assertTrue(self.env.get("EXE"), "Expected EXE to not be empty")

def test_set_env(self):
Expand All @@ -1098,9 +1069,7 @@ def test_set_env(self):
result_args = gamelauncher.parse_args()
self.assertIsInstance(result_args, Namespace)
result_check_env = gamelauncher.check_env(self.env)
self.assertIsInstance(
result_check_env, dict, "Expected a Dictionary from check_env"
)
self.assertTrue(result_check_env is self.env, "Expected the same reference")
self.assertEqual(
self.env["WINEPREFIX"], self.test_file, "Expected WINEPREFIX to be set"
)
Expand All @@ -1111,7 +1080,7 @@ def test_set_env(self):
self.env["PROTONPATH"], self.test_file, "Expected PROTONPATH to be set"
)
result = gamelauncher.set_env(self.env, result_args)
self.assertIsInstance(result, dict, "Expected a Dictionary from set_env")
self.assertTrue(result is self.env, "Expected the same reference")

def test_setup_pfx_symlinks(self):
"""Test _setup_pfx for valid symlinks.
Expand Down Expand Up @@ -1320,7 +1289,7 @@ def test_env_vars_paths(self):
os.environ["GAMEID"] = self.test_file
os.environ["PROTONPATH"] = unexpanded_path
result = gamelauncher.check_env(self.env)
self.assertIsInstance(result, dict, "Expected a Dictionary from set_env_toml")
self.assertTrue(result is self.env, "Expected the same reference")
self.assertEqual(
self.env["WINEPREFIX"], unexpanded_path, "Expected WINEPREFIX to be set"
)
Expand All @@ -1338,7 +1307,7 @@ def test_env_vars(self):
os.environ["GAMEID"] = self.test_file
os.environ["PROTONPATH"] = self.test_file
result = gamelauncher.check_env(self.env)
self.assertIsInstance(result, dict, "Expected a Dictionary from set_env_toml")
self.assertTrue(result is self.env, "Expected the same reference")
self.assertEqual(
self.env["WINEPREFIX"], self.test_file, "Expected WINEPREFIX to be set"
)
Expand Down

0 comments on commit a8f3e26

Please sign in to comment.