コード例 #1
0
def test_irrelevant_status():
    a = MemoryStorage()
    b = MemoryStorage()
    status = {'foo': 'bar'}

    metasync(a, b, status, keys=())
    assert not status
コード例 #2
0
def test_basic(monkeypatch):
    a = MemoryStorage()
    b = MemoryStorage()
    status = {}

    a.set_meta('foo', 'bar')
    metasync(a, b, status, keys=['foo'])
    assert a.get_meta('foo') == b.get_meta('foo') == 'bar'

    a.set_meta('foo', None)
    metasync(a, b, status, keys=['foo'])
    assert a.get_meta('foo') is None and b.get_meta('foo') is None

    a.set_meta('foo', 'baz')
    metasync(a, b, status, keys=['foo'])
    assert a.get_meta('foo') == b.get_meta('foo') == 'baz'

    monkeypatch.setattr(a, 'set_meta', blow_up)
    monkeypatch.setattr(b, 'set_meta', blow_up)
    metasync(a, b, status, keys=['foo'])
    assert a.get_meta('foo') == b.get_meta('foo') == 'baz'
    monkeypatch.undo()
    monkeypatch.undo()

    b.set_meta('foo', None)
    metasync(a, b, status, keys=['foo'])
    assert not a.get_meta('foo') and not b.get_meta('foo')
コード例 #3
0
def test_invalid_conflict_resolution(conflict_state):
    a, b, status = conflict_state

    with pytest.raises(UserError) as excinfo:
        metasync(a, b, status, keys=['foo'], conflict_resolution='foo')

    assert 'Invalid conflict resolution setting' in str(excinfo.value)
コード例 #4
0
def test_irrelevant_status():
    a = MemoryStorage()
    b = MemoryStorage()
    status = {"foo": "bar"}

    metasync(a, b, status, keys=())
    assert not status
コード例 #5
0
def test_irrelevant_status():
    a = MemoryStorage()
    b = MemoryStorage()
    status = {'foo': 'bar'}

    metasync(a, b, status, keys=())
    assert not status
コード例 #6
0
def test_conflict_same_content():
    a = MemoryStorage()
    b = MemoryStorage()
    status = {}
    a.set_meta('foo', 'bar')
    b.set_meta('foo', 'bar')

    metasync(a, b, status, keys=['foo'])
    assert a.get_meta('foo') == b.get_meta('foo') == status['foo'] == 'bar'
コード例 #7
0
def test_conflict_same_content():
    a = MemoryStorage()
    b = MemoryStorage()
    status = {}
    a.set_meta("foo", "bar")
    b.set_meta("foo", "bar")

    metasync(a, b, status, keys=["foo"])
    assert a.get_meta("foo") == b.get_meta("foo") == status["foo"] == "bar"
コード例 #8
0
def test_conflict_same_content():
    a = MemoryStorage()
    b = MemoryStorage()
    status = {}
    a.set_meta('foo', 'bar')
    b.set_meta('foo', 'bar')

    metasync(a, b, status, keys=['foo'])
    assert a.get_meta('foo') == b.get_meta('foo') == status['foo'] == 'bar'
コード例 #9
0
def test_conflict():
    a = MemoryStorage()
    b = MemoryStorage()
    status = {}
    a.set_meta('foo', 'bar')
    b.set_meta('foo', 'baz')

    with pytest.raises(MetaSyncConflict):
        metasync(a, b, status, keys=['foo'])

    assert a.get_meta('foo') == 'bar'
    assert b.get_meta('foo') == 'baz'
    assert not status
コード例 #10
0
def test_warning_on_custom_conflict_commands(conflict_state, monkeypatch):
    a, b, status = conflict_state
    warnings = []
    monkeypatch.setattr(logger, 'warning', warnings.append)

    with pytest.raises(MetaSyncConflict):
        metasync(a,
                 b,
                 status,
                 keys=['foo'],
                 conflict_resolution=lambda *a, **kw: None)

    assert warnings == ['Custom commands don\'t work on metasync.']
コード例 #11
0
def test_conflict():
    a = MemoryStorage()
    b = MemoryStorage()
    status = {}
    a.set_meta('foo', 'bar')
    b.set_meta('foo', 'baz')

    with pytest.raises(MetaSyncConflict):
        metasync(a, b, status, keys=['foo'])

    assert a.get_meta('foo') == 'bar'
    assert b.get_meta('foo') == 'baz'
    assert not status
コード例 #12
0
def test_conflict_x_wins(wins):
    a = MemoryStorage()
    b = MemoryStorage()
    status = {}
    a.set_meta('foo', 'bar')
    b.set_meta('foo', 'baz')

    metasync(a, b, status, keys=['foo'],
             conflict_resolution='a wins' if wins == 'a' else 'b wins')

    assert a.get_meta('foo') == b.get_meta('foo') == status['foo'] == (
        'bar' if wins == 'a' else 'baz'
    )
コード例 #13
0
def test_conflict_x_wins(wins):
    a = MemoryStorage()
    b = MemoryStorage()
    status = {}
    a.set_meta('foo', 'bar')
    b.set_meta('foo', 'baz')

    metasync(a,
             b,
             status,
             keys=['foo'],
             conflict_resolution='a wins' if wins == 'a' else 'b wins')

    assert a.get_meta('foo') == b.get_meta('foo') == status['foo'] == (
        'bar' if wins == 'a' else 'baz')
コード例 #14
0
def test_conflict_x_wins(wins):
    a = MemoryStorage()
    b = MemoryStorage()
    status = {}
    a.set_meta("foo", "bar")
    b.set_meta("foo", "baz")

    metasync(
        a,
        b,
        status,
        keys=["foo"],
        conflict_resolution="a wins" if wins == "a" else "b wins",
    )

    assert (a.get_meta("foo") == b.get_meta("foo") == status["foo"] ==
            ("bar" if wins == "a" else "baz"))
