def integers(min_value=None, max_value=None): """Returns a strategy which generates integers (in Python 2 these may be ints or longs). If min_value is not None then all values will be >= min_value. If max_value is not None then all values will be <= max_value """ from hypothesis.searchstrategy.numbers import IntegersFromStrategy, \ BoundedIntStrategy, RandomGeometricIntStrategy, WideRangeIntStrategy if min_value is None: if max_value is None: return ( RandomGeometricIntStrategy() | WideRangeIntStrategy() ) else: check_type(integer_types, max_value) return IntegersFromStrategy(0).map(lambda x: max_value - x) else: check_type(integer_types, min_value) if max_value is None: return IntegersFromStrategy(min_value) else: if min_value == max_value: return just(min_value) elif min_value > max_value: raise InvalidArgument( u'Cannot have max_value=%r < min_value=%r' % ( max_value, min_value )) return BoundedIntStrategy(min_value, max_value)
def integers(min_value=None, max_value=None): """Returns a strategy which generates integers (in Python 2 these may be ints or longs). If min_value is not None then all values will be >= min_value. If max_value is not None then all values will be <= max_value """ check_valid_integer(min_value) check_valid_integer(max_value) check_valid_interval(min_value, max_value, 'min_value', 'max_value') from hypothesis.searchstrategy.numbers import IntegersFromStrategy, \ BoundedIntStrategy, RandomGeometricIntStrategy, WideRangeIntStrategy if min_value is None: if max_value is None: return (RandomGeometricIntStrategy() | WideRangeIntStrategy()) else: return IntegersFromStrategy(0).map(lambda x: max_value - x) else: if max_value is None: return IntegersFromStrategy(min_value) else: if min_value == max_value: return just(min_value) return BoundedIntStrategy(min_value, max_value)
def test_directly_joining_one_strategy_also_fails(): with pytest.raises(ValueError): OneOfStrategy([RandomGeometricIntStrategy()])