Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Add validation tests for_internal/_validators.py#10763

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged

Conversation

tkasuz
Copy link
Contributor

@tkasuztkasuz commentedNov 4, 2024
edited
Loading

Change Summary

This PR introduces new unit tests to enhance the test coverage by covering the following scenarios:

  • Added a type check for decimal validators and the corresponding unit tests.
  • Added unit tests to validate numeric constraints (e.g., 'gt', 'lt', etc.).
  • Added a unit test to validate theFraction type.

Confirmed that the test coverage for_internal/_validators.py increased from 96.43% to 100%

Related issue number

#7656

Checklist

  • The pull request title is a good summary of the changes - it will be used in the changelog
  • Unit tests for the changes exist
  • Tests pass on CI
  • Documentation reflects the changes where applicable
  • My PR is ready to review,please add a comment including the phrase "please review" to assign reviewers

Selected Reviewer:@sydney-runkle

This PR introduces new unit tests to enhance the test coverage by covering the following scenarios:- Added a type check for decimal validators and the corresponding unit tests.- Added unit tests to validate numeric constraints (e.g., 'gt', 'lt', etc.).- Added a unit test to validate the `Fraction` type.
@github-actionsgithub-actionsbot added the relnotes-fixUsed for bugfixes. labelNov 4, 2024
@codspeed-hqCodSpeed HQ
Copy link

codspeed-hqbot commentedNov 4, 2024
edited
Loading

CodSpeed Performance Report

Merging#10763 willnot alter performance

Comparingtkasuz:increase_types_test_coverage (57783eb) withmain (bcfd413)

Summary

✅ 44 untouched benchmarks

@github-actionsGitHub Actions
Copy link
Contributor

github-actionsbot commentedNov 4, 2024
edited
Loading

Coverage report

Click to see where and how coverage changed

FileStatementsMissingCoverageCoverage
(new stmts)
Lines missing
  pydantic/_internal
  _validators.py
Project Total 

This report was generated bypython-coverage-comment-action

@tkasuz
Copy link
ContributorAuthor

please review

pydantic-hooky[bot] reacted with thumbs up emoji

Copy link
Contributor

@sydney-runklesydney-runkle left a comment

Choose a reason for hiding this comment

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

Thanks for helping us to bump up our test coverage!

I've left a few recommendations. Let me know if you have any follow up inquiries :)

Comment on lines 391 to 392
if not isinstance(x, Decimal):
raise TypeError(f'Expected Decimal, received {type(x).__name__}')
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we test this anywhere?

Copy link
ContributorAuthor

@tkasuztkasuzNov 15, 2024
edited
Loading

Choose a reason for hiding this comment

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

I ended up checking the Decimal type here instead

raiseTypeError(f'Unable to extract decimal digits info from supplied value{decimal}')

@pydantic-hookypydantic-hookybot added awaiting author revisionawaiting changes from the PR author and removed ready for review labelsNov 14, 2024
…ts_infoSigned-off-by: tkasuz <63289889+tkasuz@users.noreply.github.com>
@tkasuztkasuzforce-pushed theincrease_types_test_coverage branch from0bbfcd5 tof6919b5CompareNovember 15, 2024 04:31
Signed-off-by: tkasuz <63289889+tkasuz@users.noreply.github.com>
Copy link
Contributor

@sydney-runklesydney-runkle left a comment

Choose a reason for hiding this comment

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

Other than that one question, tests look great! Thanks for your contribution!

Comment on lines -349 to -370
decimal_tuple = decimal.as_tuple()
if not isinstance(decimal_tuple.exponent, int):
raise TypeError(f'Unable to extract decimal digits info from supplied value {decimal}')
exponent = decimal_tuple.exponent
num_digits = len(decimal_tuple.digits)

if exponent >= 0:
# A positive exponent adds that many trailing zeros
# Ex: digit_tuple=(1, 2, 3), exponent=2 -> 12300 -> 0 decimal places, 5 digits
num_digits += exponent
decimal_places = 0
else:
# If the absolute value of the negative exponent is larger than the
# number of digits, then it's the same as the number of digits,
# because it'll consume all the digits in digit_tuple and then
# add abs(exponent) - len(digit_tuple) leading zeros after the decimal point.
# Ex: digit_tuple=(1, 2, 3), exponent=-2 -> 1.23 -> 2 decimal places, 3 digits
# Ex: digit_tuple=(1, 2, 3), exponent=-4 -> 0.0123 -> 4 decimal places, 4 digits
decimal_places = abs(exponent)
num_digits = max(num_digits, decimal_places)
try:
decimal_tuple = decimal.as_tuple()

return decimal_places, num_digits
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we leave this as is? WhatAttributeError might occur here?

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

If thedecimal argument is not aDecimal type, which is accepted as Any in the root function, anAttributeError might occur because the as_tuple method may not exist

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

Would it be better to change the argument type toAny and add anotherassert to check if the type isDecimal? 🤔

Copy link
Contributor

Choose a reason for hiding this comment

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

Makes sense, thanks for the improvement!

Copy link
Contributor

@sydney-runklesydney-runkle left a comment

Choose a reason for hiding this comment

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

Thanks! Great work! 🚀

@sydney-runklesydney-runkle merged commit0157e34 intopydantic:mainNov 16, 2024
53 checks passed
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@sydney-runklesydney-runklesydney-runkle approved these changes

Assignees

@tkasuztkasuz

Labels
awaiting author revisionawaiting changes from the PR authorrelnotes-fixUsed for bugfixes.
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

2 participants
@tkasuz@sydney-runkle

[8]ページ先頭

©2009-2025 Movatter.jp