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())'
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)))
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)
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))
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
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')"
def test_does_not_strip_brackets_when_not_present(): assert nice_string(complex('nanj')) == "complex('nanj')"
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'))"
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)
def test_nice_string_for_nasty_in_just(): assert nice_string(descriptors.just( complex('inf+1.9j'))) == "Just(value=complex('inf+1.9j'))"
def test_nice_string_for_nasty_complex(): assert nice_string(complex(float('inf'), 0.0)) == "complex('inf+0j')"
def test_nice_string_for_nice_complex(): assert nice_string(1 + 1j) == '(1+1j)'
def test_nice_string_evals_as_descriptor(desc): s = nice_string(desc) read_desc = eval(s) assert actually_equal(desc, read_desc, fuzzy=True)
def test_does_not_use_nasty_type_reprs_in_nice_string(desc): s = nice_string(desc) assert not UNDESIRABLE_STRINGS.findall(s)
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) ))
def __init__(self, descriptor): super(NotSerializeable, self).__init__( '%s does not describe a serializeable type' % ( nice_string(descriptor), ) )
def test_nice_string_for_sets_is_not_a_dict(): assert nice_string(set()) == repr(set()) assert nice_string(frozenset()) == repr(frozenset())
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)
def test_non_empty_frozensets_should_use_set_representation(): assert nice_string(frozenset([int])) == 'frozenset({int})'