parent
4190c9ee0f
commit
99b85c5006
|
@ -258,7 +258,7 @@ public class PythonTypes {
|
|||
return ret;
|
||||
}else if (javaObject instanceof byte[]){
|
||||
byte[] arr = (byte[]) javaObject;
|
||||
for (int x : arr) ret.add(x);
|
||||
for (int x : arr) ret.add(x & 0xff);
|
||||
return ret;
|
||||
} else if (javaObject instanceof long[]) {
|
||||
long[] arr = (long[]) javaObject;
|
||||
|
|
|
@ -81,16 +81,31 @@ public class PythonPrimitiveTypesTest {
|
|||
}
|
||||
@Test
|
||||
public void testBytes() {
|
||||
byte[] bytes = new byte[256];
|
||||
for (int i = 0; i < 256; i++) {
|
||||
bytes[i] = (byte) i;
|
||||
}
|
||||
List<PythonVariable> inputs = new ArrayList<>();
|
||||
inputs.add(new PythonVariable<>("b1", PythonTypes.BYTES, bytes));
|
||||
List<PythonVariable> outputs = new ArrayList<>();
|
||||
outputs.add(new PythonVariable<>("b2", PythonTypes.BYTES));
|
||||
String code = "b2=b1";
|
||||
PythonExecutioner.exec(code, inputs, outputs);
|
||||
Assert.assertArrayEquals(bytes, (byte[]) outputs.get(0).getValue());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBytes2() {
|
||||
byte[] bytes = new byte[]{97, 98, 99};
|
||||
List<PythonVariable> inputs = new ArrayList<>();
|
||||
inputs.add(new PythonVariable<>("buff", PythonTypes.BYTES, bytes));
|
||||
inputs.add(new PythonVariable<>("b1", PythonTypes.BYTES, bytes));
|
||||
List<PythonVariable> outputs = new ArrayList<>();
|
||||
outputs.add(new PythonVariable<>("s1", PythonTypes.STR));
|
||||
outputs.add(new PythonVariable<>("buff2", PythonTypes.BYTES));
|
||||
String code = "s1 = ''.join(chr(c) for c in buff)\nbuff2=b'def'";
|
||||
outputs.add(new PythonVariable<>("b2", PythonTypes.BYTES));
|
||||
String code = "s1 = ''.join(chr(c) for c in b1)\nb2=b'def'";
|
||||
PythonExecutioner.exec(code, inputs, outputs);
|
||||
Assert.assertEquals("abc", outputs.get(0).getValue());
|
||||
Assert.assertArrayEquals(new byte[]{100, 101, 102}, (byte[])outputs.get(1).getValue());
|
||||
Assert.assertArrayEquals(new byte[]{100, 101, 102}, (byte[]) outputs.get(1).getValue());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue