Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

👷 Remove pytest-lazy-fixture package usage #298

Merged
merged 1 commit into from
Sep 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ test = [
"pydantic >=2",
"pytest ==7.4.3",
"pytest-cov ==5.0.0",
"pytest-lazy-fixture ==0.6.3",
"mypy ==1.11.2",
"flake8 ==7.1.1",
"black ==24.8.0",
Expand Down
51 changes: 30 additions & 21 deletions tests/test_loaders/test_common.py
Original file line number Diff line number Diff line change
@@ -1,47 +1,54 @@
from typing import Callable

import pytest
from _pytest.fixtures import FixtureRequest

from pydantic_i18n import BabelLoader, BaseLoader, JsonLoader
from pydantic_i18n import BabelLoader, JsonLoader


@pytest.mark.parametrize(
"loader",
"loader_fixture_name",
[
pytest.lazy_fixture("json_loader"),
pytest.lazy_fixture("dict_loader"),
pytest.lazy_fixture("babel_loader"),
"json_loader",
"dict_loader",
"babel_loader",
],
)
def test_get_locales(loader: BaseLoader):
def test_get_locales(request: FixtureRequest, loader_fixture_name: str):
loader = request.getfixturevalue(loader_fixture_name)

locales = loader.locales
assert len(locales) >= 2
for locale in ("en_US", "de_DE"):
assert locale in locales


@pytest.mark.parametrize(
"loader",
"loader_fixture_name",
[
pytest.lazy_fixture("json_loader"),
pytest.lazy_fixture("dict_loader"),
pytest.lazy_fixture("babel_loader"),
"json_loader",
"dict_loader",
"babel_loader",
],
)
def test_translation(loader: BaseLoader):
def test_translation(request: FixtureRequest, loader_fixture_name: str):
loader = request.getfixturevalue(loader_fixture_name)

assert loader.gettext("field required", "en_US") == "field required"
assert loader.gettext("field required", "de_DE") == "Feld erforderlich"


@pytest.mark.parametrize(
"loader",
"loader_fixture_name",
[
pytest.lazy_fixture("json_loader"),
pytest.lazy_fixture("dict_loader"),
pytest.lazy_fixture("babel_loader"),
"json_loader",
"dict_loader",
"babel_loader",
],
)
def test_unsupported_locale(loader: BaseLoader):
def test_unsupported_locale(request: FixtureRequest, loader_fixture_name: str):
loader = request.getfixturevalue(loader_fixture_name)

locale = "fr_FR"

with pytest.raises(ValueError) as e:
Expand All @@ -51,14 +58,16 @@ def test_unsupported_locale(loader: BaseLoader):


@pytest.mark.parametrize(
"loader",
"loader_fixture_name",
[
pytest.lazy_fixture("json_loader"),
pytest.lazy_fixture("dict_loader"),
pytest.lazy_fixture("babel_loader"),
"json_loader",
"dict_loader",
"babel_loader",
],
)
def test_unknown_key(loader: BaseLoader):
def test_unknown_key(request: FixtureRequest, loader_fixture_name: str):
loader = request.getfixturevalue(loader_fixture_name)

assert loader.gettext("unknown key", "en_US") == "unknown key"


Expand Down
25 changes: 17 additions & 8 deletions tests/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from typing import Dict, Tuple

import pytest
from _pytest.fixtures import FixtureRequest

from pydantic import BaseModel, Field, ValidationError
from pydantic.color import Color
Expand Down Expand Up @@ -137,13 +138,17 @@ def test_dict_source():


@pytest.mark.parametrize(
"loader",
"loader_fixture_name",
[
# pytest.lazy_fixture("dict_loader"),
pytest.lazy_fixture("babel_loader"),
# "dict_loader",
"babel_loader",
],
)
def test_key_with_placeholder_at_the_end(loader: BaseLoader):
def test_key_with_placeholder_at_the_end(
request: FixtureRequest, loader_fixture_name: str
):
loader = request.getfixturevalue(loader_fixture_name)

class CoolSchema(BaseModel):
color_field: Color

Expand All @@ -161,13 +166,17 @@ class CoolSchema(BaseModel):


@pytest.mark.parametrize(
"loader",
"loader_fixture_name",
[
pytest.lazy_fixture("dict_loader"),
pytest.lazy_fixture("babel_loader"),
"dict_loader",
"babel_loader",
],
)
def test_key_with_placeholder_in_the_middle(loader: BaseLoader):
def test_key_with_placeholder_in_the_middle(
request: FixtureRequest, loader_fixture_name: str
):
loader = request.getfixturevalue(loader_fixture_name)

class T(BaseModel):
decimal_field: Decimal = Field(max_digits=3)

Expand Down
25 changes: 15 additions & 10 deletions tests/test_pydantic_messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from typing import Dict

import pytest
from _pytest.fixtures import FixtureRequest

from pydantic_i18n import PydanticI18n

Expand Down Expand Up @@ -37,14 +38,16 @@ def babel_output() -> Dict[str, str]:


@pytest.mark.parametrize(
"output",
"output_fixture_name",
[
pytest.lazy_fixture("json_output"),
pytest.lazy_fixture("dict_output"),
pytest.lazy_fixture("babel_output"),
"json_output",
"dict_output",
"babel_output",
],
)
def test_messages(output: Dict[str, str]) -> None:
def test_messages(request: FixtureRequest, output_fixture_name: str) -> None:
output = request.getfixturevalue(output_fixture_name)

for k, v in output.items():
assert isinstance(k, str)
assert k == v
Expand All @@ -56,14 +59,16 @@ def test_dict_by_default():


@pytest.mark.parametrize(
"output",
"output_fixture_name",
[
pytest.lazy_fixture("json_output"),
pytest.lazy_fixture("dict_output"),
pytest.lazy_fixture("babel_output"),
"json_output",
"dict_output",
"babel_output",
],
)
def test_placeholders_dict(output: Dict[str, str]):
def test_placeholders_dict(request: FixtureRequest, output_fixture_name: str) -> None:
output = request.getfixturevalue(output_fixture_name)

for k in output:
if "{" in k:
assert "{}" in k
Loading