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

Improved validate unit to handle strings and to raise exception for invalid units #331

Conversation

cfulton
Copy link

@cfulton cfulton commented Dec 19, 2024

Improved the validate_unit method so that it can handle both string and enums.

  • Created set of all supported units. Set includes current enums and consts in units.py
  • Handled if unit was string or enum.
  • Checked if provided unit is in set of all supported units. Return unit if it is in set.
  • raise new InvalidUnitOfMeasureException if we didn't return a valid unit.
  • Changed return to always be string and updated implementation.

Tests created to validate scenarios of:

  • Tested with valid units as enum values.
  • Tested with valid units as string.
  • Verified that return is string type.
  • Tested Invalid unit scenarios to always raise InvalidUnitOfMeasureException

@TheJulianJES
Copy link
Contributor

We've gone with this approach for now: #352
Still, thank you very much for the PR!

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