File: test_fake.py

package info (click to toggle)
python-orjson 3.10.7-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 4,180 kB
  • sloc: ansic: 11,270; python: 6,658; sh: 135; makefile: 9
file content (50 lines) | stat: -rw-r--r-- 1,116 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
39
40
41
42
43
44
45
46
47
48
49
50
# SPDX-License-Identifier: (Apache-2.0 OR MIT)

import random

import pytest

import orjson

try:
    from faker import Faker
except ImportError:
    Faker = None  # type: ignore

NUM_LOOPS = 10
NUM_SHUFFLES = 10
NUM_ENTRIES = 250

FAKER_LOCALES = [
    "ar_AA",
    "fi_FI",
    "fil_PH",
    "he_IL",
    "ja_JP",
    "th_TH",
    "tr_TR",
    "uk_UA",
    "vi_VN",
]


class TestFaker:
    @pytest.mark.skipif(Faker is None, reason="faker not available")
    def test_faker(self):
        fake = Faker(FAKER_LOCALES)
        profile_keys = list(
            set(fake.profile().keys()) - {"birthdate", "current_location"}
        )
        for _ in range(0, NUM_LOOPS):
            data = [
                {
                    "person": fake.profile(profile_keys),
                    "emoji": fake.emoji(),
                    "text": fake.paragraphs(),
                }
                for _ in range(0, NUM_ENTRIES)
            ]
            for _ in range(0, NUM_SHUFFLES):
                random.shuffle(data)
                output = orjson.dumps(data)
                assert orjson.loads(output) == data