コード例 #15
0
ファイル: test_metasync.py プロジェクト: tbabej/vdirsyncer
def test_fuzzing(a, b, status, keys, conflict_resolution):
    def _get_storage(m, instance_name):
        s = MemoryStorage(instance_name=instance_name)
        s.metadata = m
        return s

    a = _get_storage(a, 'A')
    b = _get_storage(b, 'B')

    winning_storage = (a if conflict_resolution == 'a wins' else b)
    expected_values = dict(
        (key, winning_storage.get_meta(key)) for key in keys)

    metasync(a, b, status, keys=keys, conflict_resolution=conflict_resolution)

    for key in keys:
        s = status.get(key, '')
        assert a.get_meta(key) == b.get_meta(key) == s
        assert s == expected_values[key] or not expected_values[key] or not s
コード例 #16
0
def test_fuzzing(a, b, status, keys, conflict_resolution):
    def _get_storage(m, instance_name):
        s = MemoryStorage(instance_name=instance_name)
        s.metadata = m
        return s

    a = _get_storage(a, 'A')
    b = _get_storage(b, 'B')

    winning_storage = (a if conflict_resolution == 'a wins' else b)
    expected_values = dict((key, winning_storage.get_meta(key))
                           for key in keys)

    metasync(a, b, status,
             keys=keys, conflict_resolution=conflict_resolution)

    for key in keys:
        s = status.get(key, '')
        assert a.get_meta(key) == b.get_meta(key) == s
        assert s == expected_values[key] or not expected_values[key] or not s
コード例 #17
0
def test_fuzzing(a, b, status, keys, conflict_resolution):
    def _get_storage(m, instance_name):
        s = MemoryStorage(instance_name=instance_name)
        s.metadata = m
        return s

    a = _get_storage(a, "A")
    b = _get_storage(b, "B")

    winning_storage = a if conflict_resolution == "a wins" else b
    expected_values = {
        key: winning_storage.get_meta(key)
        for key in keys if key not in status
    }

    metasync(a, b, status, keys=keys, conflict_resolution=conflict_resolution)

    for key in keys:
        s = status.get(key, "")
        assert a.get_meta(key) == b.get_meta(key) == s
        if expected_values.get(key, "") and s:
            assert s == expected_values[key]
コード例 #18
0
ファイル: test_metasync.py プロジェクト: geier/vdirsyncer
def test_basic():
    a = MemoryStorage()
    b = MemoryStorage()
    status = {}

    a.set_meta('foo', 'bar')
    metasync(a, b, status, keys=['foo'])
    assert a.get_meta('foo') == b.get_meta('foo') == 'bar'

    a.set_meta('foo', 'baz')
    metasync(a, b, status, keys=['foo'])
    assert a.get_meta('foo') == b.get_meta('foo') == 'baz'

    b.set_meta('foo', None)
    metasync(a, b, status, keys=['foo'])
    assert a.get_meta('foo') is b.get_meta('foo') is None
コード例 #19
0
def test_basic(monkeypatch):
    a = MemoryStorage()
    b = MemoryStorage()
    status = {}

    a.set_meta("foo", "bar")
    metasync(a, b, status, keys=["foo"])
    assert a.get_meta("foo") == b.get_meta("foo") == "bar"

    a.set_meta("foo", "baz")
    metasync(a, b, status, keys=["foo"])
    assert a.get_meta("foo") == b.get_meta("foo") == "baz"

    monkeypatch.setattr(a, "set_meta", blow_up)
    monkeypatch.setattr(b, "set_meta", blow_up)
    metasync(a, b, status, keys=["foo"])
    assert a.get_meta("foo") == b.get_meta("foo") == "baz"
    monkeypatch.undo()
    monkeypatch.undo()

    b.set_meta("foo", None)
    metasync(a, b, status, keys=["foo"])
    assert not a.get_meta("foo") and not b.get_meta("foo")
コード例 #20
0
def test_basic():
    a = MemoryStorage()
    b = MemoryStorage()
    status = {}

    a.set_meta('foo', 'bar')
    metasync(a, b, status, keys=['foo'])
    assert a.get_meta('foo') == b.get_meta('foo') == 'bar'

    a.set_meta('foo', 'baz')
    metasync(a, b, status, keys=['foo'])
    assert a.get_meta('foo') == b.get_meta('foo') == 'baz'

    b.set_meta('foo', None)
    metasync(a, b, status, keys=['foo'])
    assert a.get_meta('foo') is b.get_meta('foo') is None
コード例 #21
0
def test_basic(monkeypatch):
    a = MemoryStorage()
    b = MemoryStorage()
    status = {}

    a.set_meta('foo', 'bar')
    metasync(a, b, status, keys=['foo'])
    assert a.get_meta('foo') == b.get_meta('foo') == 'bar'

    a.set_meta('foo', 'baz')
    metasync(a, b, status, keys=['foo'])
    assert a.get_meta('foo') == b.get_meta('foo') == 'baz'

    monkeypatch.setattr(a, 'set_meta', blow_up)
    monkeypatch.setattr(b, 'set_meta', blow_up)
    metasync(a, b, status, keys=['foo'])
    assert a.get_meta('foo') == b.get_meta('foo') == 'baz'
    monkeypatch.undo()
    monkeypatch.undo()

    b.set_meta('foo', None)
    metasync(a, b, status, keys=['foo'])
    assert not a.get_meta('foo') and not b.get_meta('foo')
コード例 #22
0
def test_conflict(conflict_state):
    a, b, status = conflict_state

    with pytest.raises(MetaSyncConflict):
        metasync(a, b, status, keys=['foo'])