From 5cec1bf1b644c33cffe96e8f8ebd11a1a343bc6d Mon Sep 17 00:00:00 2001 From: Terry Chia Date: Sun, 22 Mar 2015 11:49:08 +0800 Subject: Add plumbing for hypothesis. --- .gitignore | 1 + dev-requirements.txt | 2 ++ setup.py | 4 ++++ tox.ini | 25 ++++++++++++++++++++++++- 4 files changed, 31 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 8a870e05..bf1a504a 100644 --- a/.gitignore +++ b/.gitignore @@ -11,3 +11,4 @@ htmlcov/ *.egg .eggs/ *.py[co] +./hypothesis diff --git a/dev-requirements.txt b/dev-requirements.txt index 440d3b0f..55aebd4f 100644 --- a/dev-requirements.txt +++ b/dev-requirements.txt @@ -12,5 +12,7 @@ sphinx_rtd_theme sphinxcontrib-spelling tox twine +hypothesis +hypothesis-pytest -e . -e vectors diff --git a/setup.py b/setup.py index b36f3de6..ea2ea181 100644 --- a/setup.py +++ b/setup.py @@ -62,6 +62,10 @@ test_requirements = [ "iso8601", ] +if sys.version_info[:2] == (2, 6): + test_requirements.append("hypothesis") + test_requirements.append("hypothesis-pytest") + # If there's no vectors locally that probably means we are in a tarball and # need to go and get the matching vectors package from PyPi if not os.path.exists(os.path.join(base_dir, "vectors/setup.py")): diff --git a/tox.ini b/tox.ini index a890e38a..1c15abff 100644 --- a/tox.ini +++ b/tox.ini @@ -8,6 +8,29 @@ deps = iso8601 pretend pytest<2.8 + hypothesis + hypothesis-pytest + ./vectors +passenv = ARCHFLAGS LDFLAGS CFLAGS INCLUDE LIB LD_LIBRARY_PATH USERNAME +commands = + pip list + python -c "from cryptography.hazmat.backends.openssl.backend import backend; print(backend.openssl_version_text())" + # We use parallel mode and then combine here so that coverage.py will take + # the paths like .tox/py34/lib/python3.4/site-packages/cryptography/__init__.py + # and collapse them into src/cryptography/__init__.py. + coverage run --parallel-mode -m pytest --capture=no --strict {posargs} + coverage combine + coverage report -m + +[testenv:py26] +# This mirrors the testenv minus the hypothesis and hypothesis-test deps. +deps = + coverage + iso8601 + pretend + pytest<2.8 + hypothesis + hypothesis-pytest ./vectors passenv = ARCHFLAGS LDFLAGS CFLAGS INCLUDE LIB LD_LIBRARY_PATH USERNAME commands = @@ -85,7 +108,7 @@ commands = py.test --capture=no --strict --random {posargs} [flake8] -exclude = .tox,*.egg,.git,_build +exclude = .tox,*.egg,.git,_build,.hypothesis select = E,W,F,N,I application-import-names = cryptography,cryptography_vectors,tests -- cgit v1.2.3 From 7f0705ce3280c31934f111e6b4bba91260cf9cb5 Mon Sep 17 00:00:00 2001 From: Terry Chia Date: Sun, 22 Mar 2015 12:06:26 +0800 Subject: Fix .gitignore. --- .gitignore | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index bf1a504a..60f90063 100644 --- a/.gitignore +++ b/.gitignore @@ -11,4 +11,4 @@ htmlcov/ *.egg .eggs/ *.py[co] -./hypothesis +.hypothesis/ -- cgit v1.2.3 From cc2a828883d03800b3d7a145571796f01f3ed7d9 Mon Sep 17 00:00:00 2001 From: Terry Chia Date: Sun, 22 Mar 2015 12:06:45 +0800 Subject: Add hypothesis test for Fernet. --- tests/test_with_hypothesis.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 tests/test_with_hypothesis.py diff --git a/tests/test_with_hypothesis.py b/tests/test_with_hypothesis.py new file mode 100644 index 00000000..261a21d6 --- /dev/null +++ b/tests/test_with_hypothesis.py @@ -0,0 +1,12 @@ +import pytest + +from cryptography.fernet import Fernet + +hypothesis = pytest.importorskip("hypothesis") + + +@hypothesis.given(bytes) +def test_fernet(data): + f = Fernet(Fernet.generate_key()) + ct = f.encrypt(data) + assert f.decrypt(ct) == data -- cgit v1.2.3 From 6325d5c9bc54b81e0354127523b7ac449c56c0a1 Mon Sep 17 00:00:00 2001 From: Terry Chia Date: Sun, 22 Mar 2015 16:36:19 +0800 Subject: == should be !=. --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index ea2ea181..d00f9fe8 100644 --- a/setup.py +++ b/setup.py @@ -62,7 +62,7 @@ test_requirements = [ "iso8601", ] -if sys.version_info[:2] == (2, 6): +if sys.version_info[:2] != (2, 6): test_requirements.append("hypothesis") test_requirements.append("hypothesis-pytest") -- cgit v1.2.3 From 42ea0d1795797c7f52ba714147e2bbc29dad9deb Mon Sep 17 00:00:00 2001 From: Terry Chia Date: Sun, 27 Sep 2015 20:26:09 +0800 Subject: Pin version of hypothesis above 1.11.4. --- tests/test_with_hypothesis.py | 5 ++++- tox.ini | 23 +---------------------- 2 files changed, 5 insertions(+), 23 deletions(-) diff --git a/tests/test_with_hypothesis.py b/tests/test_with_hypothesis.py index 261a21d6..1e39b6b1 100644 --- a/tests/test_with_hypothesis.py +++ b/tests/test_with_hypothesis.py @@ -1,11 +1,14 @@ +from hypothesis import binary + import pytest from cryptography.fernet import Fernet + hypothesis = pytest.importorskip("hypothesis") -@hypothesis.given(bytes) +@hypothesis.given(binary()) def test_fernet(data): f = Fernet(Fernet.generate_key()) ct = f.encrypt(data) diff --git a/tox.ini b/tox.ini index 1c15abff..8b4343d0 100644 --- a/tox.ini +++ b/tox.ini @@ -8,28 +8,7 @@ deps = iso8601 pretend pytest<2.8 - hypothesis - hypothesis-pytest - ./vectors -passenv = ARCHFLAGS LDFLAGS CFLAGS INCLUDE LIB LD_LIBRARY_PATH USERNAME -commands = - pip list - python -c "from cryptography.hazmat.backends.openssl.backend import backend; print(backend.openssl_version_text())" - # We use parallel mode and then combine here so that coverage.py will take - # the paths like .tox/py34/lib/python3.4/site-packages/cryptography/__init__.py - # and collapse them into src/cryptography/__init__.py. - coverage run --parallel-mode -m pytest --capture=no --strict {posargs} - coverage combine - coverage report -m - -[testenv:py26] -# This mirrors the testenv minus the hypothesis and hypothesis-test deps. -deps = - coverage - iso8601 - pretend - pytest<2.8 - hypothesis + hypothesis>=1.11.4 hypothesis-pytest ./vectors passenv = ARCHFLAGS LDFLAGS CFLAGS INCLUDE LIB LD_LIBRARY_PATH USERNAME -- cgit v1.2.3 From 3d7f8d1d6cf268f5c0c482c8d1cce7ec773a7030 Mon Sep 17 00:00:00 2001 From: Terry Chia Date: Sun, 27 Sep 2015 21:00:58 +0800 Subject: Use correct import. --- tests/test_with_hypothesis.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_with_hypothesis.py b/tests/test_with_hypothesis.py index 1e39b6b1..31dfa04c 100644 --- a/tests/test_with_hypothesis.py +++ b/tests/test_with_hypothesis.py @@ -1,4 +1,4 @@ -from hypothesis import binary +from hypothesis.strategies import binary import pytest -- cgit v1.2.3 From 36a787ff216dff16e49c3cbc8895515588697337 Mon Sep 17 00:00:00 2001 From: Terry Chia Date: Wed, 30 Sep 2015 19:13:14 +0800 Subject: Address comments. --- setup.py | 6 ++---- tests/test_with_hypothesis.py | 3 ++- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/setup.py b/setup.py index d00f9fe8..167b62e0 100644 --- a/setup.py +++ b/setup.py @@ -60,12 +60,10 @@ test_requirements = [ "pytest<2.8", "pretend", "iso8601", + "hypothesis", + "hypothesis-pytest", ] -if sys.version_info[:2] != (2, 6): - test_requirements.append("hypothesis") - test_requirements.append("hypothesis-pytest") - # If there's no vectors locally that probably means we are in a tarball and # need to go and get the matching vectors package from PyPi if not os.path.exists(os.path.join(base_dir, "vectors/setup.py")): diff --git a/tests/test_with_hypothesis.py b/tests/test_with_hypothesis.py index 31dfa04c..5a181216 100644 --- a/tests/test_with_hypothesis.py +++ b/tests/test_with_hypothesis.py @@ -1,3 +1,4 @@ +from hypothesis import given from hypothesis.strategies import binary import pytest @@ -8,7 +9,7 @@ from cryptography.fernet import Fernet hypothesis = pytest.importorskip("hypothesis") -@hypothesis.given(binary()) +@given(binary()) def test_fernet(data): f = Fernet(Fernet.generate_key()) ct = f.encrypt(data) -- cgit v1.2.3 From dcf643f20bee524e748a85221e45c8152afa7478 Mon Sep 17 00:00:00 2001 From: Terry Chia Date: Wed, 30 Sep 2015 19:13:56 +0800 Subject: Remove unneeded line. --- tests/test_with_hypothesis.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/tests/test_with_hypothesis.py b/tests/test_with_hypothesis.py index 5a181216..738549f6 100644 --- a/tests/test_with_hypothesis.py +++ b/tests/test_with_hypothesis.py @@ -6,9 +6,6 @@ import pytest from cryptography.fernet import Fernet -hypothesis = pytest.importorskip("hypothesis") - - @given(binary()) def test_fernet(data): f = Fernet(Fernet.generate_key()) -- cgit v1.2.3 From ea3a2325fde4be04ba65a2c07e4847235e71e89d Mon Sep 17 00:00:00 2001 From: Terry Chia Date: Wed, 30 Sep 2015 19:23:58 +0800 Subject: Remove unused import. --- tests/test_with_hypothesis.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/tests/test_with_hypothesis.py b/tests/test_with_hypothesis.py index 738549f6..fd243803 100644 --- a/tests/test_with_hypothesis.py +++ b/tests/test_with_hypothesis.py @@ -1,8 +1,6 @@ from hypothesis import given from hypothesis.strategies import binary -import pytest - from cryptography.fernet import Fernet -- cgit v1.2.3 From e98df9c97b764420ab5c89b64ed4d7c164e28e50 Mon Sep 17 00:00:00 2001 From: Terry Chia Date: Fri, 2 Oct 2015 22:48:49 +0800 Subject: Move hypothesis tests to the subfolder. --- tests/hypothesis/__init__.py | 5 +++++ tests/hypothesis/test_fernet.py | 11 +++++++++++ tests/test_with_hypothesis.py | 11 ----------- 3 files changed, 16 insertions(+), 11 deletions(-) create mode 100644 tests/hypothesis/__init__.py create mode 100644 tests/hypothesis/test_fernet.py delete mode 100644 tests/test_with_hypothesis.py diff --git a/tests/hypothesis/__init__.py b/tests/hypothesis/__init__.py new file mode 100644 index 00000000..4b540884 --- /dev/null +++ b/tests/hypothesis/__init__.py @@ -0,0 +1,5 @@ +# This file is dual licensed under the terms of the Apache License, Version +# 2.0, and the BSD License. See the LICENSE file in the root of this repository +# for complete details. + +from __future__ import absolute_import, division, print_function diff --git a/tests/hypothesis/test_fernet.py b/tests/hypothesis/test_fernet.py new file mode 100644 index 00000000..fd243803 --- /dev/null +++ b/tests/hypothesis/test_fernet.py @@ -0,0 +1,11 @@ +from hypothesis import given +from hypothesis.strategies import binary + +from cryptography.fernet import Fernet + + +@given(binary()) +def test_fernet(data): + f = Fernet(Fernet.generate_key()) + ct = f.encrypt(data) + assert f.decrypt(ct) == data diff --git a/tests/test_with_hypothesis.py b/tests/test_with_hypothesis.py deleted file mode 100644 index fd243803..00000000 --- a/tests/test_with_hypothesis.py +++ /dev/null @@ -1,11 +0,0 @@ -from hypothesis import given -from hypothesis.strategies import binary - -from cryptography.fernet import Fernet - - -@given(binary()) -def test_fernet(data): - f = Fernet(Fernet.generate_key()) - ct = f.encrypt(data) - assert f.decrypt(ct) == data -- cgit v1.2.3