1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
|
from __future__ import annotations
import sys
sys.path[0:0] = [""]
from test import unittest
from bson import encode
from bson.errors import InvalidStringData
class TestUTF8(unittest.TestCase):
# Verify that python and bson have the same understanding of
# legal utf-8 if the first byte is 0xf4 (244)
def _assert_same_utf8_validation(self, data):
try:
data.decode("utf-8")
py_is_legal = True
except UnicodeDecodeError:
py_is_legal = False
try:
encode({"x": data})
bson_is_legal = True
except InvalidStringData:
bson_is_legal = False
self.assertEqual(py_is_legal, bson_is_legal, data)
if __name__ == "__main__":
unittest.main()
|