summary refs log tree commit diff
path: root/pkgs/applications/science/math/sage/patches/python3-syntax-without-write.patch
blob: ff1dcd22acf3d9921a40fc964091d02545fb8f25 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
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,