From ac2324d96ef613bf0fcc519046a2d5b7d39c7317 Mon Sep 17 00:00:00 2001 From: Mathieu Virbel Date: Thu, 10 Dec 2015 14:14:48 +0100 Subject: [PATCH] fixes bytearray tests again (python3) --- jnius/jnius_conversion.pxi | 2 +- tests/test_bytearray.py | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/jnius/jnius_conversion.pxi b/jnius/jnius_conversion.pxi index 0eb98d18..f01bba25 100644 --- a/jnius/jnius_conversion.pxi +++ b/jnius/jnius_conversion.pxi @@ -60,7 +60,7 @@ cdef void populate_args(JNIEnv *j_env, tuple definition_args, jvalue *j_args, ar try: py_str = py_arg j_args[index].l = j_env[0].NewStringUTF(j_env, py_str) - except UnicodeEncodeError: + except (UnicodeEncodeError, TypeError): py_str = py_arg.encode('utf-8') j_args[index].l = j_env[0].NewStringUTF(j_env, py_str) elif isinstance(py_arg, JavaClass): diff --git a/tests/test_bytearray.py b/tests/test_bytearray.py index 733a66aa..d8bbc91c 100644 --- a/tests/test_bytearray.py +++ b/tests/test_bytearray.py @@ -29,13 +29,13 @@ def test_create_bytearray(self): nis = StringBufferInputStream("Hello world") barr = bytearray("\x00" * 5, encoding="utf8") self.assertEquals(nis.read(barr, 0, 5), 5) - self.assertEquals(barr, "Hello") + self.assertEquals(barr, b"Hello") def test_bytearray_ascii(self): ByteArrayInputStream = autoclass('java.io.ByteArrayInputStream') - s = "".join(chr(x) for x in range(256)) + s = b"".join(bytes(x) for x in range(256)) nis = ByteArrayInputStream(s) barr = bytearray("\x00" * 256, encoding="ascii") self.assertEquals(nis.read(barr, 0, 256), 256) - self.assertEquals(barr, s) + self.assertEquals(barr[:256], s[:256])