def __init__(self, settings): super(DescriptorStrategy, self).__init__(strategy=strategy( NAryTree(branch_labels=sampled_from((tuple, dict, set, frozenset, list)), branch_keys=one_of((int, str)), leaf_values=sampled_from((int, float, text_type, binary_type, bool, complex, type(None)))), settings))
(complex, {'hi'}), ([{bool}], 0), (Just(1), 'hi'), (binary_type, 0.0), (binary_type, frozenset()), ({ True: {int} }, []), (Random, []), (int, ''), (text_type, 'kittens'), ((int, int, int), (1, 2)), (SampledFrom((1, 2, 3)), 'fish'), (SampledFrom((1, 2, 3)), 5), (SampledFrom((1, 2, 3)), -2), (OneOf((int, float)), 1), (OneOf((int, float)), 'tv'), (OneOf((int, float)), [-2, 0]), (binary_type, '1'), (float, -1), ([frozenset({float}), frozenset({float})], [[8, 0], []]), (float, 252010555201342071294067021251680995120), ((int, int), 10), (NAryTree(int, int, int), []), (NAryTree(int, int, int), [1, 2, 3, 4, 5]), ]) def test_simple_data_validation(specifier, data): converter = strategy(specifier) with pytest.raises(BadData): converter.from_basic(data)
TestString = strategy_test_suite(text_type) BinaryString = strategy_test_suite(binary_type) TestIntBool = strategy_test_suite((int, bool)) TestFloats = strategy_test_suite(float) TestComplex = strategy_test_suite(complex) TestJust = strategy_test_suite(just('hi')) TestTemplates = strategy_test_suite(TemplatesFor({int})) TestEmptyString = strategy_test_suite(strings(alphabet='')) TestSingleString = strategy_test_suite(strings(alphabet='a')) TestManyString = strategy_test_suite(strings(alphabet='abcdefâ')) Stuff = namedtuple('Stuff', ('a', 'b')) TestNamedTuple = strategy_test_suite(Stuff(int, int)) TestTrees = strategy_test_suite(NAryTree(int, int, int)) TestMixedSets = strategy_test_suite({int, bool, float}) TestFrozenSets = strategy_test_suite(frozenset({bool})) TestNestedSets = strategy_test_suite(frozenset({frozenset({complex})})) TestMisc1 = strategy_test_suite({(2, -374): frozenset({None})}) TestMisc2 = strategy_test_suite({b'': frozenset({int})}) TestMisc3 = strategy_test_suite(({type(None), str}, ), ) TestEmptyTuple = strategy_test_suite(()) TestEmptyList = strategy_test_suite([]) TestEmptySet = strategy_test_suite(set()) TestEmptyFrozenSet = strategy_test_suite(frozenset()) TestEmptyDict = strategy_test_suite({})
def test_tree(): tree = strategy(NAryTree(bool, bool, bool)).example() assert isinstance(tree, (Branch, Leaf))
@strategy.extend(ConstantList) def constant_list_strategy(spec, settings): return strategy(spec.spec, settings).flatmap(lambda v: [just(v)], ) ABC = namedtuple('ABC', ('a', 'b', 'c')) standard_types = [ Bitfields, [], (), set(), frozenset(), {}, NAryTree(bool, bool, bool), ABC(bool, bool, bool), ABC(bool, bool, int), { 'a': int, 'b': bool }, one_of((int, (bool, ))), sampled_from(range(10)), one_of((just('a'), just('b'), just('c'))), sampled_from(('a', 'b', 'c')), int, integers_from(3), integers_in_range(-2**32, 2**64), float, floats_in_range(-2.0, 3.0),
def dav_strategy(cls, settings): return strategy(NAryTree(int, int, int), settings).flatmap(nary_tree_to_descriptor)
def smallest_tree(predicate): d = NAryTree(int, int, int) strat = strategy(d) v = Verifier() return strat.reify(v.falsify(lambda t: not predicate(t), d)[0])
def smallest_tree(predicate): return minimal(NAryTree(int, int, int), predicate)