vdirsyncer/tests/unit/sync/test_status.py
Hugo Osvaldo Barrera b1b4dd92fe Sort imports
I don't want to ever have to sort imports again. It's a poor use of
developer time. Automate this with a pre-commit hook, and check this on
CI.

Developers: I suggest you configure your editor to use
`reorder_python_imports`. It uses the standard sorting, and detects
first/third party libs well.
2020-06-09 14:34:45 +02:00

42 lines
1.2 KiB
Python

import hypothesis.strategies as st
import pytest
from hypothesis import assume
from hypothesis import given
from vdirsyncer.sync.status import SqliteStatus
@pytest.fixture(params=[
SqliteStatus
])
def new_status(request):
return request.param
status_dict_strategy = st.dictionaries(
st.text(),
st.tuples(*(
st.fixed_dictionaries({
'href': st.text(),
'hash': st.text(),
'etag': st.text()
}) for _ in range(2)
))
)
@given(status_dict=status_dict_strategy)
def test_legacy_status(new_status, status_dict):
hrefs_a = {meta_a['href'] for meta_a, meta_b in status_dict.values()}
hrefs_b = {meta_b['href'] for meta_a, meta_b in status_dict.values()}
assume(len(hrefs_a) == len(status_dict) == len(hrefs_b))
status = new_status()
status.load_legacy_status(status_dict)
assert dict(status.to_legacy_status()) == status_dict
for ident, (meta_a, meta_b) in status_dict.items():
ident_a, meta2_a = status.get_by_href_a(meta_a['href'])
ident_b, meta2_b = status.get_by_href_b(meta_b['href'])
assert meta2_a.to_status() == meta_a
assert meta2_b.to_status() == meta_b
assert ident_a == ident_b == ident