| 1002 | self.assertIsInstance(decode(x, CodecOptions(document_class=SON))["x"][0], SON) # type: ignore[type-var] |
| 1003 | |
| 1004 | def test_subclasses(self): |
| 1005 | # make sure we can serialize subclasses of native Python types. |
| 1006 | class _myint(int): |
| 1007 | pass |
| 1008 | |
| 1009 | class _myfloat(float): |
| 1010 | pass |
| 1011 | |
| 1012 | class _myunicode(str): |
| 1013 | pass |
| 1014 | |
| 1015 | d = {"a": _myint(42), "b": _myfloat(63.9), "c": _myunicode("hello world")} |
| 1016 | d2 = decode(encode(d)) |
| 1017 | for key, value in d2.items(): |
| 1018 | orig_value = d[key] |
| 1019 | orig_type = orig_value.__class__.__bases__[0] |
| 1020 | self.assertEqual(type(value), orig_type) |
| 1021 | self.assertEqual(value, orig_type(value)) |
| 1022 | |
| 1023 | def test_encode_type_marker(self): |
| 1024 | # Assert that a custom subclass can be BSON encoded based on the _type_marker attribute. |