Beispiel #1
0
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)
Beispiel #2
0
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)
Beispiel #3
0
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),
    )
Beispiel #4
0
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)
Beispiel #6
0
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])
Beispiel #7
0
def test_two_objects_are_not():
    assert not actually_equal(object(), object())
Beispiel #8
0
def test_an_object_is_actually_equal_to_itself():
    x = object()
    assert actually_equal(x, x)
Beispiel #9
0
def test_fuzzy_equal_uses_full_repr_precision():
    assert not actually_equal(
        1113142313206.0,
        1113142313208.0,
        fuzzy=True,
    )
Beispiel #10
0
 def to_basic(self, c):
     if not actually_equal(c, self.value):
         raise WrongFormat('%r != %r' % (c, self.value))
     return None
Beispiel #11
0
 def could_have_produced(self, value):
     return actually_equal(self.descriptor.value, value)
Beispiel #12
0
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()})
Beispiel #13
0
def test_rejects_collections_which_lie_about_being_equal():
    assert not actually_equal(LyingList([1, 2, 3]), LyingList([1, 2]))
Beispiel #14
0
def test_lists_of_different_length_are_not():
    assert not actually_equal([1] * 3, [1] * 4)
Beispiel #15
0
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))
Beispiel #16
0
def test_lists_of_same_elements_are_equal():
    assert actually_equal([1, 2, 3], [1, 2, 3])
Beispiel #17
0
def test_a_complex_is_fuzzy_equal_to_parsing_its_string(x):
    assert actually_equal(x, complex(repr(x)), fuzzy=True)
Beispiel #18
0
def test_a_float_is_fuzzy_equal_to_parsing_its_string(x):
    assert actually_equal(x, float(repr(x)), fuzzy=True)
Beispiel #19
0
def test_lists_of_different_elements_are_not():
    assert not actually_equal([1, 2, 3], [1, 2, 4])
Beispiel #20
0
def test_respects_equality_given_no_reason_not_to():
    assert actually_equal(Inclusive(), Inclusive())
Beispiel #21
0
def test_handles_ints_correctly():
    assert actually_equal(1, 1)
    assert not actually_equal(1, 2)
Beispiel #22
0
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)
Beispiel #23
0
def test_rejects_equal_things_of_different_types():
    assert not actually_equal(WeirdSet(), frozenset())
Beispiel #24
0
def test_dicts_of_same_length_but_different_keys_are_not_equal():
    assert not actually_equal({1: 2}, {2: 1})
Beispiel #25
0
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()})
Beispiel #26
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)
Beispiel #27
0
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
Beispiel #28
0
def test_sets_are_not_actually_equal_to_frozensets():
    assert not actually_equal(set(), frozenset())
Beispiel #29
0
def test_lists_of_sets_are_not_actually_equal_to_lists_of_frozensets():
    assert not actually_equal([set()], [frozenset()])
Beispiel #30
0
def test_can_handle_really_broken_dicts():
    assert not actually_equal(
        BrokenEqDict({1: frozenset()}),
        BrokenEqDict({2: frozenset()})
    )