Ejemplo n.º 1
0
def test_just_nice_string_should_respect_its_values_reprs():
    class Stuff(object):
        def __repr__(self):
            return 'Things()'

    assert strat.nice_string(descriptors.Just(
        Stuff())) == 'Just(value=Things())'
Ejemplo n.º 2
0
 def to_basic(self, value):
     for i in hrange(len(self.converters)):  # pragma: no branch
         if self.strategies[i].could_have_produced(value):
             return [i, self.converters[i].to_basic(value)]
     raise WrongFormat('Value %r does not match any of %s' % (
         value, ', '.join(
             nice_string(s.descriptor) for s in self.strategies)))
Ejemplo n.º 3
0
 def __init__(self, backend, descriptor, converter, strategy, format):
     self.backend = backend
     self.descriptor = descriptor
     self.converter = converter
     self.format = format
     self.strategy = strategy
     self.key = nice_string(descriptor)
Ejemplo n.º 4
0
def test_cannot_generate_mutable_data_from_an_immutable_strategy(d):
    strategy = small_table.strategy(d)
    assume(strategy.has_immutable_data)
    really_small_verifier = Verifier(
        settings=hs.Settings(max_examples=50, timeout=5))

    with pytest.raises((Unfalsifiable, Unsatisfiable)):
        print(nice_string(d),
              really_small_verifier.falsify(is_immutable_data, d))
Ejemplo n.º 5
0
 def from_basic(self, value):
     if not self.strategy.could_have_produced(value):
         raise BadData('Data %r does not match description %s' % (
             value, nice_string(self.strategy.descriptor)
         ))
     return value
Ejemplo n.º 6
0
def test_nice_string_for_nasty_floats():
    assert nice_string(float('inf')) == "float('inf')"
    assert nice_string(float('-inf')) == "float('-inf')"
    assert nice_string(float('nan')) == "float('nan')"
Ejemplo n.º 7
0
def test_does_not_strip_brackets_when_not_present():
    assert nice_string(complex('nanj')) == "complex('nanj')"
Ejemplo n.º 8
0
def test_uses_nice_string_inside_named_tuples():
    Foo = namedtuple('Foo', ('b', 'a'))
    assert nice_string(Foo(1, float('nan'))) == "Foo(b=1, a=float('nan'))"
Ejemplo n.º 9
0
def test_set_descriptor_representation_is_stable_for_order():
    x = AwkwardSet(list(hrange(100)))
    assert repr(x) != repr(x)
    assert strat.nice_string(x) == strat.nice_string(x)
Ejemplo n.º 10
0
def test_nice_string_for_nasty_in_just():
    assert nice_string(descriptors.just(
        complex('inf+1.9j'))) == "Just(value=complex('inf+1.9j'))"
Ejemplo n.º 11
0
def test_nice_string_for_nasty_complex():
    assert nice_string(complex(float('inf'), 0.0)) == "complex('inf+0j')"
Ejemplo n.º 12
0
def test_nice_string_for_nice_complex():
    assert nice_string(1 + 1j) == '(1+1j)'
Ejemplo n.º 13
0
def test_nice_string_evals_as_descriptor(desc):
    s = nice_string(desc)
    read_desc = eval(s)
    assert actually_equal(desc, read_desc, fuzzy=True)
Ejemplo n.º 14
0
def test_does_not_use_nasty_type_reprs_in_nice_string(desc):
    s = nice_string(desc)
    assert not UNDESIRABLE_STRINGS.findall(s)
Ejemplo n.º 15
0
def check_matches(strategy, value):
    if not strategy.could_have_produced(value):
        raise WrongFormat('Value %r does not match description %s' % (
            value, nice_string(strategy.descriptor)
        ))
Ejemplo n.º 16
0
 def __init__(self, descriptor):
     super(NotSerializeable, self).__init__(
         '%s does not describe a serializeable type' % (
             nice_string(descriptor),
         )
     )
Ejemplo n.º 17
0
def test_nice_string_for_sets_is_not_a_dict():
    assert nice_string(set()) == repr(set())
    assert nice_string(frozenset()) == repr(frozenset())
Ejemplo n.º 18
0
def test_dict_descriptor_representation_is_stable_for_order():
    x = AwkwardDict({i: i for i in hrange(100)})
    assert strat.nice_string(x) == strat.nice_string(x)
Ejemplo n.º 19
0
def test_non_empty_frozensets_should_use_set_representation():
    assert nice_string(frozenset([int])) == 'frozenset({int})'