File: test_utf8.py

package info (click to toggle)
pymongo 4.16.0-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 23,676 kB
  • sloc: python: 107,763; ansic: 4,597; javascript: 137; makefile: 38; sh: 18
file content (33 lines) | stat: -rw-r--r-- 765 bytes parent folder | download | duplicates (3)
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()