Skip to content

Commit 00744db

Browse files
committed
Fix PYTHONIOENCODING parsing error and re-enable assertion in test_sys#test_exit
1 parent 3286cb6 commit 00744db

File tree

3 files changed

+13
-9
lines changed

3 files changed

+13
-9
lines changed

graalpython/com.oracle.graal.python.test/src/tests/unittest_tags/test_sys.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@
2727
*graalpython.lib-python.3.test.test_sys.SysModuleTest.test_refcount
2828
*graalpython.lib-python.3.test.test_sys.SysModuleTest.test_setrecursionlimit_recursion_depth
2929
*graalpython.lib-python.3.test.test_sys.SysModuleTest.test_sys_getwindowsversion_no_instantiation
30+
*graalpython.lib-python.3.test.test_sys.SysModuleTest.test_c_locale_surrogateescape
31+
*graalpython.lib-python.3.test.test_sys.SysModuleTest.test_posix_locale_surrogateescape
3032
*graalpython.lib-python.3.test.test_sys.UnraisableHookTest.test_custom_unraisablehook
3133
*graalpython.lib-python.3.test.test_sys.UnraisableHookTest.test_custom_unraisablehook_fail
3234
*graalpython.lib-python.3.test.test_sys.UnraisableHookTest.test_original_unraisablehook

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/GraalPythonModuleBuiltins.java

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -125,13 +125,16 @@ public void initialize(PythonCore core) {
125125
builtinConstants.put("is_native", TruffleOptions.AOT);
126126
PythonContext ctx = core.getContext();
127127
String encodingOpt = ctx.getLanguage().getEngineOption(PythonOptions.StandardStreamEncoding);
128-
String standardStreamEncoding;
129-
String standardStreamError;
128+
String standardStreamEncoding = null;
129+
String standardStreamError = null;
130130
if (encodingOpt != null && !encodingOpt.isEmpty()) {
131131
String[] parts = encodingOpt.split(":");
132-
standardStreamEncoding = parts[0].isEmpty() ? "utf-8" : parts[0];
133-
standardStreamError = parts.length > 1 && !parts[1].isEmpty() ? parts[1] : "strict";
134-
} else {
132+
if (parts.length > 0) {
133+
standardStreamEncoding = parts[0].isEmpty() ? "utf-8" : parts[0];
134+
standardStreamError = parts.length > 1 && !parts[1].isEmpty() ? parts[1] : "strict";
135+
}
136+
}
137+
if (standardStreamEncoding == null) {
135138
standardStreamEncoding = "utf-8";
136139
standardStreamError = "surrogateescape";
137140
}

graalpython/lib-python/3/test/test_sys.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -169,10 +169,9 @@ def check_exit_message(code, expected, **env_vars):
169169

170170
# test that the exit message is written with backslashreplace error
171171
# handler to stderr
172-
# TODO: GraalPython patch, will be fixed by proper implementation of backslashreplace handler (GR-10256)
173-
# check_exit_message(
174-
# r'import sys; sys.exit("surrogates:\uDCFF")',
175-
# b"surrogates:\\udcff")
172+
check_exit_message(
173+
r'import sys; sys.exit("surrogates:\uDCFF")',
174+
b"surrogates:\\udcff")
176175

177176
# test that the unicode message is encoded to the stderr encoding
178177
# instead of the default encoding (utf8)

0 commit comments

Comments
 (0)