Merge pull request #1773 from Ayrx/hypothesis
Property based testing with Hypothesis
diff --git a/.gitignore b/.gitignore
index 8a870e0..60f9006 100644
--- a/.gitignore
+++ b/.gitignore
@@ -11,3 +11,4 @@
*.egg
.eggs/
*.py[co]
+.hypothesis/
diff --git a/dev-requirements.txt b/dev-requirements.txt
index 440d3b0..55aebd4 100644
--- a/dev-requirements.txt
+++ b/dev-requirements.txt
@@ -12,5 +12,7 @@
sphinxcontrib-spelling
tox
twine
+hypothesis
+hypothesis-pytest
-e .
-e vectors
diff --git a/setup.py b/setup.py
index b36f3de..167b62e 100644
--- a/setup.py
+++ b/setup.py
@@ -60,6 +60,8 @@
"pytest<2.8",
"pretend",
"iso8601",
+ "hypothesis",
+ "hypothesis-pytest",
]
# If there's no vectors locally that probably means we are in a tarball and
diff --git a/tests/hypothesis/__init__.py b/tests/hypothesis/__init__.py
new file mode 100644
index 0000000..4b54088
--- /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 0000000..fd24380
--- /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/tox.ini b/tox.ini
index a890e38..8b4343d 100644
--- a/tox.ini
+++ b/tox.ini
@@ -8,6 +8,8 @@
iso8601
pretend
pytest<2.8
+ hypothesis>=1.11.4
+ hypothesis-pytest
./vectors
passenv = ARCHFLAGS LDFLAGS CFLAGS INCLUDE LIB LD_LIBRARY_PATH USERNAME
commands =
@@ -85,7 +87,7 @@
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