Skip to content

Commit

Permalink
src/sage/env.py: canonicalize paths in a test
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
orlitzky committed Oct 19, 2024
1 parent 7726cd9 commit ad85362
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/sage/env.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,13 @@
sage: env = {k:v for (k,v) in os.environ.items() if not k.startswith("SAGE_")}
sage: from subprocess import check_output
sage: environment = "sage.all"
sage: cmd = f"from {environment} import SAGE_ROOT, SAGE_LOCAL; print((SAGE_ROOT, SAGE_LOCAL))"
sage: cmd = "from sage.all import SAGE_ROOT, SAGE_LOCAL;"
sage: cmd += "from os.path import samefile;"
sage: cmd += f"s1 = samefile(SAGE_ROOT, '{SAGE_ROOT}');"
sage: cmd += f"s2 = samefile(SAGE_LOCAL, '{SAGE_LOCAL}');"
sage: cmd += "print(s1 and s2);"
sage: out = check_output([sys.executable, "-c", cmd], env=env).decode().strip() # long time
sage: out == repr((SAGE_ROOT, SAGE_LOCAL)) # long time
sage: out == "True" # long time
True
AUTHORS:
Expand Down

0 comments on commit ad85362

Please sign in to comment.