Skip to content

Commit

Permalink
sagemathgh-38826: 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.

URL: sagemath#38826
Reported by: Michael Orlitzky
Reviewer(s): Tobias Diez
  • Loading branch information
Release Manager committed Oct 23, 2024
2 parents 47bd349 + 53a6d31 commit 7dbd4a8
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 deletions.
4 changes: 2 additions & 2 deletions build/pkgs/configure/checksums.ini
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
tarball=configure-VERSION.tar.gz
sha1=978eb775a20fea3ed9b88f0d67ecd84a3d9cd6ea
sha256=c3987bb0f8aca81e112a17d8904ef2353a706159d43250305dc2bcac4ca2e33a
sha1=79e1a7cf5a6059a27290c9674daca4674288d8da
sha256=201265adcd883a6cadf317139bb24c8dee9b276c586b61eb49ab8c4a03d789ca
2 changes: 1 addition & 1 deletion build/pkgs/configure/package-version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
4326d0d9422011034a230ab3c1445fafeb2ac444
87a7e8d4272eba438146e04000ef12fee61abb61
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 = f"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
sage: out == repr((SAGE_ROOT, SAGE_LOCAL)) # long time
sage: out == "True" # long time
True
AUTHORS:
Expand Down

0 comments on commit 7dbd4a8

Please sign in to comment.