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

[3/17] Add tests to entities #1192

Merged
merged 13 commits into from
Oct 3, 2023
Merged

[3/17] Add tests to entities #1192

merged 13 commits into from
Oct 3, 2023

Conversation

bonjourmauko
Copy link
Member

@bonjourmauko bonjourmauko commented Sep 26, 2023

Technical changes

  • Add tests to entities.

@bonjourmauko bonjourmauko added meta:quality-assurance level:starter Suited for beginners and new contributors labels Sep 26, 2023
@bonjourmauko bonjourmauko requested a review from a team September 26, 2023 23:23
@coveralls
Copy link

coveralls commented Sep 26, 2023

Coverage Status

coverage: 73.501% (-0.6%) from 74.127% when pulling 696e00f on compose-entity into 23979ed on master.

Copy link
Member

@MattiSG MattiSG left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting changes, thank you!

openfisca_core/entities/group_entity.py Outdated Show resolved Hide resolved
plural: str,
label: str,
doc: str,
roles: Sequence[HasKey],
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there any reason why the roles should be ordered? I don't see one and would recommend to use Set or Iterable instead.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would not change that ionce it might be used by package dependent on core (and even core) when filling population if the roles are indexed by an integer.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After spending a couple of hours on this... good part of the code depends on roles and sub-roles being ordered.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I prefer not to touch that for now, not before the aforesaid parts of the code are properly tested and documented.

Copy link
Member Author

@bonjourmauko bonjourmauko Sep 27, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BTW @MattiSG at least in Python, iterable is a generic protocol including list (ordered, mutable), tuple (ordered, immutable), dict (not-ordered, mutable), and set (not-ordered, sort of mutable).

@benjello Why? You mean, for example, I have a GroupEntity of 4 people. You'll use role/subrole's index to determine each person's order within the group? (I actually had strange results when I tried to remove indexation). A lot to do in OpenFisca yet! 😄

openfisca_core/entities/group_entity.py Outdated Show resolved Hide resolved
openfisca_core/entities/typing.py Outdated Show resolved Hide resolved
openfisca_core/entities/tests/test_role.py Outdated Show resolved Hide resolved
openfisca_core/entities/tests/test_group_entity.py Outdated Show resolved Hide resolved
openfisca_core/entities/tests/test_group_entity.py Outdated Show resolved Hide resolved
openfisca_core/entities/tests/test_entity.py Outdated Show resolved Hide resolved
@bonjourmauko
Copy link
Member Author

@benjello This PR opened a couple of questions that I pose here for documentation purposes:

  1. Why the reliance on roles/subroles indexes?
  2. Why do we need bidirectional navigation entity <--> role?
  3. Why do we need bidirectional navigation entity <--> TBS?
  4. How does / where does the magic happen with the members_role projector?
  5. Why defining entity.CHILD and not something like entity.roles.where(key="child")?

These are all breaking-changes, but refactoring each could greatly facilitate maintenance and new features.

@bonjourmauko
Copy link
Member Author

Is there anything missing for LTGM @benjello @MattiSG?

Copy link
Member

@benjello benjello left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some suggestions left to the author of the PR to adopt or not.

@@ -46,10 +46,10 @@ def check_variable_defined_for_entity(self, variable_name: str) -> None:
if entity.key != self.key:
message = os.linesep.join(
[
"You tried to compute the variable '{0}' for the entity '{1}';".format(
"You tried to compute the variable '{}' for the entity '{}';".format(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about using f-stings here too ?

variable_name, self.plural
),
"however the variable '{0}' is defined for '{1}'.".format(
"however the variable '{}' is defined for '{}'.".format(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about using f-stings here too ?

@bonjourmauko bonjourmauko merged commit a3c2f83 into master Oct 3, 2023
22 checks passed
@bonjourmauko bonjourmauko deleted the compose-entity branch October 3, 2023 23:32
@bonjourmauko bonjourmauko added this to the Improved testing milestone Sep 17, 2024
@bonjourmauko bonjourmauko changed the title Add tests to entities [3/17] Add tests to entities Sep 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
level:starter Suited for beginners and new contributors meta:quality-assurance
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants