def test_backend_returns_what_you_put_in(xs): backend = SQLiteBackend(u':memory:') mapping = {} for key, value in xs: mapping.setdefault(key, set()).add(value) backend.save(key, value) for key, values in mapping.items(): backend_contents = list(backend.fetch(key)) distinct_backend_contents = set(backend_contents) assert len(backend_contents) == len(distinct_backend_contents) assert distinct_backend_contents == set(values)
def test_backend_returns_what_you_put_in(xs): backend = SQLiteBackend(':memory:') mapping = {} for key, value in xs: mapping.setdefault(key, set()).add(value) backend.save(key, value) for key, values in mapping.items(): backend_contents = list(backend.fetch(key)) distinct_backend_contents = set(backend_contents) assert len(backend_contents) == len(distinct_backend_contents) assert distinct_backend_contents == set(values)
def test_does_not_commit_in_error_state(): backend = SQLiteBackend(u':memory:') backend.create_db_if_needed() try: with backend.cursor() as cursor: cursor.execute(""" insert into hypothesis_data_mapping(key, value) values("a", "b") """) raise ValueError() except ValueError: pass assert backend.fetch(u'a') == []
def test_does_not_commit_in_error_state(): backend = SQLiteBackend(':memory:') backend.create_db_if_needed() try: with backend.cursor() as cursor: cursor.execute(""" insert into hypothesis_data_mapping(key, value) values("a", "b") """) raise ValueError() except ValueError: pass assert backend.fetch('a') == []
def test_can_delete_keys(): backend = SQLiteBackend(u':memory:') backend.save(u'foo', u'bar') backend.save(u'foo', u'baz') backend.delete(u'foo', u'bar') assert list(backend.fetch(u'foo')) == [u'baz']
def test_can_delete_keys(): backend = SQLiteBackend(':memory:') backend.save('foo', 'bar') backend.save('foo', 'baz') backend.delete('foo', 'bar') assert list(backend.fetch('foo')) == ['baz']