Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ef79a85
commit f41535b
Showing
3 changed files
with
67 additions
and
67 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,35 @@ | ||
from typing import Callable | ||
|
||
from mimesis.locales import Locale | ||
from mimesis.schema import Field | ||
|
||
try: | ||
import pytest | ||
except ImportError: | ||
raise ImportError("pytest is required to use this plugin") | ||
|
||
_CacheCallable = Callable[[Locale], Field] | ||
|
||
|
||
@pytest.fixture(scope="session") | ||
def _mimesis_cache() -> _CacheCallable: | ||
cached_instances: dict[Locale, Field] = {} | ||
|
||
def factory(locale: Locale) -> Field: | ||
if locale not in cached_instances: | ||
cached_instances[locale] = Field(locale) | ||
return cached_instances[locale] | ||
|
||
return factory | ||
|
||
|
||
@pytest.fixture() | ||
def mimesis_locale() -> Locale: | ||
"""Specifies which locale to use.""" | ||
return Locale.DEFAULT | ||
|
||
|
||
@pytest.fixture() | ||
def mimesis(_mimesis_cache: _CacheCallable, mimesis_locale: Locale) -> Field: | ||
"""Mimesis fixture to provide fake data using all built-in providers.""" | ||
return _mimesis_cache(mimesis_locale) | ||
# from typing import Callable | ||
# | ||
# from mimesis.locales import Locale | ||
# from mimesis.schema import Field | ||
# | ||
# try: | ||
# import pytest | ||
# except ImportError: | ||
# raise ImportError("pytest is required to use this plugin") | ||
# | ||
# _CacheCallable = Callable[[Locale], Field] | ||
# | ||
# | ||
# @pytest.fixture(scope="session") | ||
# def _mimesis_cache() -> _CacheCallable: | ||
# cached_instances: dict[Locale, Field] = {} | ||
# | ||
# def factory(locale: Locale) -> Field: | ||
# if locale not in cached_instances: | ||
# cached_instances[locale] = Field(locale) | ||
# return cached_instances[locale] | ||
# | ||
# return factory | ||
# | ||
# | ||
# @pytest.fixture() | ||
# def mimesis_locale() -> Locale: | ||
# """Specifies which locale to use.""" | ||
# return Locale.DEFAULT | ||
# | ||
# | ||
# @pytest.fixture() | ||
# def mimesis(_mimesis_cache: _CacheCallable, mimesis_locale: Locale) -> Field: | ||
# """Mimesis fixture to provide fake data using all built-in providers.""" | ||
# return _mimesis_cache(mimesis_locale) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,30 @@ | ||
import string | ||
|
||
import pytest | ||
|
||
from mimesis.locales import Locale | ||
|
||
|
||
def test_locale(mimesis_locale, mimesis): | ||
assert mimesis_locale == Locale.DEFAULT | ||
assert mimesis._generic.locale == Locale.DEFAULT | ||
|
||
|
||
@pytest.mark.parametrize("mimesis_locale", [Locale.DE]) | ||
def test_locale_override(mimesis_locale, mimesis): | ||
assert mimesis_locale == Locale.DE | ||
assert mimesis._generic.locale == Locale.DE | ||
|
||
|
||
def test_mimesis_fixture(mimesis): | ||
assert mimesis("birthdate", min_year=2023, max_year=2023).year == 2023 | ||
assert len(mimesis("full_name").split(" ")) > 1 | ||
|
||
|
||
@pytest.mark.parametrize("mimesis_locale", [Locale.RU]) | ||
def test_mimesis_fixture_with_overridden_locale(mimesis, mimesis_locale): | ||
assert mimesis._generic.locale == Locale.RU | ||
|
||
name = mimesis("full_name") | ||
for letter in name: # russian letters are not in ASCII: | ||
assert letter not in string.ascii_letters | ||
# import string | ||
# | ||
# import pytest | ||
# | ||
# from mimesis.locales import Locale | ||
# | ||
# | ||
# def test_locale(mimesis_locale, mimesis): | ||
# assert mimesis_locale == Locale.DEFAULT | ||
# assert mimesis._generic.locale == Locale.DEFAULT | ||
# | ||
# | ||
# @pytest.mark.parametrize("mimesis_locale", [Locale.DE]) | ||
# def test_locale_override(mimesis_locale, mimesis): | ||
# assert mimesis_locale == Locale.DE | ||
# assert mimesis._generic.locale == Locale.DE | ||
# | ||
# | ||
# def test_mimesis_fixture(mimesis): | ||
# assert mimesis("birthdate", min_year=2023, max_year=2023).year == 2023 | ||
# assert len(mimesis("full_name").split(" ")) > 1 | ||
# | ||
# | ||
# @pytest.mark.parametrize("mimesis_locale", [Locale.RU]) | ||
# def test_mimesis_fixture_with_overridden_locale(mimesis, mimesis_locale): | ||
# assert mimesis._generic.locale == Locale.RU | ||
# | ||
# name = mimesis("full_name") | ||
# for letter in name: # russian letters are not in ASCII: | ||
# assert letter not in string.ascii_letters |