本文整理汇总了Python中vdirsyncer.sync.sync函数的典型用法代码示例。如果您正苦于以下问题:Python sync函数的具体用法?Python sync怎么用?Python sync使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了sync函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: sync
def sync(self, status, a, b, force_delete, conflict_resolution):
old_items_a = self._get_items(a)
old_items_b = self._get_items(b)
try:
# If one storage is read-only, double-sync because changes don't
# get reverted immediately.
for _ in range(2 if a.read_only or b.read_only else 1):
sync(a, b, status,
force_delete=force_delete,
conflict_resolution=conflict_resolution)
except BothReadOnly:
assert a.read_only and b.read_only
assume(False)
except StorageEmpty:
if force_delete:
raise
else:
assert not list(a.list()) or not list(b.list())
return status
items_a = self._get_items(a)
items_b = self._get_items(b)
assert items_a == items_b
assert items_a == old_items_a or not a.read_only
assert items_b == old_items_b or not b.read_only
return status
示例2: test_irrelevant_status
def test_irrelevant_status():
a = MemoryStorage()
b = MemoryStorage()
status = {'1': ('1.txt', 1234, '1.ics', 2345)}
sync(a, b, status)
assert not status
assert empty_storage(a)
assert empty_storage(b)
示例3: test_both_readonly
def test_both_readonly():
a = MemoryStorage(read_only=True)
b = MemoryStorage(read_only=True)
assert a.read_only
assert b.read_only
status = {}
with pytest.raises(BothReadOnly):
sync(a, b, status)
示例4: test_conflict_resolution_invalid_mode
def test_conflict_resolution_invalid_mode():
a = MemoryStorage()
b = MemoryStorage()
item_a = Item(u'UID:1\nitem a')
item_b = Item(u'UID:1\nitem b')
a.upload(item_a)
b.upload(item_b)
with pytest.raises(ValueError):
sync(a, b, {}, conflict_resolution='yolo')
示例5: test_conflict_resolution_new_etags_without_changes
def test_conflict_resolution_new_etags_without_changes():
a = MemoryStorage()
b = MemoryStorage()
item = Item(u'UID:1')
href_a, etag_a = a.upload(item)
href_b, etag_b = b.upload(item)
status = {'1': (href_a, 'BOGUS_a', href_b, 'BOGUS_b')}
sync(a, b, status)
assert status == {'1': (href_a, etag_a, href_b, etag_b)}
示例6: test_readonly
def test_readonly():
a = MemoryStorage()
b = MemoryStorage(read_only=True)
status = {}
href_a, _ = a.upload(Item(u'UID:1'))
href_b, _ = b.upload(Item(u'UID:2'))
sync(a, b, status)
assert len(status) == 2 and a.has(href_a) and not b.has(href_a)
sync(a, b, status)
assert len(status) == 1 and not a.has(href_a) and not b.has(href_a)
示例7: test_missing_status
def test_missing_status():
a = MemoryStorage()
b = MemoryStorage()
status = {}
item = Item(u'asdf')
href_a, _ = a.upload(item)
href_b, _ = b.upload(item)
sync(a, b, status)
assert len(status) == 1
assert a.has(href_a)
assert b.has(href_b)
示例8: test_no_uids
def test_no_uids():
a = MemoryStorage()
b = MemoryStorage()
href_a, _ = a.upload(Item(u'ASDF'))
href_b, _ = b.upload(Item(u'FOOBAR'))
status = {}
sync(a, b, status)
a_items = set(a.get(href)[0].raw for href, etag in a.list())
b_items = set(b.get(href)[0].raw for href, etag in b.list())
assert a_items == b_items == {u'ASDF', u'FOOBAR'}
示例9: test_updated_and_deleted
def test_updated_and_deleted():
a = MemoryStorage()
b = MemoryStorage()
href_a, etag_a = a.upload(Item(u"UID:1"))
status = {}
sync(a, b, status, force_delete=True)
(href_b, etag_b), = b.list()
b.delete(href_b, etag_b)
a.update(href_a, Item(u"UID:1\nupdated"), etag_a)
sync(a, b, status, force_delete=True)
assert len(list(a.list())) == len(list(b.list())) == 1
示例10: test_already_synced
def test_already_synced():
a = MemoryStorage(fileext=".a")
b = MemoryStorage(fileext=".b")
item = Item(u"UID:1")
a.upload(item)
b.upload(item)
status = {"1": ({"href": "1.a", "etag": a.get("1.a")[1]}, {"href": "1.b", "etag": b.get("1.b")[1]})}
old_status = dict(status)
a.update = b.update = a.upload = b.upload = lambda *a, **kw: pytest.fail("Method shouldn't have been called.")
for i in (1, 2):
sync(a, b, status)
assert status == old_status
assert a.has("1.a") and b.has("1.b")
示例11: test_missing_status_and_different_items
def test_missing_status_and_different_items():
a = MemoryStorage()
b = MemoryStorage()
status = {}
item1 = Item(u'UID:1\nhaha')
item2 = Item(u'UID:1\nhoho')
a.upload(item1)
b.upload(item2)
with pytest.raises(SyncConflict):
sync(a, b, status)
assert not status
sync(a, b, status, conflict_resolution='a wins')
assert_item_equals(item1, b.get('1.txt')[0])
assert_item_equals(item1, a.get('1.txt')[0])
示例12: test_readonly
def test_readonly():
a = MemoryStorage(instance_name="a")
b = MemoryStorage(instance_name="b")
status = {}
href_a, _ = a.upload(Item(u"UID:1"))
href_b, _ = b.upload(Item(u"UID:2"))
b.read_only = True
with pytest.raises(exceptions.ReadOnlyError):
b.upload(Item(u"UID:3"))
sync(a, b, status)
assert len(status) == 2 and a.has(href_a) and not b.has(href_a)
sync(a, b, status)
assert len(status) == 1 and not a.has(href_a) and not b.has(href_a)
示例13: test_read_only_and_prefetch
def test_read_only_and_prefetch():
a = MemoryStorage()
b = MemoryStorage()
b.read_only = True
status = {}
item1 = Item(u"UID:1\nhaha")
item2 = Item(u"UID:2\nhoho")
a.upload(item1)
a.upload(item2)
sync(a, b, status, force_delete=True)
sync(a, b, status, force_delete=True)
assert list(a.list()) == list(b.list()) == []
示例14: test_conflict_resolution_new_etags_without_changes
def test_conflict_resolution_new_etags_without_changes():
a = MemoryStorage()
b = MemoryStorage()
item = Item(u"UID:1")
href_a, etag_a = a.upload(item)
href_b, etag_b = b.upload(item)
status = {"1": (href_a, "BOGUS_a", href_b, "BOGUS_b")}
sync(a, b, status)
(ident, (status_a, status_b)), = status.items()
assert ident == "1"
assert status_a["href"] == href_a
assert status_a["etag"] == etag_a
assert status_b["href"] == href_b
assert status_b["etag"] == etag_b
示例15: test_already_synced
def test_already_synced():
a = MemoryStorage()
b = MemoryStorage()
item = Item(u'UID:1')
a.upload(item)
b.upload(item)
status = {
'1': ('1.txt', a.get('1.txt')[1], '1.txt', b.get('1.txt')[1])
}
old_status = dict(status)
a.update = b.update = a.upload = b.upload = \
lambda *a, **kw: pytest.fail('Method shouldn\'t have been called.')
for i in (1, 2):
sync(a, b, status)
assert status == old_status
assert a.has('1.txt') and b.has('1.txt')