Skip to content

Commit 74d9c08

Browse files
committed
Better explain the env_case test
This expands and adds comments in test_it_avoids_upcasing_unrelated_environment_variable_names and its supporting fixture env_case.py so it is clear exactly what is being tested and how/why the test works to test it.
1 parent c8e303f commit 74d9c08

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-3
lines changed

test/fixtures/env_case.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,18 @@
1+
# Steps 3 and 4 for test_it_avoids_upcasing_unrelated_environment_variable_names.
2+
13
import subprocess
24
import sys
35

6+
# Step 3a: Import the module, in case that upcases the environment variable name.
47
import git
58

69

710
_, working_dir, env_var_name = sys.argv
811

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.)
1014
repo = git.Repo(working_dir) # Hold the reference.
1115
git.Git(repo.working_dir).execute(["git", "version"])
1216

17+
# Step 4: Create the non-Python grandchild that accesses the variable case-sensitively.
1318
print(subprocess.check_output(["set", env_var_name], shell=True, text=True))

test/test_git.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,15 +98,25 @@ def test_it_avoids_upcasing_unrelated_environment_variable_names(self):
9898
old_name = "28f425ca_d5d8_4257_b013_8d63166c8158"
9999
if old_name == old_name.upper():
100100
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.
102101

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.
103112
cmdline = [
104113
sys.executable,
105114
fixture_path("env_case.py"),
106115
self.rorepo.working_dir,
107116
old_name,
108117
]
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+
110120
new_name = pair_text.split("=")[0]
111121
self.assertEqual(new_name, old_name)
112122

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy