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

test(enums): fix enums doctests #1273

Merged
merged 10 commits into from
Oct 14, 2024
Merged

test(enums): fix enums doctests #1273

merged 10 commits into from
Oct 14, 2024

Conversation

bonjourmauko
Copy link
Member

Depends on #1272
Fixes #1267

New features

  • Introduce indexed_enums.EnumType
    • Allows for actually fancy indexing indexed_enums.Enum

Technical changes

  • Fix doctests
  • Fix bug in Enum.encode when passing a scalar
    • Still raises TypeError but with an explanation of why it fails
  • Fix bug in Enum.encode when encoding values not present in the enum
    • When encoding values not present in an enum, Enum.encode always encoded the first item of it
    • Now, it correctly encodes only the values requested that exist in the enum
Before
from openfisca_core import indexed_enums as enum

class TestEnum(enum.Enum):
     ONE = "one"
     TWO = "two"

TestEnum.encode([2])
#  EnumArray([0])
After
from openfisca_core import indexed_enums as enum

class TestEnum(enum.Enum):
     ONE = "one"
     TWO = "two"

TestEnum.encode([2])
#  EnumArray([])

TestEnum.encode([0,1,2,5])
# EnumArray([<TestEnum.ONE: 'one'> <TestEnum.TWO: 'two'>])

@bonjourmauko bonjourmauko added the kind:test Adding missing tests or correcting existing tests label Oct 9, 2024
@bonjourmauko bonjourmauko requested review from a team October 9, 2024 00:58
@bonjourmauko bonjourmauko self-assigned this Oct 9, 2024
@coveralls
Copy link

Coverage Status

coverage: 82.236% (+0.4%) from 81.804%
when pulling b5b7968 on test/fix-enums-doctests
into df9e9d7 on master.

@bonjourmauko bonjourmauko changed the base branch from master to docs/add-docs-to-enums October 9, 2024 01:10
@bonjourmauko bonjourmauko changed the title Test/fix enums doctests test(enums): fix enums doctests Oct 9, 2024
Base automatically changed from docs/add-docs-to-enums to master October 14, 2024 11:38
@bonjourmauko bonjourmauko merged commit 6dfc93f into master Oct 14, 2024
29 checks passed
@bonjourmauko bonjourmauko deleted the test/fix-enums-doctests branch October 14, 2024 11:38
bonjourmauko added a commit that referenced this pull request Oct 18, 2024
bonjourmauko added a commit that referenced this pull request Oct 18, 2024
bonjourmauko added a commit that referenced this pull request Oct 18, 2024
bonjourmauko added a commit that referenced this pull request Oct 18, 2024
bonjourmauko added a commit that referenced this pull request Oct 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind:test Adding missing tests or correcting existing tests
Projects
Status: Abandoned
Development

Successfully merging this pull request may close these issues.

Fix enums doctests
2 participants