From 7296e5c021450743e5fe824e94b830a73eebc4c8 Mon Sep 17 00:00:00 2001 From: Eliah Kagan Date: Thu, 7 Sep 2023 06:36:34 -0400 Subject: [PATCH] Make test helper script a file, for readability --- test/fixtures/env_case.py | 13 +++++++++++++ test/test_git.py | 14 +++++--------- 2 files changed, 18 insertions(+), 9 deletions(-) create mode 100644 test/fixtures/env_case.py diff --git a/test/fixtures/env_case.py b/test/fixtures/env_case.py new file mode 100644 index 000000000..120e59289 --- /dev/null +++ b/test/fixtures/env_case.py @@ -0,0 +1,13 @@ +import subprocess +import sys + +import git + + +_, working_dir, env_var_name = sys.argv + +# Importing git should be enough, but this really makes sure Git.execute is called. +repo = git.Repo(working_dir) # Hold the reference. +git.Git(repo.working_dir).execute(["git", "version"]) + +print(subprocess.check_output(["set", env_var_name], shell=True, text=True)) diff --git a/test/test_git.py b/test/test_git.py index 8ed9b64fe..804cd22e4 100644 --- a/test/test_git.py +++ b/test/test_git.py @@ -112,16 +112,12 @@ def test_it_avoids_upcasing_unrelated_environment_variable_names(self): raise RuntimeError("test bug or strange locale: old_name invariant under upcasing") os.putenv(old_name, "1") # It has to be done this lower-level way to set it lower-case. - script_lines = [ - "import subprocess, git", - - # Importing git should be enough, but this really makes sure Git.execute is called. - f"repo = git.Repo({self.rorepo.working_dir!r})", - "git.Git(repo.working_dir).execute(['git', 'version'])", - - f"print(subprocess.check_output(['set', {old_name!r}], shell=True, text=True))", + cmdline = [ + sys.executable, + fixture_path("env_case.py"), + self.rorepo.working_dir, + old_name, ] - cmdline = [sys.executable, "-c", "\n".join(script_lines)] pair_text = subprocess.check_output(cmdline, shell=False, text=True) new_name = pair_text.split("=")[0] self.assertEqual(new_name, old_name)