streams.py 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. # coding=utf-8
  2. #
  3. # This file is part of Hypothesis, which may be found at
  4. # https://github.com/HypothesisWorks/hypothesis-python
  5. #
  6. # Most of this work is copyright (C) 2013-2018 David R. MacIver
  7. # (david@drmaciver.com), but it contains contributions by others. See
  8. # CONTRIBUTING.rst for a full list of people who may hold copyright, and
  9. # consult the git log if you need to determine who owns an individual
  10. # contribution.
  11. #
  12. # This Source Code Form is subject to the terms of the Mozilla Public License,
  13. # v. 2.0. If a copy of the MPL was not distributed with this file, You can
  14. # obtain one at http://mozilla.org/MPL/2.0/.
  15. #
  16. # END HEADER
  17. from __future__ import division, print_function, absolute_import
  18. from hypothesis.types import Stream
  19. from hypothesis.searchstrategy.strategies import SearchStrategy
  20. class StreamStrategy(SearchStrategy):
  21. supports_find = False
  22. def __init__(self, source_strategy):
  23. super(StreamStrategy, self).__init__()
  24. self.source_strategy = source_strategy
  25. def __repr__(self):
  26. return u'StreamStrategy(%r)' % (self.source_strategy,)
  27. def do_draw(self, data):
  28. data.can_reproduce_example_from_repr = False
  29. def gen():
  30. while True:
  31. yield data.draw(self.source_strategy)
  32. return Stream(gen())