File: test_json_matchers.py

package info (click to toggle)
python-syrupy 4.9.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 4,368 kB
  • sloc: python: 5,978; makefile: 3
file content (31 lines) | stat: -rw-r--r-- 719 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
import datetime
import random

import pytest

from syrupy.extensions.json import JSONSnapshotExtension
from syrupy.matchers import path_type


@pytest.fixture
def snapshot_json(snapshot):
    return snapshot.use_extension(JSONSnapshotExtension)


def test_matcher(snapshot_json):
    content = {
        "int": random.randint(1, 100),
        "date": datetime.datetime.utcnow(),
        "foo": {
            "x": "y",
            "another_date": datetime.datetime.utcnow(),
        },
    }
    matcher = path_type(
        {
            "int": (int,),
            "date": (datetime.date,),
            "foo.another_date": (dict, datetime.datetime),
        }
    )
    assert snapshot_json(matcher=matcher) == content