(self)
| 586 | self.assertIsInstance(doc["d"], cls) |
| 587 | |
| 588 | def test_encode_subclass(self): |
| 589 | cases: list[Tuple[Type, Any]] = [ |
| 590 | (int, (1,)), |
| 591 | (int, (2 << 60,)), |
| 592 | (float, (1.1,)), |
| 593 | (Int64, (64,)), |
| 594 | (Int64, (2 << 60,)), |
| 595 | (str, ("str",)), |
| 596 | (bytes, (b"bytes",)), |
| 597 | (datetime.datetime, (2024, 1, 16)), |
| 598 | (DatetimeMS, (1,)), |
| 599 | (uuid.UUID, ("f47ac10b-58cc-4372-a567-0e02b2c3d479",)), |
| 600 | (Binary, (b"1", USER_DEFINED_SUBTYPE)), |
| 601 | (Code, ("code",)), |
| 602 | (DBRef, ("coll", ObjectId())), |
| 603 | (ObjectId, ("65a6dab5f98bc03906ee3597",)), |
| 604 | (MaxKey, ()), |
| 605 | (MinKey, ()), |
| 606 | (Regex, ("pat",)), |
| 607 | (Timestamp, (1, 1)), |
| 608 | (Decimal128, ("0.5",)), |
| 609 | ] |
| 610 | allopts = [ |
| 611 | CANONICAL_JSON_OPTIONS.with_options(uuid_representation=STANDARD), |
| 612 | RELAXED_JSON_OPTIONS.with_options(uuid_representation=STANDARD), |
| 613 | LEGACY_JSON_OPTIONS.with_options(uuid_representation=STANDARD), |
| 614 | ] |
| 615 | for cls, args in cases: |
| 616 | basic_obj = cls(*args) |
| 617 | my_cls = type(f"My{cls.__name__}", (cls,), {}) |
| 618 | my_obj = my_cls(*args) |
| 619 | for opts in allopts: |
| 620 | expected_json = json_util.dumps(basic_obj, json_options=opts) |
| 621 | self.assertEqual(json_util.dumps(my_obj, json_options=opts), expected_json) |
| 622 | |
| 623 | def test_encode_type_marker(self): |
| 624 | # Assert that a custom subclass can be JSON encoded based on the _type_marker attribute. |
nothing calls this directly
no test coverage detected