| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent c8e303f commit 74d9c08
2 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,13 +1,18 @@ | |||
| 1 | + # Steps 3 and 4 for test_it_avoids_upcasing_unrelated_environment_variable_names. | ||
| 2 | + | ||
| 1 | 3 | import subprocess | |
| 2 | 4 | import sys | |
| 3 | 5 | ||
| 6 | + # Step 3a: Import the module, in case that upcases the environment variable name. | ||
| 4 | 7 | import git | |
| 5 | 8 | ||
| 6 | 9 | ||
| 7 | 10 | _, working_dir, env_var_name = sys.argv | |
| 8 | 11 | ||
| 9 | - # Importing git should be enough, but this really makes sure Git.execute is called. | ||
| 12 | + # Step 3b: Use Git.execute explicitly, in case that upcases the environment variable. | ||
| 13 | + # (Importing git should be enough, but this ensures Git.execute is called.) | ||
| 10 | 14 | repo = git.Repo(working_dir) # Hold the reference. | |
| 11 | 15 | git.Git(repo.working_dir).execute(["git", "version"]) | |
| 12 | 16 | ||
| 17 | + # Step 4: Create the non-Python grandchild that accesses the variable case-sensitively. | ||
| 13 | 18 | print(subprocess.check_output(["set", env_var_name], shell=True, text=True)) | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -98,15 +98,25 @@ def test_it_avoids_upcasing_unrelated_environment_variable_names(self): | |||
| 98 | 98 | old_name = "28f425ca_d5d8_4257_b013_8d63166c8158" | |
| 99 | 99 | if old_name == old_name.upper(): | |
| 100 | 100 | raise RuntimeError("test bug or strange locale: old_name invariant under upcasing") | |
| 101 | - os.putenv(old_name, "1") # It has to be done this lower-level way to set it lower-case. | ||
| 102 | 101 | ||
| 102 | + # Step 1: Set the environment variable in this parent process. Because os.putenv is a thin | ||
| 103 | + # wrapper around a system API, os.environ never sees the variable in this parent | ||
| 104 | + # process, so the name is not upcased even on Windows. | ||
| 105 | + os.putenv(old_name, "1") | ||
| 106 | + | ||
| 107 | + # Step 2: Create the child process that inherits the environment variable. It will see it | ||
| 108 | + # in os.environ with an upcased name, but if it is not mutated through os.environ | ||
| 109 | + # then it will pass it on to its own child processes with the original name. The | ||
| 110 | + # child process will use GitPython, and we are testing that it passes the variable | ||
| 111 | + # with the exact original name to its own child processes. | ||
| 103 | 112 | cmdline = [ | |
| 104 | 113 | sys.executable, | |
| 105 | 114 | fixture_path("env_case.py"), | |
| 106 | 115 | self.rorepo.working_dir, | |
| 107 | 116 | old_name, | |
| 108 | 117 | ] | |
| 109 | - pair_text = subprocess.check_output(cmdline, shell=False, text=True) | ||
| 118 | + pair_text = subprocess.check_output(cmdline, shell=False, text=True) # Steps 3 and 4. | ||
| 119 | + | ||
| 110 | 120 | new_name = pair_text.split("=")[0] | |
| 111 | 121 | self.assertEqual(new_name, old_name) | |
| 112 | 122 | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments