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

✨ Add flexible currency parser with validation and symbol detection for Pydantic models #86

Open
wants to merge 32 commits into
base: main
Choose a base branch
from

Conversation

mohamedmamdouh22
Copy link
Collaborator

@mohamedmamdouh22 mohamedmamdouh22 commented Nov 13, 2024

  • Implemented CurrencyParser to parse and validate currency inputs, detecting symbols and converting them to standardized currency codes.
  • Added ParserTypeCurrency using Annotated and BeforeValidator for seamless integration with Pydantic models, returning structured dictionaries.
  • Supports numeric and string inputs, gracefully handling None values and unavailable price indicators.
  • Ensures consistent dictionary output for reliable testing and usage.

)
def test_flexible_price_success(input_value, expected_output):
model = _TestModel(value=input_value)
assert model.value == pytest.approx(expected_output)
Copy link
Member

Choose a reason for hiding this comment

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

why are we doing approx? Whats the limit here

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

i usually do this when comparing floats to avoid any unexpected percision issues

Copy link
Member

@awtkns awtkns left a comment

Choose a reason for hiding this comment

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

Please add a full schema parsing test by adding a mock schema in core/test/parser/mock_schemas that uses both currency and price. We need to validate the case when currency is all null

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants