forked from ijl/orjson
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_fake.py
50 lines (42 loc) · 1.09 KB
/
test_fake.py
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