[Python-modules-commits] [python-hypothesis] 01/03: Import python-hypothesis_3.0.1.orig.tar.gz

Tristan Seligmann mithrandi at moszumanska.debian.org
Thu Feb 18 15:43:02 UTC 2016


This is an automated email from the git hooks/post-receive script.

mithrandi pushed a commit to branch master
in repository python-hypothesis.

commit ae629461bc84e2af2ff4241ae4de166cc2aee0e3
Author: Tristan Seligmann <mithrandi at debian.org>
Date:   Thu Feb 18 15:56:39 2016 +0200

    Import python-hypothesis_3.0.1.orig.tar.gz
---
 README.rst                               |  8 ++------
 docs/changes.rst                         | 22 ++++++++++++++++++++++
 setup.py                                 |  2 --
 src/hypothesis/configuration.py          |  8 ++++----
 src/hypothesis/searchstrategy/strings.py |  9 +++++++++
 src/hypothesis/stateful.py               | 27 +++++++++++++++------------
 src/hypothesis/strategies.py             |  6 +++++-
 src/hypothesis/version.py                |  2 +-
 tests/cover/test_simple_strings.py       |  6 ++++++
 tests/cover/test_stateful.py             | 25 +++++++++++++++++++++++--
 10 files changed, 87 insertions(+), 28 deletions(-)

diff --git a/README.rst b/README.rst
index 9314db9..f76d48f 100644
--- a/README.rst
+++ b/README.rst
@@ -12,12 +12,8 @@ unit testing by some way. It's easy to use, stable, and extremely powerful. If
 you're not using Hypothesis to test your project then you're missing out.
 
 Hypothesis works with most widely used versions of Python. It officially supports
-CPython 2.7, 3.4 and 3.5, as well as PyPy. CPython 2.6 and 3.3 are supported on a
-"best effort" basis - they probably work, and bugs in them may be fixed, but they're
-not regularly tested and are likely to work less well.
-
-Jython, IronPython and PyPy3 are known not to work and there are currently no plans
-to support them.
+CPython 2.7, 3.4 and 3.5, as well as PyPy. Most other versions of Python are known
+not to work.
 
 -----------------
 Links of interest
diff --git a/docs/changes.rst b/docs/changes.rst
index 234ab0b..f77048b 100644
--- a/docs/changes.rst
+++ b/docs/changes.rst
@@ -22,6 +22,21 @@ You should generally assume that an API is internal unless you have specific
 information to the contrary.
 
 ------------------
