MCPcopy Index your code
hub / github.com/mongodb/mongo-python-driver / test_clamping

Method test_clamping

test/test_bson.py:1522–1540  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

1520 self.assertNotEqual(dt1, type(dec1["x"]))
1521
1522 def test_clamping(self):
1523 # Test clamping from below and above.
1524 opts = CodecOptions(
1525 datetime_conversion=DatetimeConversion.DATETIME_CLAMP,
1526 tz_aware=True,
1527 tzinfo=datetime.timezone.utc,
1528 )
1529 below = encode({"x": DatetimeMS(_datetime_to_millis(datetime.datetime.min) - 1)})
1530 dec_below = decode(below, opts)
1531 self.assertEqual(
1532 dec_below["x"], datetime.datetime.min.replace(tzinfo=datetime.timezone.utc)
1533 )
1534
1535 above = encode({"x": DatetimeMS(_datetime_to_millis(datetime.datetime.max) + 1)})
1536 dec_above = decode(above, opts)
1537 self.assertEqual(
1538 dec_above["x"],
1539 datetime.datetime.max.replace(tzinfo=datetime.timezone.utc, microsecond=999000),
1540 )
1541
1542 def test_tz_clamping_local(self):
1543 # Naive clamping to local tz.

Callers

nothing calls this directly

Calls 5

CodecOptionsClass · 0.90
encodeFunction · 0.90
DatetimeMSClass · 0.90
_datetime_to_millisFunction · 0.90
decodeFunction · 0.90

Tested by

no test coverage detected