MCPcopy
hub / github.com/pyodide/pyodide / test_zerod_buffers

Function test_zerod_buffers

packages/test-buffer/test_buffer.py:7–94  ·  view source on GitHub ↗
(selenium)

Source from the content-addressed store, hash-verified

5@pytest.mark.requires_dynamic_linking
6@run_in_pyodide(packages=["test-buffer"])
7def test_zerod_buffers(selenium):
8 from buffer_test import ZeroDBuffer
9
10 from pyodide.ffi import to_js
11
12 int8Buf = ZeroDBuffer("b", bytes([((~18) & 255) + 1]))
13 jsInt8Buf = to_js(int8Buf)
14 assert jsInt8Buf.constructor.name == "Int8Array"
15 assert jsInt8Buf.length == 1
16 assert jsInt8Buf.byteLength == 1
17 assert jsInt8Buf[0] == -18
18
19 uint8Buf = ZeroDBuffer("B", bytes([130]))
20 jsUint8Buf = to_js(uint8Buf)
21 assert jsUint8Buf.constructor.name == "Uint8Array"
22 assert jsUint8Buf.length == 1
23 assert jsUint8Buf.byteLength == 1
24 assert jsUint8Buf[0] == 130
25
26 int16Buf = ZeroDBuffer("h", bytes([18, 2]))
27 jsInt16Buf = to_js(int16Buf)
28 assert jsInt16Buf.constructor.name == "Int16Array"
29 assert jsInt16Buf.length == 1
30 assert jsInt16Buf.byteLength == 2
31 assert jsInt16Buf[0] == 18 + 2 * 256
32
33 uint16Buf = ZeroDBuffer("H", bytes([18, 2]))
34 jsUint16Buf = to_js(uint16Buf)
35 assert jsUint16Buf.constructor.name == "Uint16Array"
36 assert jsUint16Buf.length == 1
37 assert jsUint16Buf.byteLength == 2
38 assert jsUint16Buf[0] == 18 + 2 * 256
39
40 int32Buf = ZeroDBuffer("i", bytes([18, 2, 0, 1]))
41 jsInt32Buf = to_js(int32Buf)
42 assert jsInt32Buf.constructor.name == "Int32Array"
43 assert jsInt32Buf.length == 1
44 assert jsInt32Buf.byteLength == 4
45 assert jsInt32Buf[0] == 18 + 2 * 256 + 1 * 256 * 256 * 256
46
47 uint32Buf = ZeroDBuffer("I", bytes([18, 2, 0, 1]))
48 jsUint32Buf = to_js(uint32Buf)
49 assert jsUint32Buf.constructor.name == "Uint32Array"
50 assert jsUint32Buf.length == 1
51 assert jsUint32Buf.byteLength == 4
52 assert jsUint32Buf[0] == 18 + 2 * 256 + 1 * 256 * 256 * 256
53
54 int64Buf = ZeroDBuffer("q", bytes([18, 2, 0, 1, 0, 0, 0, 1]))
55 jsInt64Buf = to_js(int64Buf)
56 assert jsInt64Buf.constructor.name == "BigInt64Array"
57 assert jsInt64Buf.length == 1
58 assert jsInt64Buf.byteLength == 8
59 assert jsInt64Buf[0] == 18 + 2 * 256 + 1 * 256 * 256 * 256 + pow(256, 7)
60
61 uint64Buf = ZeroDBuffer("Q", bytes([18, 2, 0, 1, 0, 0, 0, 1]))
62 jsUint64Buf = to_js(uint64Buf)
63 assert jsUint64Buf.constructor.name == "BigUint64Array"
64 assert jsUint64Buf.length == 1

Callers

nothing calls this directly

Calls 1

to_jsFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…