1
0
Fork 1
mirror of https://github.com/NixOS/nixpkgs.git synced 2024-12-25 03:17:13 +00:00
nixpkgs/pkgs/applications/science/math/sage/patches/python3-syntax-without-write.patch

41 lines
1.4 KiB
Diff
Raw Normal View History

2018-04-24 22:53:36 +01:00
diff --git a/src/sage/tests/py3_syntax.py b/src/sage/tests/py3_syntax.py
index e564860b48..86ab3725f9 100644
--- a/src/sage/tests/py3_syntax.py
+++ b/src/sage/tests/py3_syntax.py
@@ -179,15 +179,30 @@ class Python3SyntaxTest(SortedDirectoryWalkerABC):
sage: py3_syntax = Python3SyntaxTest()
sage: py3_syntax.test(src.name)
Invalid Python 3 syntax found:
- File "...py", line 1
- print "invalid print statement"
- ^
- SyntaxError: Missing parentheses in call to 'print'
+ Missing parentheses in call to 'print'...
sage: os.unlink(src.name)
"""
+
+ # compile all given files in memory, printing all errors
+ # inspired by the py_compile module (but without writing to file)
+ script = """
+import sys
+import importlib.machinery
+rv = 0
+for file in sys.argv[1:]:
+ loader = importlib.machinery.SourceFileLoader('<sage_test>', file)
+ source_bytes = loader.get_data(file)
+ try:
+ code = loader.source_to_code(source_bytes, file)
+ except Exception as err:
+ print(err)
+ rv = 1
+sys.exit(rv)
+"""
cmd = [
'python3',
- '-m', 'py_compile'
+ '-c',
+ script,
] + list(filenames)
process = subprocess.Popen(
cmd,