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