Skip to content

Commit

Permalink
faker
Browse files Browse the repository at this point in the history
  • Loading branch information
ijl committed May 23, 2023
1 parent 563c4ac commit 2c6e81a
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 0 deletions.
1 change: 1 addition & 0 deletions test/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
arrow
faker
numpy;(platform_machine=="x86_64" or (platform_machine=="aarch64" and sys_platform == "linux")) and python_version>"3.7" and python_version<"3.12"
pendulum;sys_platform=="linux" and platform_machine=="x86_64" and python_version<"3.12"
psutil;(sys_platform=="linux" or sys_platform == "macos") and platform_machine=="x86_64"
Expand Down
50 changes: 50 additions & 0 deletions test/test_fake.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,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 = tuple(
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

0 comments on commit 2c6e81a

Please sign in to comment.