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 92b0ae8
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/sage/env.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,14 @@
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: module_name = "sage.all" # hide .all import from the linter
sage: cmd = "from {module_name} 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

Check failure on line 17 in src/sage/env.py

View workflow job for this annotation

GitHub Actions / test-new

Failed example:

Failed example:: Exception raised: Traceback (most recent call last): File "/sage/src/sage/doctest/forker.py", line 714, in _run self.compile_and_execute(example, compiler, test.globs) File "/sage/src/sage/doctest/forker.py", line 1144, in compile_and_execute exec(compiled, globs) File "<doctest sage.env[8]>", line 1, in <module> out = check_output([sys.executable, "-c", cmd], env=env).decode().strip() # long time File "/usr/lib/python3.10/subprocess.py", line 421, in check_output return run(*popenargs, stdout=PIPE, timeout=timeout, check=True, File "/usr/lib/python3.10/subprocess.py", line 526, in run raise CalledProcessError(retcode, process.args, subprocess.CalledProcessError: Command '['/sage/local/var/lib/sage/venv-python3.10/bin/python3', '-c', "from {module_name} import SAGE_ROOT, SAGE_LOCAL;from os.path import samefile;s1 = samefile(SAGE_ROOT, '/sage');s2 = samefile(SAGE_LOCAL, '/sage/local');print(s1 and s2);"]' returned non-zero exit status 1.
sage: out == repr((SAGE_ROOT, SAGE_LOCAL)) # long time
sage: out == "True" # long time

Check failure on line 18 in src/sage/env.py

View workflow job for this annotation

GitHub Actions / test-new

Failed example:

Failed example:: Exception raised: Traceback (most recent call last): File "/sage/src/sage/doctest/forker.py", line 714, in _run self.compile_and_execute(example, compiler, test.globs) File "/sage/src/sage/doctest/forker.py", line 1144, in compile_and_execute exec(compiled, globs) File "<doctest sage.env[9]>", line 1, in <module> out == "True" # long time NameError: name 'out' is not defined
True
AUTHORS:
Expand Down

0 comments on commit 92b0ae8

Please sign in to comment.