You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Faker version: 24.14.0 (same happens on the latest version)
OS: MacOS (does not matter)
Distribution of pydecimal is very far from optimal which can lead to difficulty of use it in the tests.
For instance, it the initial value is max_value and the updated value is also max_value then it will "break" the test because the value will not be updated.
I can recommend the following approaches (imho):
re-evaluate the value if it is min or max value (maybe provide special extra kwargs to support it)
make the logic of generation more "random" as currently it is obvious that due to overflow we set it to max value or in case of underflow to min value
use min and max value inside the calculation to make sure that the value will be in the boundaries during generation
defget_value() ->dec.Decimal:
"""Generates real fake decimal by eliminating `min_value` and `max_value` value which is returned in case of underflow/overflow."""returnnext(
itemforiteminiter(
lambda: fake['en'].pydecimal(
left_digits=0,
right_digits=4,
min_value=dec.Decimal('0.0001'),
max_value=dec.Decimal(1),
),
None,
)
ifitemnotin {dec.Decimal('0.0001'), dec.Decimal(1)}
)
Distribution of
pydecimal
is very far from optimal which can lead to difficulty of use it in the tests.For instance, it the initial value is
max_value
and the updated value is alsomax_value
then it will "break" the test because the value will not be updated.I can recommend the following approaches (imho):
min
ormax
value (maybe provide special extrakwargs
to support it)Steps to reproduce
Expected behavior
Actual behavior
The text was updated successfully, but these errors were encountered: