Skip to content

Commit 99b4975

Browse files
committed
Fixed tests that were writing strings to binary streams
1 parent ae11419 commit 99b4975

File tree

3 files changed

+8
-14
lines changed

3 files changed

+8
-14
lines changed

graalpython/com.oracle.graal.python.cext/src/object.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -372,9 +372,9 @@ int PyObject_Print(PyObject* object, FILE* fd, int flags) {
372372
int f = fileno(fd);
373373
PyTuple_SetItem(args, 0, PyLong_FromLong(f));
374374
kwargs = PyDict_New();
375-
int buffering = 0;
375+
int buffering = 1;
376376
PyDict_SetItemString(kwargs, "buffering", PyLong_FromLong(buffering));
377-
PyDict_SetItemString(kwargs, "mode", polyglot_from_string("wb", SRC_CS));
377+
PyDict_SetItemString(kwargs, "mode", polyglot_from_string("w", SRC_CS));
378378
file = PyObject_Call(openFunc, args, kwargs);
379379

380380
printfunc = UPCALL_CEXT_O(_jls_PyTruffle_GetBuiltin, polyglot_from_string("print", SRC_CS));

graalpython/com.oracle.graal.python.test/src/com/oracle/graal/python/test/module/PosixTest.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -140,17 +140,17 @@ public void lseek() throws IOException {
140140
@Test
141141
public void write() throws IOException {
142142
assertPrints("", open("posix.O_RDWR") +
143-
"posix.write(fd, 'hello')");
143+
"posix.write(fd, b'hello')");
144144
assertTrue(new String(Files.readAllBytes(tmpfile)).equals("hello"));
145145
}
146146

147147
@Test
148148
public void close() throws IOException {
149149
assertLastLineErrorContains("OSError",
150150
open("posix.O_RDWR") +
151-
"posix.write(fd, 'hello')\n" +
151+
"posix.write(fd, b'hello')\n" +
152152
"posix.close(fd)\n" +
153-
"posix.write(fd, 'world')");
153+
"posix.write(fd, b'world')");
154154
assertTrue(new String(Files.readAllBytes(tmpfile)).equals("hello"));
155155
}
156156

@@ -179,7 +179,7 @@ public void printToFile() throws IOException {
179179
assertPrints("", open("posix.O_CREAT") +
180180
"import _io\n" +
181181
"f = _io.FileIO(fd, mode='w')\n" +
182-
"print('hello', file=f)");
182+
"print('hello', file=_io.TextIOWrapper(f))");
183183
assertEquals("hello\n", new String(Files.readAllBytes(tmpfile)));
184184
}
185185

graalpython/com.oracle.graal.python.test/src/tests/cpyext/__init__.py

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -341,10 +341,7 @@ def create_module(self, name=None):
341341
code = self.template.format(**fargs)
342342

343343
with open("%s/%s.c" % (__dir__, self.name), "wb", buffering=0) as f:
344-
if GRAALPYTHON:
345-
f.write(code)
346-
else:
347-
f.write(bytes(code, 'utf-8'))
344+
f.write(bytes(code, 'utf-8'))
348345

349346
def _insert(self, d, name, default_value):
350347
d[name] = d.get(name, default_value)
@@ -597,10 +594,7 @@ def CPyExtType(name, code, **kwargs):
597594

598595
source_file = "%s/%s.c" % (__dir__, name)
599596
with open(source_file, "wb", buffering=0) as f:
600-
if GRAALPYTHON:
601-
f.write(c_source)
602-
else:
603-
f.write(bytes(c_source, 'utf-8'))
597+
f.write(bytes(c_source, 'utf-8'))
604598

605599
# ensure file was really written
606600
try:

0 commit comments

Comments
 (0)