From d2c25dcf0acbd449fcb60ac984b649b6a678c689 Mon Sep 17 00:00:00 2001 From: mattsb42-aws Date: Thu, 8 Mar 2018 15:51:21 -0800 Subject: [PATCH 1/4] adding hypothesis pytest marker --- setup.cfg | 1 + test/functional/test_f_formatting_attribute_serialization.py | 4 ++++ .../test_f_formatting_material_description_serialization.py | 2 ++ 3 files changed, 7 insertions(+) diff --git a/setup.cfg b/setup.cfg index 0a1d775e..d3796a38 100644 --- a/setup.cfg +++ b/setup.cfg @@ -19,6 +19,7 @@ markers = unit: mark test as a unit test (does not require network access) functional: mark test as a functional test (does not require network access) integ: mark a test as an integration test (requires network access) + hypothesis: mark a test as using hypothesis (will run many times for each pytest call) slow: mark a test as being known to take a long time to complete (order 5s < t < 60s) veryslow: mark a test as being known to take a very long time to complete (order t > 60s) nope: mark a test as being so slow that it should only be very infrequently (order t > 30m) diff --git a/test/functional/test_f_formatting_attribute_serialization.py b/test/functional/test_f_formatting_attribute_serialization.py index d128758b..c12e8f1c 100644 --- a/test/functional/test_f_formatting_attribute_serialization.py +++ b/test/functional/test_f_formatting_attribute_serialization.py @@ -73,6 +73,7 @@ def _serialize_deserialize_cycle(attribute): @pytest.mark.slow +@pytest.mark.hypothesis @SLOW_SETTINGS @hypothesis.given(ddb_attribute_values) def test_serialize_deserialize_attribute_slow(attribute): @@ -80,6 +81,7 @@ def test_serialize_deserialize_attribute_slow(attribute): @pytest.mark.veryslow +@pytest.mark.hypothesis @VERY_SLOW_SETTINGS @hypothesis.given(ddb_attribute_values) def test_serialize_deserialize_attribute_vslow(attribute): @@ -93,6 +95,7 @@ def _ddb_dict_ddb_transform_cycle(item): @pytest.mark.slow +@pytest.mark.hypothesis @SLOW_SETTINGS @hypothesis.given(ddb_items) def test_dict_to_ddb_and_back_slow(item): @@ -100,6 +103,7 @@ def test_dict_to_ddb_and_back_slow(item): @pytest.mark.veryslow +@pytest.mark.hypothesis @VERY_SLOW_SETTINGS @hypothesis.given(ddb_items) def test_dict_to_ddb_and_back_vslow(item): diff --git a/test/functional/test_f_formatting_material_description_serialization.py b/test/functional/test_f_formatting_material_description_serialization.py index 37d66b28..786aac9f 100644 --- a/test/functional/test_f_formatting_material_description_serialization.py +++ b/test/functional/test_f_formatting_material_description_serialization.py @@ -77,6 +77,7 @@ def _serialize_deserialize_cycle(material_description): @pytest.mark.slow +@pytest.mark.hypothesis @SLOW_SETTINGS @hypothesis.given(material_descriptions) def test_serialize_deserialize_material_description_slow(material_description): @@ -84,6 +85,7 @@ def test_serialize_deserialize_material_description_slow(material_description): @pytest.mark.veryslow +@pytest.mark.hypothesis @VERY_SLOW_SETTINGS @hypothesis.given(material_descriptions) def test_serialize_deserialize_material_description_vslow(material_description): From c5e110642fb4d3139f144a7b9fc3d83e509c8f35 Mon Sep 17 00:00:00 2001 From: mattsb42-aws Date: Thu, 8 Mar 2018 15:52:45 -0800 Subject: [PATCH 2/4] blacklisting quote characters in hypothesis strings until moto bug is fixed https://github.com/spulec/moto/issues/1505 --- test/functional/hypothesis_strategies.py | 25 ++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/test/functional/hypothesis_strategies.py b/test/functional/hypothesis_strategies.py index e4f9038d..21beb977 100644 --- a/test/functional/hypothesis_strategies.py +++ b/test/functional/hypothesis_strategies.py @@ -17,7 +17,9 @@ from boto3.dynamodb.types import Binary, DYNAMODB_CONTEXT import hypothesis -from hypothesis.strategies import binary, booleans, dictionaries, deferred, fractions, just, lists, none, sets, text +from hypothesis.strategies import ( + binary, booleans, characters, dictionaries, deferred, fractions, just, lists, none, sets, text +) SLOW_SETTINGS = hypothesis.settings( suppress_health_check=( @@ -49,7 +51,14 @@ ) -ddb_string = text(min_size=1, max_size=MAX_ITEM_BYTES) +ddb_string = text( + min_size=1, + max_size=MAX_ITEM_BYTES, + alphabet=characters( + blacklist_categories=('Cs',), + blacklist_characters=('"', "'") # Quotes break moto :( + ) +) ddb_string_set = sets(ddb_string, min_size=1) @@ -89,9 +98,17 @@ def _ddb_fraction_to_decimal(val): | ddb_number_set | ddb_binary_set ) +ddb_attribute_names = text( + min_size=1, + max_size=255, + alphabet=characters( + blacklist_categories=('Cs',), + blacklist_characters=('"', "'") # Quotes break moto :( + ) +) # TODO: List and Map types have a max depth of 32 ddb_map_type = deferred(lambda: dictionaries( - keys=text(), + keys=ddb_attribute_names, values=( ddb_scalar_types | ddb_set_types @@ -112,7 +129,7 @@ def _ddb_fraction_to_decimal(val): ddb_attribute_values = ddb_scalar_types | ddb_set_types | ddb_list_type ddb_items = dictionaries( - keys=text(min_size=1, max_size=255), + keys=ddb_attribute_names, values=ddb_scalar_types | ddb_set_types | ddb_list_type ) From e19db60775138938b2886ea10f859d109e63dfbc Mon Sep 17 00:00:00 2001 From: mattsb42-aws Date: Tue, 27 Mar 2018 17:25:04 -0700 Subject: [PATCH 3/4] move test requirements into test/requirements.txt --- test/requirements.txt | 7 +++++++ tox.ini | 11 ++--------- 2 files changed, 9 insertions(+), 9 deletions(-) create mode 100644 test/requirements.txt diff --git a/test/requirements.txt b/test/requirements.txt new file mode 100644 index 00000000..780cff82 --- /dev/null +++ b/test/requirements.txt @@ -0,0 +1,7 @@ +hypothesis +mock +moto +pytest>=3.3.1 +pytest-cov +pytest-mock +pytest-xdist \ No newline at end of file diff --git a/tox.ini b/tox.ini index a2daa457..40517637 100644 --- a/tox.ini +++ b/tox.ini @@ -1,6 +1,6 @@ [tox] envlist = - py{27,34,35,36}-{local,integ}-full, + py{27,34,35,36}-{local,integ}-fast, bandit, doc8, readme, flake8, pylint, flake8-tests, pylint-tests, @@ -23,14 +23,7 @@ passenv = # Pass through AWS profile name (useful for local testing) AWS_PROFILE sitepackages = False -deps = - hypothesis - mock - moto - pytest>=3.3.1 - pytest-cov - pytest-mock - pytest-xdist +deps = -rtest/requirements.txt commands = local-fast: {[testenv:base-command]commands} -m "local and not slow and not veryslow and not nope" integ-fast: {[testenv:base-command]commands} -m "integ and not slow and not veryslow and not nope" From 317d17ee374fb5af91112751721f22f2d16ceff6 Mon Sep 17 00:00:00 2001 From: mattsb42-aws Date: Thu, 19 Apr 2018 12:50:31 -0700 Subject: [PATCH 4/4] temporarily bump moto dependency to latest git status to unblock quotes in attribute and map field names --- test/functional/hypothesis_strategies.py | 12 ++---------- test/requirements.txt | 2 +- 2 files changed, 3 insertions(+), 11 deletions(-) diff --git a/test/functional/hypothesis_strategies.py b/test/functional/hypothesis_strategies.py index 21beb977..aa0fb8e5 100644 --- a/test/functional/hypothesis_strategies.py +++ b/test/functional/hypothesis_strategies.py @@ -53,11 +53,7 @@ ddb_string = text( min_size=1, - max_size=MAX_ITEM_BYTES, - alphabet=characters( - blacklist_categories=('Cs',), - blacklist_characters=('"', "'") # Quotes break moto :( - ) + max_size=MAX_ITEM_BYTES ) ddb_string_set = sets(ddb_string, min_size=1) @@ -100,11 +96,7 @@ def _ddb_fraction_to_decimal(val): ) ddb_attribute_names = text( min_size=1, - max_size=255, - alphabet=characters( - blacklist_categories=('Cs',), - blacklist_characters=('"', "'") # Quotes break moto :( - ) + max_size=255 ) # TODO: List and Map types have a max depth of 32 ddb_map_type = deferred(lambda: dictionaries( diff --git a/test/requirements.txt b/test/requirements.txt index 780cff82..34d6a3b4 100644 --- a/test/requirements.txt +++ b/test/requirements.txt @@ -1,6 +1,6 @@ hypothesis mock -moto +git+https://github.com/spulec/moto.git pytest>=3.3.1 pytest-cov pytest-mock