File: test_integration.py

package info (click to toggle)
python-msgspec 0.19.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 6,356 kB
  • sloc: javascript: 23,944; ansic: 20,540; python: 20,465; makefile: 29; sh: 19
file content (38 lines) | stat: -rw-r--r-- 914 bytes parent folder | download
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
34
35
36
37
38
import datetime
import sys

import pytest

import msgspec


@pytest.fixture(params=["json", "msgpack"])
def proto(request):
    if request.param == "json":
        return msgspec.json
    elif request.param == "msgpack":
        return msgspec.msgpack


def test_decode_naive_datetime(proto):
    """See https://github.com/jcrist/msgspec/issues/408"""
    dt = datetime.datetime(2001, 2, 3, 4, 5, 6, 7)
    msg = proto.encode(dt)

    start = sys.getrefcount(None)
    for _ in range(1000):
        proto.decode(msg, type=datetime.datetime)
    end = sys.getrefcount(None)
    assert start == end


def test_decode_naive_time(proto):
    """See https://github.com/jcrist/msgspec/issues/408"""
    dt = datetime.time(12, 20)
    msg = proto.encode(dt)

    start = sys.getrefcount(None)
    for _ in range(1000):
        proto.decode(msg, type=datetime.time)
    end = sys.getrefcount(None)
    assert start == end