Skip to content

Commit 2304cfd

Browse files
author
Release Manager
committed
gh-38826: src/sage/env.py: canonicalize paths in a test A test in sage.env is running sage in a subprocess to compare the values of `SAGE_ROOT` and `SAGE_LOCAL`. It does the comparison as strings, however, and can fail: ``` File "src/sage/env.py", line 14, in sage.env Failed example: out == repr((SAGE_ROOT, SAGE_LOCAL)) # long time Expected: True Got: False ``` This despite the fact that both values are equivalent: ``` sage: out "('/home/mjo/src/sage.git/src/sage/../..', '/usr')" sage: repr((SAGE_ROOT, SAGE_LOCAL)) "('/home/mjo/src/sage.git', '/usr')" ``` We update the test to canonicalize the paths within the subprocess, and output only "True" or "False" instead. URL: #38826 Reported by: Michael Orlitzky Reviewer(s): Tobias Diez
2 parents 3232e30 + 53a6d31 commit 2304cfd

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

src/sage/env.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,14 @@
88
99
sage: env = {k:v for (k,v) in os.environ.items() if not k.startswith("SAGE_")}
1010
sage: from subprocess import check_output
11-
sage: environment = "sage.all"
12-
sage: cmd = f"from {environment} import SAGE_ROOT, SAGE_LOCAL; print((SAGE_ROOT, SAGE_LOCAL))"
11+
sage: module_name = "sage.all" # hide .all import from the linter
12+
sage: cmd = f"from {module_name} import SAGE_ROOT, SAGE_LOCAL;"
13+
sage: cmd += "from os.path import samefile;"
14+
sage: cmd += f"s1 = samefile(SAGE_ROOT, '{SAGE_ROOT}');"
15+
sage: cmd += f"s2 = samefile(SAGE_LOCAL, '{SAGE_LOCAL}');"
16+
sage: cmd += "print(s1 and s2);"
1317
sage: out = check_output([sys.executable, "-c", cmd], env=env).decode().strip() # long time
14-
sage: out == repr((SAGE_ROOT, SAGE_LOCAL)) # long time
18+
sage: out == "True" # long time
1519
True
1620
1721
AUTHORS:

0 commit comments

Comments
 (0)