mirror of
https://github.com/langgenius/dify.git
synced 2026-11-11 22:02:23 +08:00
Co-authored-by: Felix Shi <204130665+shi-felix@users.noreply.github.com> Co-authored-by: Asuka Minato <i@asukaminato.eu.org>
26 lines
731 B
Python
26 lines
731 B
Python
import orjson
|
|
import pytest
|
|
|
|
from libs.orjson import orjson_dumps
|
|
|
|
|
|
def test_orjson_dumps_round_trip_basic() -> None:
|
|
obj = {"a": 1, "b": [1, 2, 3], "c": {"d": True}}
|
|
s = orjson_dumps(obj)
|
|
assert orjson.loads(s) == obj
|
|
|
|
|
|
def test_orjson_dumps_with_unicode_and_indent() -> None:
|
|
obj = {"msg": "你好,Dify"}
|
|
s = orjson_dumps(obj, option=orjson.OPT_INDENT_2)
|
|
# contains indentation newline/spaces
|
|
assert "\n" in s
|
|
assert orjson.loads(s) == obj
|
|
|
|
|
|
def test_orjson_dumps_non_utf8_encoding_fails() -> None:
|
|
obj = {"msg": "你好"}
|
|
# orjson.dumps() always produces UTF-8 bytes; decoding with non-UTF8 fails.
|
|
with pytest.raises(UnicodeDecodeError):
|
|
orjson_dumps(obj, encoding="ascii")
|