+3.0.1 - 2016-02-18
+------------------
+
+* Fix a case where it was possible to trigger an "Unreachable" assertion when
+  running certain flaky stateful tests.
+* Improve shrinking of large stateful tests by eliminating a case where it was
+  hard to delete early steps.
+* Improve efficiency of drawing binary(min_size=n, max_size=n0 significantly by
+  provide a custom implementation for fixed size blocks that can bypass a lot
+  of machinery.
+* Set default home directory based on the current working directory at the
+  point Hypothesis is imported, not whenever the function first happens to be
+  called.
+
+------------------
 3.0.0 - 2016-02-17
 ------------------
 
@@ -42,12 +57,19 @@ New features:
 * New "exploded" database format which allows you to more easily check the example
   database into a source repository while supporting merging.
 * Better management of how examples are saved in the database.
+* Health checks will now raise as errors when they fail. It was too easy to have
+  the warnings be swallowed entirely.
 
 New limitations:
 
 * choices and streaming strategies may no longer be used with find(). Neither may
   data() (this is the change that necessitated a major version bump).
 
+Feature removal:
+
+* The ForkingTestCase executor has gone away. It may return in some more working
+  form at a later date.
+
 Performance improvements:
 
 * A new model which allows flatmap, composite strategies and stateful testing to
diff --git a/setup.py b/setup.py
index c77af04..dcfbcb8 100644
--- a/setup.py
+++ b/setup.py
@@ -71,10 +71,8 @@ setup(
         "Operating System :: POSIX",
         "Operating System :: Microsoft :: Windows",
         "Programming Language :: Python",
-        "Programming Language :: Python :: 2.6",
         "Programming Language :: Python :: 2.7",
         "Programming Language :: Python :: 3",
-        "Programming Language :: Python :: 3.3",
         "Programming Language :: Python :: 3.4",
         "Programming Language :: Python :: 3.5",
         "Programming Language :: Python :: Implementation :: CPython",
diff --git a/src/hypothesis/configuration.py b/src/hypothesis/configuration.py
index dedd5a3..506dad1 100644
--- a/src/hypothesis/configuration.py
+++ b/src/hypothesis/configuration.py
@@ -18,6 +18,8 @@ from __future__ import division, print_function, absolute_import
 
 import os
 
+__hypothesis_home_directory_default = os.path.join(os.getcwd(), '.hypothesis')
+
 __hypothesis_home_directory = None
 
 
@@ -39,10 +41,8 @@ def hypothesis_home_dir():
         __hypothesis_home_directory = os.getenv(
             'HYPOTHESIS_STORAGE_DIRECTORY')
     if not __hypothesis_home_directory:
-        __hypothesis_home_directory = os.path.join(
-            os.getcwd(), '.hypothesis'
-        )
-    mkdir_p(__hypothesis_home_directory)
+        __hypothesis_home_directory = __hypothesis_home_directory_default
+        mkdir_p(__hypothesis_home_directory)
     return __hypothesis_home_directory
 
 
diff --git a/src/hypothesis/searchstrategy/strings.py b/src/hypothesis/searchstrategy/strings.py
index a63732e..bd0896c 100644
--- a/src/hypothesis/searchstrategy/strings.py
+++ b/src/hypothesis/searchstrategy/strings.py
@@ -123,3 +123,12 @@ class BinaryStringStrategy(MappedSearchStrategy):
         assert isinstance(x, list), repr(x)
         ba = bytearray(x)
         return binary_type(ba)
+
+
+class FixedSizeBytes(SearchStrategy):
+
+    def __init__(self, size):
+        self.size = size
+
+    def do_draw(self, data):
+        return binary_type(data.draw_bytes(self.size))
diff --git a/src/hypothesis/stateful.py b/src/hypothesis/stateful.py
index d0d9880..e4bd25f 100644
--- a/src/hypothesis/stateful.py
+++ b/src/hypothesis/stateful.py
@@ -40,7 +40,6 @@ from hypothesis._settings import settings as Settings
 from hypothesis._settings import Verbosity
 from hypothesis.reporting import report, verbose_report, current_verbosity
 from hypothesis.strategies import just, one_of, sampled_from
-from hypothesis.internal.compat import hrange
 from hypothesis.internal.reflection import proxies
 from hypothesis.internal.conjecture.data import StopTest
 from hypothesis.searchstrategy.strategies import SearchStrategy
@@ -105,10 +104,10 @@ def run_state_machine_as_test(state_machine_factory, settings=None):
         with BuildContext(is_final=True):
             breaker.run(state_machine_factory(), print_steps=True)
     except StopTest:
-        raise Flaky(
-            u'Run failed initially but succeeded on a second try'
-        )
-    assert False, 'Unreachable'  # pragma: no cover
+        pass
+    raise Flaky(
+        u'Run failed initially but succeeded on a second try'
+    )
 
 
 class GenericStateMachine(object):
@@ -208,19 +207,23 @@ class StateMachineRunner(object):
         if print_steps is None:
             print_steps = current_verbosity() >= Verbosity.debug
 
-        stopping_value = 1 - 1.0 / (1 + self.n_steps)
+        stopping_value = 1 - 1.0 / (1 + self.n_steps * 0.5)
         try:
-            for _ in hrange(self.n_steps):
+            steps = 0
+            while True:
+                if steps == self.n_steps:
+                    stopping_value = 0
                 self.data.start_example()
                 if not cu.biased_coin(self.data, stopping_value):
                     self.data.stop_example()
                     break
 
                 value = self.data.draw(state_machine.steps())
-
-                if print_steps:
-                    state_machine.print_step(value)
-                state_machine.execute_step(value)
+                steps += 1
+                if steps <= self.n_steps:
+                    if print_steps:
+                        state_machine.print_step(value)
+                    state_machine.execute_step(value)
                 self.data.stop_example()
         finally:
             state_machine.teardown()
@@ -417,7 +420,7 @@ class RuleBasedStateMachine(GenericStateMachine):
             valid = True
             if rule.precondition is not None and not rule.precondition(self):
                 continue
-            for k, v in rule.arguments.items():
+            for k, v in sorted(rule.arguments.items()):
                 if isinstance(v, Bundle):
                     bundle = self.bundle(v.name)
                     if not bundle:
diff --git a/src/hypothesis/strategies.py b/src/hypothesis/strategies.py
index a6bbfcb..4fe45d0 100644
--- a/src/hypothesis/strategies.py
+++ b/src/hypothesis/strategies.py
@@ -613,7 +613,11 @@ def binary(
     min_size, average_size and max_size have the usual interpretations.
 
     """
-    from hypothesis.searchstrategy.strings import BinaryStringStrategy
+    from hypothesis.searchstrategy.strings import BinaryStringStrategy, \
+        FixedSizeBytes
+    check_valid_sizes(min_size, average_size, max_size)
+    if min_size == max_size is not None:
+        return FixedSizeBytes(min_size)
     return BinaryStringStrategy(
         lists(
             integers(min_value=0, max_value=255),
diff --git a/src/hypothesis/version.py b/src/hypothesis/version.py
index c282275..db28c25 100644
--- a/src/hypothesis/version.py
+++ b/src/hypothesis/version.py
@@ -16,5 +16,5 @@
 
 from __future__ import division, print_function, absolute_import
 
-__version_info__ = (3, 0, 0)
+__version_info__ = (3, 0, 1)
 __version__ = '.'.join(map(str, __version_info__))
diff --git a/tests/cover/test_simple_strings.py b/tests/cover/test_simple_strings.py
index d4d26ab..0d9e301 100644
--- a/tests/cover/test_simple_strings.py
+++ b/tests/cover/test_simple_strings.py
@@ -117,3 +117,9 @@ def test_can_exclude_newlines_by_category(s):
 @given(text(characters(max_codepoint=127)))
 def test_can_restrict_to_ascii_only(s):
     s.encode('ascii')
+
+
+def test_fixed_size_bytes_just_draw_bytes():
+    from hypothesis.internal.conjecture.data import TestData
+    x = TestData.for_buffer(b'foo')
+    assert x.draw(binary(min_size=3, max_size=3)) == b'foo'
diff --git a/tests/cover/test_stateful.py b/tests/cover/test_stateful.py
index a041ecc..97d6df0 100644
--- a/tests/cover/test_stateful.py
+++ b/tests/cover/test_stateful.py
@@ -24,13 +24,14 @@ import pytest
 from hypothesis import settings as Settings
 from hypothesis import assume
 from hypothesis.errors import Flaky, InvalidDefinition
+from hypothesis.control import current_build_context
 from tests.common.utils import raises, capture_out
 from hypothesis.database import ExampleDatabase
 from hypothesis.stateful import rule, Bundle, precondition, \
     GenericStateMachine, RuleBasedStateMachine, \
     run_state_machine_as_test
-from hypothesis.strategies import just, none, lists, tuples, booleans, \
-    integers, sampled_from
+from hypothesis.strategies import just, none, lists, binary, tuples, \
+    booleans, integers, sampled_from
 
 
 class SetStateMachine(GenericStateMachine):
@@ -235,6 +236,26 @@ def test_can_get_test_case_off_machine_instance():
     assert GoodSet().TestCase is not None
 
 
+class FlakyDrawLessMachine(GenericStateMachine):
+
+    def steps(self):
+        cb = current_build_context()
+        if cb.is_final:
+            return binary(min_size=1, max_size=1)
+        else:
+            return binary(min_size=1024, max_size=1024)
+
+    def execute_step(self, step):
+        cb = current_build_context()
+        if not cb.is_final:
+            assert 0 not in bytearray(step)
+
+
+def test_flaky_draw_less_raises_flaky():
+    with raises(Flaky):
+        FlakyDrawLessMachine.TestCase().runTest()
+
+
 class FlakyStateMachine(GenericStateMachine):
 
     def steps(self):

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/python-modules/packages/python-hypothesis.git



More information about the Python-modules-commits mailing list