Skip to content

Commit

Permalink
fixes bytearray tests again (python3)
Browse files Browse the repository at this point in the history
  • Loading branch information
tito committed Dec 10, 2015
1 parent c8ede02 commit ac2324d
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion jnius/jnius_conversion.pxi
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ cdef void populate_args(JNIEnv *j_env, tuple definition_args, jvalue *j_args, ar
try:
py_str = <bytes>py_arg
j_args[index].l = j_env[0].NewStringUTF(j_env, <char *>py_str)
except UnicodeEncodeError:
except (UnicodeEncodeError, TypeError):
py_str = <bytes>py_arg.encode('utf-8')
j_args[index].l = j_env[0].NewStringUTF(j_env, <char *>py_str)
elif isinstance(py_arg, JavaClass):
Expand Down
6 changes: 3 additions & 3 deletions tests/test_bytearray.py
Original file line number Diff line number Diff line change
Expand Up @@ -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])

0 comments on commit ac2324d

Please sign in to comment.