def test_loading_profile_keeps_expected_behaviour(): Settings.register_profile('ci', Settings(max_examples=10000)) Settings.load_profile('ci') assert Settings().max_examples == 10000 with Settings(max_examples=5): assert Settings().max_examples == 5 assert Settings().max_examples == 10000
def test_inherits_an_empty_database(db): assert Settings.default.database is not None s = Settings(database=db) assert s.database is db with s: t = Settings() assert t.database is db
def test_cannot_define_a_setting_with_default_not_valid(): with pytest.raises(InvalidArgument): Settings.define_setting( 'kittens', default=8, description='Kittens are pretty great', options=(1, 2, 3, 4), )
def test_define_setting_then_loading_profile(): x = Settings() Settings.define_setting( u'fun_times', default=3, description=u'Something something spoon', options=(1, 2, 3, 4), ) Settings.register_profile('hi', Settings(fun_times=2)) assert x.fun_times == 3 assert Settings.get_profile('hi').fun_times == 2
def test_load_profile(): Settings.load_profile('default') assert Settings.default.max_examples == 200 assert Settings.default.max_shrinks == 500 assert Settings.default.min_satisfying_examples == 5 Settings.register_profile( 'test', Settings( max_examples=10, max_shrinks=5 ) ) Settings.load_profile('test') assert Settings.default.max_examples == 10 assert Settings.default.max_shrinks == 5 assert Settings.default.min_satisfying_examples == 5 Settings.load_profile('default') assert Settings.default.max_examples == 200 assert Settings.default.max_shrinks == 500 assert Settings.default.min_satisfying_examples == 5
def test_will_handle_a_really_weird_failure(self, rnd): db = ExampleDatabase() @given(specifier, settings=Settings( settings, database=db, max_examples=max_examples, min_satisfying_examples=2, average_list_length=2.0, ), random=rnd) def nope(x): s = hashlib.sha1(repr(x).encode(u'utf-8')).digest() assert Random(s).randint(0, 1) == Random(s).randint(0, 1) if Random(s).randint(0, 1): raise Rejected(u'%r with digest %r' % (x, s)) try: try: nope() except Rejected: pass try: nope() except Rejected: pass finally: db.close()
def find(specifier, condition, settings=None, random=None, storage=None): settings = settings or Settings( max_examples=2000, min_satisfying_examples=0, max_shrinks=2000, ) search = strategy(specifier, settings) if storage is None and settings.database is not None: storage = settings.database.storage( u'find(%s)' % (binascii.hexlify(function_digest(condition)).decode(u'ascii'), )) random = random or Random() successful_examples = [0] def template_condition(template): with BuildContext(): result = search.reify(template) success = condition(result) if success: successful_examples[0] += 1 if not successful_examples[0]: verbose_report(lambda: u'Trying example %s' % (repr(result), )) elif success: if successful_examples[0] == 1: verbose_report(lambda: u'Found satisfying example %s' % (repr(result), )) else: verbose_report(lambda: u'Shrunk example to %s' % (repr(result), )) return success template_condition.__name__ = condition.__name__ tracker = Tracker() try: template = best_satisfying_template( search, random, template_condition, settings, tracker=tracker, max_parameter_tries=2, storage=storage, ) with BuildContext(): return search.reify(template) except Timeout: raise except NoSuchExample: if search.template_upper_bound <= len(tracker): raise DefinitelyNoSuchExample( get_pretty_function_description(condition), search.template_upper_bound, ) raise NoSuchExample(get_pretty_function_description(condition))
def test_will_handle_a_really_weird_failure(self): db = ExampleDatabase() @given( specifier, settings=Settings( database=db, max_examples=max_examples, min_satisfying_examples=2, average_list_length=2.0, ) ) def nope(x): s = hashlib.sha1(show(x).encode('utf-8')).digest() if Random(s).randint(0, 1): raise Rejected() try: try: nope() except Rejected: pass try: nope() except Rejected: pass finally: db.close()
def test_puts_elements_of_set_in_database(): database = ExampleDatabase(backend=SQLiteBackend(':memory:')) verifier = Verifier(settings=Settings(database=database)) verifier.falsify(lambda x: not x, {int}) assert list(database.storage_for([int]).fetch()) == [] assert list(database.storage_for({int}).fetch()) == [{0}] assert list(database.storage_for(int).fetch()) == [0]
def __call__(self, specifier, settings=None): from hypothesis.searchstrategy.strategies import SearchStrategy if isinstance(specifier, SearchStrategy): return specifier self.load_deprecated_api() if settings is None: settings = Settings() try: result = super(StrategyExtMethod, self).__call__( specifier, settings) except NotImplementedError: quiet_raise(NotImplementedError(( 'Expected a SearchStrategy but got %r of type %s. ' 'Note: This is a NotImplementedError for legacy reasons and ' 'will become an InvalidArgumentError in Hypothesis 2.0.' ) % (specifier, type(specifier).__name__))) note_deprecation(( 'Conversion of %r to strategy is deprecated ' 'and will be removed in Hypothesis 2.0. Use %r instead.') % ( specifier, result ), settings) assert isinstance(result, SearchStrategy) return result
def test_prints_debug_on_no_simplification(): with Settings(verbosity=Verbosity.debug): with capture_out() as o: find(just(u'hi'), bool) v = o.getvalue() print(v) assert u'No simplifiers' in v
def test_can_use_values_in_the_database(): example = 'Hello world' database = ExampleDatabase(backend=SQLiteBackend(':memory:')) storage = database.storage_for(text_type) storage.save(example) verifier = Verifier(settings=Settings(database=database)) assert verifier.falsify(lambda x: x != example, text_type) == (example, )
def find(specifier, condition, settings=None, random=None): settings = settings or Settings( max_examples=2000, min_satisfying_examples=0, ) search = strategy(specifier, settings) random = random or Random() def template_condition(template): return assume(condition(search.reify(template))) template_condition.__name__ = condition.__name__ tracker = Tracker() try: return search.reify( best_satisfying_template( search, random, template_condition, settings, None, tracker=tracker, )) except NoSuchExample: if search.size_upper_bound <= len(tracker): raise DefinitelyNoSuchExample( get_pretty_function_description(condition), search.size_upper_bound, ) raise NoSuchExample(get_pretty_function_description(condition))
def test_reports_differently_for_single_shrink(): with capture_verbosity(Verbosity.verbose) as o: @fails @given(basic(SillyStrategy), settings=Settings(database=None)) def test_foo(x): assert False test_foo() assert u'shrunk example once' in o.getvalue()
def test_includes_progress_in_verbose_mode(): with capture_verbosity(Verbosity.verbose) as o: with Settings(verbosity=Verbosity.verbose): find(lists(integers()), lambda x: sum(x) >= 1000000) out = o.getvalue() assert out assert u'Shrunk example' in out assert u'Found satisfying example' in out
def test_puts_keyword_arguments_in_the_database_from_given(): database = ExampleDatabase(backend=SQLiteBackend(':memory:')) verifier = Verifier(settings=Settings(database=database)) @given(x=int, verifier=verifier) def a_test(x): assert False with pytest.raises(AssertionError): a_test() assert list(database.storage_for(int).fetch()) == [0]
def test_will_find_a_failure_from_the_database(self): db = ExampleDatabase() @given(specifier, settings=Settings(max_examples=10, database=db)) def nope(x): raise Rejected() try: for i in hrange(3): self.assertRaises(Rejected, nope) # pragma: no cover finally: db.close()
def __init__(self, base, extend, max_leaves): self.max_leaves = max_leaves self.base = TemplateLimitedStrategy(base) self.extend = extend with Settings(average_list_length=2): strategies = [self.base, self.extend(self.base)] while 2**len(strategies) <= max_leaves: strategies.append(extend(OneOfStrategy(tuple(strategies)))) super(RecursiveStrategy, self).__init__(OneOfStrategy(tuple(strategies)))
def __init__(self, strategy, constraint=None, execute=None, settings=None): self.strategy = strategy self.constraint = constraint self.settings = settings or Settings( max_examples=10000, max_iterations=10000, max_shrinks=5000, ) self.constraint = constraint or (lambda x: True) self.execute = execute or (lambda f: f()) self._set_template() ALL_FIXTURES.append(weakref.ref(self))
def test_load_profile(): Settings.load_profile('default') assert Settings.default.max_examples == 200 assert Settings.default.max_shrinks == 500 assert Settings.default.min_satisfying_examples == 5 Settings.register_profile('test', Settings(max_examples=10, max_shrinks=5)) Settings.load_profile('test') assert Settings.default.max_examples == 10 assert Settings.default.max_shrinks == 5 assert Settings.default.min_satisfying_examples == 5 Settings.load_profile('default') assert Settings.default.max_examples == 200 assert Settings.default.max_shrinks == 500 assert Settings.default.min_satisfying_examples == 5
def test_prints_initial_attempts_on_find(): with capture_verbosity(Verbosity.verbose) as o: with Settings(verbosity=Verbosity.verbose): seen = [] def not_first(x): if not seen: seen.append(x) return False return x not in seen find(integers(), not_first) assert u'Trying example' in o.getvalue()
def __call__(self, specifier, settings=None): if isinstance(specifier, SearchStrategy): return specifier if settings is None: settings = Settings() note_deprecation( ('Calling strategy with non-strategy object %s is deprecated ' 'and will be removed in Hypothesis 2.0. Use the functions in ' 'hypothesis.strategies instead.') % (repr(specifier), ), settings) result = super(StrategyExtMethod, self).__call__(specifier, settings) assert isinstance(result, SearchStrategy) return result
def find(specifier, condition, settings=None, random=None): settings = settings or Settings( max_examples=2000, min_satisfying_examples=0, ) search = strategy(specifier, settings) random = random or Random() successful_examples = [0] def template_condition(template): result = search.reify(template) success = condition(result) if success: successful_examples[0] += 1 if not successful_examples[0]: verbose_report(lambda: 'Trying example %s' % (show(result), )) elif success: if successful_examples[0] == 1: verbose_report(lambda: 'Found satisfying example %s' % (show(result), )) else: verbose_report(lambda: 'Shrunk example to %s' % (show(result), )) return assume(success) template_condition.__name__ = condition.__name__ tracker = Tracker() try: return search.reify( best_satisfying_template( search, random, template_condition, settings, None, tracker=tracker, )) except NoSuchExample: if search.size_upper_bound <= len(tracker): raise DefinitelyNoSuchExample( get_pretty_function_description(condition), search.size_upper_bound, ) raise NoSuchExample(get_pretty_function_description(condition))
def __call__(self, specifier, settings=None): from hypothesis.searchstrategy.strategies import SearchStrategy if isinstance(specifier, SearchStrategy): return specifier self.load_deprecated_api() if settings is None: settings = Settings() result = super(StrategyExtMethod, self).__call__(specifier, settings) note_deprecation( ('Conversion of %r to strategy is deprecated ' 'and will be removed in Hypothesis 2.0. Use %r instead.') % (specifier, result), settings) assert isinstance(result, SearchStrategy) return result
def test_does_print_verbose_in_debug(): with Settings(verbosity=Verbosity.debug): with capture_out() as o: verbose_report(u'Hi') assert u'Hi' in o.getvalue()
def test_does_not_print_debug_in_verbose(): with Settings(verbosity=Verbosity.verbose): with capture_out() as o: debug_report(u'Hi') assert not o.getvalue()
class ValidationSuite(TestCase): def __repr__(self): return 'strategy_test_suite(%s)' % (show(specifier), ) @given(specifier, settings=settings) def test_does_not_error(self, value): pass def test_can_give_example(self): strat.example() def test_can_give_list_of_examples(self): strategy([strat]).example() def test_will_give_unsatisfiable_if_all_rejected(self): @given(specifier, settings=settings) def nope(x): assume(False) with self.assertRaises(Unsatisfiable): nope() def test_will_find_a_constant_failure(self): @given(specifier, settings=settings) def nope(x): raise Rejected() with self.assertRaises(Rejected): nope() def test_will_find_a_failure_from_the_database(self): db = ExampleDatabase() @given(specifier, settings=Settings(max_examples=10, database=db)) def nope(x): raise Rejected() try: for _ in hrange(3): with self.assertRaises(Rejected): nope() # pragma: no branch finally: db.close() def test_will_handle_a_really_weird_failure(self): @given(specifier, settings=settings) def nope(x): if hash(show(specifier)) % 2: raise Rejected() try: nope() except Rejected: pass @specifier_test def test_is_basic(self, value, rnd): def is_basic(v): return isinstance( v, integer_types + (list, type(None), text_type)) and ( not isinstance(v, list) or all(is_basic(w) for w in v)) supposedly_basic = strat.to_basic(value) self.assertTrue(is_basic(supposedly_basic), repr(supposedly_basic)) @specifier_test def test_only_raises_bad_data_in_from_basic(self, value, rnd): basic = strat.to_basic(value) messed_basic = mutate_basic(basic, rnd) try: strat.from_basic(messed_basic) except BadData: pass @specifier_test def test_can_round_trip_through_the_database(self, template, rnd): empty_db = ExampleDatabase(backend=SQLiteBackend(':memory:'), ) try: storage = empty_db.storage_for(specifier) storage.save(template) values = list(storage.fetch()) assert len(values) == 1 assert strat.to_basic(template) == strat.to_basic(values[0]) finally: empty_db.close() @specifier_test def test_template_is_hashable(self, template, rnd): hash(template) # It can be easy to forget to convert a list... hash(strat.from_basic(strat.to_basic(template))) @given(TemplatesFor(specifier), Random, [[int]], settings=settings) def test_apply_all_simplifiers(self, template, rnd, path): path = list(filter(None, path)) assume(path) current_template = template for local_route in path: simplifiers = list(strat.simplifiers(current_template)) if not simplifiers: break for i in local_route: simplify = simplifiers[abs(i) % len(simplifiers)] simpler = list(simplify(rnd, current_template)) if simpler: current_template = random.choice(simpler) @specifier_test def test_can_minimize_to_empty(self, template, rnd): simplest = list( strat.simplify_such_that(rnd, template, lambda x: True))[-1] assert list(strat.full_simplify(rnd, simplest)) == [] @specifier_test def test_can_complete_falsify_loop(self, template, rnd): for _ in strat.full_simplify(rnd, template): pass @given(Random, settings=Settings(max_examples=1000)) def test_can_create_templates(self, random): parameter = strat.draw_parameter(random) strat.draw_template(BuildContext(random), parameter)
def test_modifying_registered_profile_does_not_change_profile(): ci_profile = Settings(max_examples=10000) Settings.register_profile('ci', ci_profile) ci_profile.max_examples = 1 Settings.load_profile('ci') assert Settings().max_examples == 10000
def setup_function(fn): Settings.load_profile('default') Settings.register_profile('test_settings', Settings()) Settings.load_profile('test_settings')
class ValidationSuite(TestCase): def __repr__(self): return u'strategy_test_suite(%s)' % (repr(specifier), ) @given(specifier, settings=settings) def test_does_not_error(self, value): pass def test_can_give_example(self): strat.example() def test_can_give_list_of_examples(self): strategy(lists(strat)).example() def test_will_give_unsatisfiable_if_all_rejected(self): @given(specifier, settings=settings) def nope(x): assume(False) self.assertRaises(Unsatisfiable, nope) def test_will_find_a_constant_failure(self): @given(specifier, settings=settings) def nope(x): raise Rejected() self.assertRaises(Rejected, nope) def test_will_find_a_failure_from_the_database(self): db = ExampleDatabase() @given(specifier, settings=Settings(settings, max_examples=10, database=db)) def nope(x): raise Rejected() try: for i in hrange(3): self.assertRaises(Rejected, nope) # pragma: no cover finally: db.close() @given(templates_for(specifier), templates_for(specifier), settings=settings) def test_simplicity_is_asymmetric(self, x, y): assert not (strat.strictly_simpler(x, y) and strat.strictly_simpler(y, x)) @given(integers(), settings=settings) def test_templates_generated_from_same_random_are_equal(self, i): try: t1 = strat.draw_and_produce(Random(i)) t2 = strat.draw_and_produce(Random(i)) except BadTemplateDraw: assume(False) if t1 is not t2: assert t1 == t2 assert hash(t1) == hash(t2) @given(integers(), settings=settings) def test_templates_generated_from_same_random_are_equal_after_reify( self, i): try: t1 = strat.draw_and_produce(Random(i)) t2 = strat.draw_and_produce(Random(i)) except BadTemplateDraw: assume(False) if t1 is not t2: with BuildContext(): strat.reify(t1) with BuildContext(): strat.reify(t2) assert t1 == t2 assert hash(t1) == hash(t2) @given(randoms(), settings=settings) def test_will_handle_a_really_weird_failure(self, rnd): db = ExampleDatabase() @given(specifier, settings=Settings( settings, database=db, max_examples=max_examples, min_satisfying_examples=2, average_list_length=2.0, ), random=rnd) def nope(x): s = hashlib.sha1(repr(x).encode(u'utf-8')).digest() assert Random(s).randint(0, 1) == Random(s).randint(0, 1) if Random(s).randint(0, 1): raise Rejected(u'%r with digest %r' % (x, s)) try: try: nope() except Rejected: pass try: nope() except Rejected: pass finally: db.close() @specifier_test def test_is_basic(self, value, rnd): def is_basic(v): if v is None or isinstance(v, text_type): return True if isinstance(v, integer_types): return not (abs(v) >> 64) if isinstance(v, list): return all(is_basic(w) for w in v) return False supposedly_basic = strat.to_basic(value) self.assertTrue(is_basic(supposedly_basic), repr(supposedly_basic)) @specifier_test def test_only_raises_bad_data_in_from_basic(self, value, rnd): basic = strat.to_basic(value) messed_basic = mutate_basic(basic, rnd) try: strat.from_basic(messed_basic) except BadData: pass @specifier_test def test_can_round_trip_through_the_database(self, template, rnd): empty_db = ExampleDatabase(backend=SQLiteBackend(u':memory:'), ) try: storage = empty_db.storage(u'round trip') storage.save(template, strat) values = list(storage.fetch(strat)) assert len(values) == 1 assert strat.to_basic(template) == strat.to_basic(values[0]) finally: empty_db.close() @specifier_test def test_template_is_hashable(self, template, rnd): hash(template) # It can be easy to forget to convert a list... hash(strat.from_basic(strat.to_basic(template))) @specifier_test def test_can_minimize_to_empty(self, template, rnd): simplest = template tracker = Tracker() while True: for t in strat.full_simplify(rnd, simplest): if tracker.track(t) == 1: simplest = t break else: break assert list(strat.full_simplify(rnd, simplest)) == [] @specifier_test def test_full_simplify_completes(self, template, rnd): # Cut off at 100 for the occasional case where we get # really very large templates which have too many simplifies. for x in islice(strat.full_simplify(rnd, template), 100): pass @specifier_test def test_does_not_increase_complexity(self, template, rnd): for s in islice(strat.full_simplify(rnd, template), 100): assert not strat.strictly_simpler(template, s) @given(randoms(), settings=Settings(settings, max_examples=100)) def test_can_create_templates(self, random): parameter = strat.draw_parameter(random) try: strat.draw_template(random, parameter) except BadTemplateDraw: assume(False)
def test_cannot_set_non_settings(): s = Settings() with pytest.raises(AttributeError): s.databas_file = 'some_file'
import pytest from hypothesis.settings import Settings from hypothesis.internal.debug import timeout from hypothesis.strategytests import templates_for from tests.common.basic import Bitfields from hypothesis.strategies import integers, floats, just, one_of, \ sampled_from, streaming, basic, lists, booleans, dictionaries, tuples, \ frozensets, complex_numbers, sets, text, binary, decimals, fractions, \ none, randoms, builds, fixed_dictionaries, recursive from hypothesis.internal.compat import hrange from hypothesis.searchstrategy.narytree import n_ary_tree from hypothesis.utils.show import show settings = Settings(max_examples=100, timeout=4) __all__ = [u'small_verifier', u'timeout', u'standard_types', u'OrderedPair'] OrderedPair = namedtuple(u'OrderedPair', (u'left', u'right')) ordered_pair = integers().flatmap( lambda right: integers(min_value=0).map( lambda length: OrderedPair(right - length, right))) def constant_list(strat): return strat.flatmap( lambda v: lists(just(v)),
def __call__(self, specifier, settings=None): if settings is None: settings = Settings() result = super(StrategyExtMethod, self).__call__(specifier, settings) assert isinstance(result, SearchStrategy) return result
def test_load_non_existent_profile(): with pytest.raises(hypothesis.errors.InvalidArgument): Settings.get_profile('nonsense')
def test_verifier_explodes_when_you_mix_random_and_derandom(): settings = Settings(derandomize=True) with pytest.raises(ValueError): Verifier(settings=settings, random=Random())
from hypothesis.errors import Flaky, NoSuchExample, InvalidDefinition, \ UnsatisfiedAssumption from hypothesis.settings import Settings, Verbosity from hypothesis.reporting import report, verbose_report, current_verbosity from hypothesis.internal.compat import hrange, integer_types from hypothesis.searchstrategy.misc import JustStrategy, \ SampledFromStrategy from hypothesis.searchstrategy.strategies import BadData, SearchStrategy, \ strategy, check_length, check_data_type, one_of_strategies from hypothesis.searchstrategy.collections import TupleStrategy, \ FixedKeysDictStrategy Settings.define_setting( name='stateful_step_count', default=50, description=""" Number of steps to run a stateful program for before giving up on it breaking. """ ) class TestCaseProperty(object): # pragma: no cover def __get__(self, obj, typ=None): if obj is not None: typ = type(obj) return typ._to_test_case() def __set__(self, obj, value): raise AttributeError('Cannot set TestCase')
# obtain one at http://mozilla.org/MPL/2.0/. # END HEADER from __future__ import division, print_function, absolute_import, \ unicode_literals import pytest from hypothesis.errors import InvalidArgument from hypothesis.settings import Settings, Verbosity TEST_DESCRIPTION = 'This is a setting just for these tests' Settings.define_setting( 'a_setting_just_for_these_tests', default=3, description=TEST_DESCRIPTION, ) Settings.define_setting( 'a_setting_with_limited_options', default=3, description='Something something spoon', options=(1, 2, 3, 4), ) def test_has_docstrings(): assert TEST_DESCRIPTION in Settings.a_setting_just_for_these_tests.__doc__
"""A strategy which produces dicts with a fixed set of keys, given a strategy for each of their equivalent values. e.g. {'foo' : some_int_strategy} would generate dicts with the single key 'foo' mapping to some integer. """ def __init__(self, strategy_dict): self.dict_type = type(strategy_dict) if isinstance(strategy_dict, OrderedDict): self.keys = tuple(strategy_dict.keys()) else: try: self.keys = tuple(sorted(strategy_dict.keys())) except TypeError: self.keys = tuple(sorted(strategy_dict.keys(), key=show)) super(FixedKeysDictStrategy, self).__init__( strategy=TupleStrategy((strategy_dict[k] for k in self.keys), tuple) ) def __repr__(self): return u"FixedKeysDictStrategy(%r, %r)" % (self.keys, self.mapped_strategy) def pack(self, value): return self.dict_type(zip(self.keys, value)) Settings.define_setting(u"average_list_length", default=25.0, description=u"Average length of lists to use")
""" def __init__(self, strategy_dict): self.dict_type = type(strategy_dict) if isinstance(strategy_dict, OrderedDict): self.keys = tuple(strategy_dict.keys()) else: try: self.keys = tuple(sorted(strategy_dict.keys(), )) except TypeError: self.keys = tuple(sorted( strategy_dict.keys(), key=show, )) super( FixedKeysDictStrategy, self).__init__(strategy=TupleStrategy((strategy_dict[k] for k in self.keys), tuple)) def __repr__(self): return 'FixedKeysDictStrategy(%r, %r)' % (self.keys, self.mapped_strategy) def pack(self, value): return self.dict_type(zip(self.keys, value)) Settings.define_setting('average_list_length', default=25.0, description='Average length of lists to use')
def test_loading_profile_resets_defaults(): assert Settings.default.min_satisfying_examples == 5 Settings.default.min_satisfying_examples = 100 assert Settings.default.min_satisfying_examples == 100 Settings.load_profile('default') assert Settings.default.min_satisfying_examples == 5
def test_can_assign_database(db): x = Settings() assert x.database is not None x.database = db assert x.database is db
import os import pytest import hypothesis from hypothesis.errors import InvalidArgument from hypothesis.database import ExampleDatabase from hypothesis.settings import Settings, Verbosity def test_has_docstrings(): assert Settings.verbosity.__doc__ original_default = Settings.get_profile('default').max_examples def setup_function(fn): Settings.load_profile('default') Settings.register_profile('test_settings', Settings()) Settings.load_profile('test_settings') def test_cannot_set_non_settings(): s = Settings() with pytest.raises(AttributeError): s.databas_file = u'some_file' def test_settings_uses_defaults():
@strategy.extend(frozenset) def define_frozen_set_strategy(specifier, settings): return FrozenSetStrategy(strategy(set(specifier), settings)) @strategy.extend(list) def define_list_strategy(specifier, settings): return ListStrategy( [strategy(d, settings) for d in specifier], average_length=settings.average_list_length ) Settings.define_setting( 'average_list_length', default=50.0, description='Average length of lists to use' ) @strategy.extend(tuple) def define_tuple_strategy(specifier, settings): return TupleStrategy( tuple(strategy(d, settings) for d in specifier), tuple_type=type(specifier) ) @strategy.extend(dict) def define_dict_strategy(specifier, settings): strategy_dict = {}
# This Source Code Form is subject to the terms of the Mozilla Public License, # v. 2.0. If a copy of the MPL was not distributed with this file, You can # obtain one at http://mozilla.org/MPL/2.0/. # END HEADER from __future__ import division, print_function, absolute_import import pytest from hypothesis.errors import InvalidArgument from hypothesis.settings import Settings, Verbosity TEST_DESCRIPTION = u"This is a setting just for these tests" Settings.define_setting(u"a_setting_just_for_these_tests", default=3, description=TEST_DESCRIPTION) Settings.define_setting( u"a_setting_with_limited_options", default=3, description=u"Something something spoon", options=(1, 2, 3, 4) ) def test_has_docstrings(): assert TEST_DESCRIPTION in Settings.a_setting_just_for_these_tests.__doc__ def setup_function(fn): try: delattr(Settings.default, u"a_setting_just_for_these_tests") except AttributeError: