File: test_status.py

package info (click to toggle)
vdirsyncer 0.20.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 944 kB
  • sloc: python: 7,380; makefile: 205; sh: 66
file content (38 lines) | stat: -rw-r--r-- 1,189 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
from __future__ import annotations

import hypothesis.strategies as st
from hypothesis import assume
from hypothesis import given

from vdirsyncer.sync.status import SqliteStatus

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(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 = SqliteStatus()
    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

    status.close()