From db5df8d254ac0e6de2a3754f925d12c83bca5f78 Mon Sep 17 00:00:00 2001 From: mattsb42-aws Date: Fri, 30 Mar 2018 16:39:20 -0700 Subject: [PATCH] fix hypothesis decimal strategy to fully filter out values that are not compatible with DYNAMODB_CONTEXT --- test/functional/hypothesis_strategies.py | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/test/functional/hypothesis_strategies.py b/test/functional/hypothesis_strategies.py index fa7f316c..233192c1 100644 --- a/test/functional/hypothesis_strategies.py +++ b/test/functional/hypothesis_strategies.py @@ -51,6 +51,15 @@ ) +def _valid_ddb_number(value): + try: + DYNAMODB_CONTEXT.create_decimal(float(value)) + except Exception: + return False + else: + return True + + ddb_string = text( min_size=1, max_size=MAX_ITEM_BYTES @@ -60,17 +69,17 @@ def _ddb_fraction_to_decimal(val): """Hypothesis does not support providing a custom Context, so working around that.""" - return DYNAMODB_CONTEXT.create_decimal(Decimal(val.numerator) / Decimal(val.denominator)) + return Decimal(val.numerator) / Decimal(val.denominator) _ddb_positive_numbers = fractions( min_value=POSITIVE_NUMBER_RANGE.min, max_value=POSITIVE_NUMBER_RANGE.max -).map(_ddb_fraction_to_decimal) +).map(_ddb_fraction_to_decimal).filter(_valid_ddb_number) _ddb_negative_numbers = fractions( min_value=NEGATIVE_NUMBER_RANGE.min, max_value=NEGATIVE_NUMBER_RANGE.max -).map(_ddb_fraction_to_decimal) +).map(_ddb_fraction_to_decimal).filter(_valid_ddb_number) ddb_number = _ddb_negative_numbers | just(Decimal('0')) | _ddb_positive_numbers ddb_number_set = sets(ddb_number, min_size=1)