项目文件夹

文件
wehub-resource-sync 593b94c120
pytest / Unit Tests (push) Has been cancelled
pytest / Integration (integration_tests_a) (push) Has been cancelled
pytest / Integration (integration_tests_b) (push) Has been cancelled
pytest / Integration (integration_tests_c) (push) Has been cancelled
pytest / Integration (integration_tests_d) (push) Has been cancelled
pytest / Integration (integration_tests_e) (push) Has been cancelled
pytest / Integration (integration_tests_f) (push) Has been cancelled
pytest / Integration (integration_tests_g) (push) Has been cancelled
pytest / Integration (integration_tests_h) (push) Has been cancelled
pytest / Integration (integration_tests_i) (push) Has been cancelled
pytest / Integration (integration_tests_j) (push) Has been cancelled
pytest / Distributed (distributed_a) (push) Has been cancelled
pytest / Distributed (distributed_b) (push) Has been cancelled
pytest / Distributed (distributed_c) (push) Has been cancelled
pytest / Distributed (distributed_d) (push) Has been cancelled
pytest / Distributed (distributed_e) (push) Has been cancelled
pytest / Distributed (distributed_f) (push) Has been cancelled
pytest / Minimal Install (push) Has been cancelled
pytest / Event File (push) Has been cancelled
pytest (slow) / py-slow (push) Has been cancelled
Publish JSON Schema / publish-schema (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 12:49:20 +08:00

32 行
1.2 KiB
Python

import numpy as np
from ludwig.utils.server_utils import NumpyJSONResponse
def test_numpy_json_response():
response = NumpyJSONResponse({"message": "Ludwig server is up"})
# Test Python builtin data type encoding.
assert response.render(None) == b"null"
assert response.render({}) == b"{}"
assert response.render(1) == b"1"
assert response.render(1.0) == b"1.0"
assert response.render("a") == b'"a"'
assert response.render([0, 1, 2, 3, 4]) == b"[0,1,2,3,4]"
assert response.render((0, 1, 2, 3, 4)) == b"[0,1,2,3,4]"
assert response.render({0, 1, 2, 3, 4}) == b"[0,1,2,3,4]"
assert response.render({"a": "b"}) == b'{"a":"b"}'
# Test numpy data type encoding
for dtype in [np.byte, np.ubyte, np.short, np.ushort, np.int32, np.int64, np.uint, np.longlong, np.ulonglong]:
x = np.arange(5, dtype=dtype)
assert response.render(x) == b"[0,1,2,3,4]"
for i in x:
assert response.render(i) == f"{i}".encode()
for dtype in [np.half, np.single, np.double, np.longdouble]:
x = np.arange(5, dtype=dtype)
assert response.render(x) == b"[0.0,1.0,2.0,3.0,4.0]"
for i in x:
assert response.render(i) == f"{i}".encode()