Skip to content

Commit

Permalink
Clarify type hints
Browse files Browse the repository at this point in the history
  • Loading branch information
bonjourmauko committed Sep 27, 2023
1 parent 9f509c4 commit a906211
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 33 deletions.
2 changes: 1 addition & 1 deletion openfisca_core/entities/role.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from __future__ import annotations

from collections.abc import Sequence, Mapping
from collections.abc import Mapping, Sequence
from typing import Any

import dataclasses
Expand Down
20 changes: 3 additions & 17 deletions openfisca_core/entities/tests/test_group_entity.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,50 +8,36 @@

@pytest.fixture
def parent() -> str:
"""A key."""

return "parent"


@pytest.fixture
def uncle() -> str:
"""Another key."""

return "uncle"


@pytest.fixture
def first_parent() -> str:
"""A sub-role."""

return "first_parent"


@pytest.fixture
def second_parent() -> str:
"""Another sub-role."""

return "second_parent"


@pytest.fixture
def third_parent() -> str:
"""Yet another sub-role."""

return "third_parent"


@pytest.fixture
def role(parent: str, first_parent: str, third_parent: str) -> Any:
"""A role."""

def role(parent: str, first_parent: str, third_parent: str) -> Mapping[str, Any]:
return {"key": parent, "subroles": {first_parent, third_parent}}


@pytest.fixture
def group_entity(role: Mapping[str, Any]) -> entities.GroupEntity:
"""A group entity."""

return entities.GroupEntity("key", "label", "plural", "doc", (role,))


Expand All @@ -68,7 +54,7 @@ def test_init_when_doc_indented() -> None:
def test_group_entity_with_roles(
group_entity: entities.GroupEntity, parent: str, uncle: str
) -> None:
"""Assign a role for each role-like passed as argument."""
"""Assign a Role for each role-like passed as argument."""

assert hasattr(group_entity, parent.upper())
assert not hasattr(group_entity, uncle.upper())
Expand All @@ -77,7 +63,7 @@ def test_group_entity_with_roles(
def test_group_entity_with_subroles(
group_entity: entities.GroupEntity, first_parent: str, second_parent: str
) -> None:
"""Assign a role for each sub-role-like passed as argument."""
"""Assign a Role for each subrole-like passed as argument."""

assert hasattr(group_entity, first_parent.upper())
assert not hasattr(group_entity, second_parent.upper())
17 changes: 2 additions & 15 deletions openfisca_core/entities/tests/test_role.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,11 @@
from typing import Any

import pytest

from openfisca_core import entities

from openfisca_core.entities.typing import Entity


@pytest.fixture
def entity() -> Any:
"""An entity."""

return object()


def test_init_when_doc_indented(entity: Entity) -> None:
def test_init_when_doc_indented() -> None:
"""De-indent the ``doc`` attribute if it is passed at initialisation."""

key = "\tkey"
doc = "\tdoc"
role = entities.Role({"key": key, "doc": doc}, entity)
role = entities.Role({"key": key, "doc": doc}, object())
assert role.key == key
assert role.doc == doc.lstrip()

0 comments on commit a906211

Please sign in to comment.