You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

test_orjson.py 707B

12345678910111213141516171819202122232425
  1. import orjson
  2. import pytest
  3. from libs.orjson import orjson_dumps
  4. def test_orjson_dumps_round_trip_basic():
  5. obj = {"a": 1, "b": [1, 2, 3], "c": {"d": True}}
  6. s = orjson_dumps(obj)
  7. assert orjson.loads(s) == obj
  8. def test_orjson_dumps_with_unicode_and_indent():
  9. obj = {"msg": "你好,Dify"}
  10. s = orjson_dumps(obj, option=orjson.OPT_INDENT_2)
  11. # contains indentation newline/spaces
  12. assert "\n" in s
  13. assert orjson.loads(s) == obj
  14. def test_orjson_dumps_non_utf8_encoding_fails():
  15. obj = {"msg": "你好"}
  16. # orjson.dumps() always produces UTF-8 bytes; decoding with non-UTF8 fails.
  17. with pytest.raises(UnicodeDecodeError):
  18. orjson_dumps(obj, encoding="ascii")