def test_equality_is_symmetric(d, r): test_cases = [d] for _ in hrange(10): test_cases.append(mutate_slightly(r, d)) for x in test_cases: for y in test_cases: if actually_equal(x, y): assert actually_equal(y, x)
def test_equality_is_transitive(d, r): test_cases = [d] for _ in hrange(10): test_cases.append(mutate_slightly(r, d)) for x in test_cases: for y in test_cases: if actually_equal(x, y): for z in test_cases: if actually_equal(y, z): assert actually_equal(x, z)
def test_can_handle_collections_that_define_no_equality(): assert actually_equal( BadCollection(1, 2, 3), BadCollection(1, 2, 3), ) assert not actually_equal( BadCollection(1, 2, 3), BadCollection(1, 2, 4), )
def test_handles_strings_correctly(): s = hex(random.getrandbits(128)) rs = ''.join(reversed(s)) rrs = ''.join(reversed(rs)) assert s is not rrs assert s == rrs, (rrs, s) assert actually_equal(s, rrs)
def test_can_falsify_complex_numbers(): falsify(lambda x: assume(abs(x) <= 1000) and x == (x**2)**0.5, complex) with pytest.raises(Unfalsifiable): falsify( lambda x, y: actually_equal((x * y).conjugate(), x.conjugate() * y.conjugate()), complex, complex)
def run_round_trip(descriptor, value, format=None, backend=None): if backend is not None: backend = backend() else: backend = SQLiteBackend() db = ExampleDatabase(format=format, backend=backend) storage = db.storage_for(descriptor) storage.save(value) saved = list(storage.fetch()) assert actually_equal(saved, [value])
def test_two_objects_are_not(): assert not actually_equal(object(), object())
def test_an_object_is_actually_equal_to_itself(): x = object() assert actually_equal(x, x)
def test_fuzzy_equal_uses_full_repr_precision(): assert not actually_equal( 1113142313206.0, 1113142313208.0, fuzzy=True, )
def to_basic(self, c): if not actually_equal(c, self.value): raise WrongFormat('%r != %r' % (c, self.value)) return None
def could_have_produced(self, value): return actually_equal(self.descriptor.value, value)
def test_sets_are_equal_to_sets_correctly(): assert actually_equal({1, 2, 3}, {3, 2, 1}) assert not actually_equal({1, 2, 3}, {3, 2}) assert not actually_equal({3, 2}, {1, 2, 3}) assert not actually_equal({frozenset()}, {WeirdSet()})
def test_rejects_collections_which_lie_about_being_equal(): assert not actually_equal(LyingList([1, 2, 3]), LyingList([1, 2]))
def test_lists_of_different_length_are_not(): assert not actually_equal([1] * 3, [1] * 4)
def test_copies_all_its_values_correctly(desc, random): strategy = small_table.strategy(desc) value = strategy.produce(random, strategy.parameter.draw(random)) assert actually_equal(value, strategy.copy(value))
def test_lists_of_same_elements_are_equal(): assert actually_equal([1, 2, 3], [1, 2, 3])
def test_a_complex_is_fuzzy_equal_to_parsing_its_string(x): assert actually_equal(x, complex(repr(x)), fuzzy=True)
def test_a_float_is_fuzzy_equal_to_parsing_its_string(x): assert actually_equal(x, float(repr(x)), fuzzy=True)
def test_lists_of_different_elements_are_not(): assert not actually_equal([1, 2, 3], [1, 2, 4])
def test_respects_equality_given_no_reason_not_to(): assert actually_equal(Inclusive(), Inclusive())
def test_handles_ints_correctly(): assert actually_equal(1, 1) assert not actually_equal(1, 2)
def test_actually_equal_things_have_same_type_shape(d, r): for _ in hrange(10): d2 = mutate_slightly(r, d) if actually_equal(d, d2): assert type_shape(d) == type_shape(d2)
def test_rejects_equal_things_of_different_types(): assert not actually_equal(WeirdSet(), frozenset())
def test_dicts_of_same_length_but_different_keys_are_not_equal(): assert not actually_equal({1: 2}, {2: 1})
def test_dicts_of_same_length_but_not_actually_equal_values_are_not_equal(): assert actually_equal({1: 2}, {1: 2}) assert not actually_equal({1: frozenset()}, {1: WeirdSet()})
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 mutate_maliciously(random, d): for _ in hrange(10): d2 = mutate_slightly(random, d) if d == d2 and not actually_equal(d, d2): return d2 return d2
def test_sets_are_not_actually_equal_to_frozensets(): assert not actually_equal(set(), frozenset())
def test_lists_of_sets_are_not_actually_equal_to_lists_of_frozensets(): assert not actually_equal([set()], [frozenset()])
def test_can_handle_really_broken_dicts(): assert not actually_equal( BrokenEqDict({1: frozenset()}), BrokenEqDict({2: frozenset()}) )