本文整理汇总了Python中vdirsyncer.storage.memory.MemoryStorage类的典型用法代码示例。如果您正苦于以下问题:Python MemoryStorage类的具体用法?Python MemoryStorage怎么用?Python MemoryStorage使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了MemoryStorage类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_uses_get_multi
def test_uses_get_multi(monkeypatch):
def breakdown(*a, **kw):
raise AssertionError('Expected use of get_multi')
get_multi_calls = []
old_get = MemoryStorage.get
def get_multi(self, hrefs):
hrefs = list(hrefs)
get_multi_calls.append(hrefs)
for href in hrefs:
item, etag = old_get(self, href)
yield href, item, etag
monkeypatch.setattr(MemoryStorage, 'get', breakdown)
monkeypatch.setattr(MemoryStorage, 'get_multi', get_multi)
a = MemoryStorage()
b = MemoryStorage()
item = Item(u'UID:1')
expected_href, etag = a.upload(item)
sync(a, b, {})
assert get_multi_calls == [[expected_href]]
示例2: test_moved_href
def test_moved_href():
'''
Concrete application: ppl_ stores contact aliases in filenames, which means
item's hrefs get changed. Vdirsyncer doesn't synchronize this data, but
also shouldn't do things like deleting and re-uploading to the server.
.. _ppl: http://ppladdressbook.org/
'''
a = MemoryStorage()
b = MemoryStorage()
status = {}
href, etag = a.upload(Item(u'UID:haha'))
sync(a, b, status)
b.items['lol'] = b.items.pop('haha')
# The sync algorithm should prefetch `lol`, see that it's the same ident
# and not do anything else.
a.get_multi = blow_up # Absolutely no prefetch on A
# No actual sync actions
a.delete = a.update = a.upload = b.delete = b.update = b.upload = blow_up
sync(a, b, status)
assert len(status) == 1
assert len(list(a.list())) == len(list(b.list())) == 1
assert status['haha'][1]['href'] == 'lol'
old_status = deepcopy(status)
# Further sync should be a noop. Not even prefetching should occur.
b.get_multi = blow_up
sync(a, b, status)
assert old_status == status
assert len(list(a.list())) == len(list(b.list())) == 1
示例3: 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)}
示例4: test_partial_sync_error
def test_partial_sync_error():
a = MemoryStorage()
b = MemoryStorage()
status = {}
a.upload(Item('UID:0'))
b.read_only = True
with pytest.raises(PartialSync):
sync(a, b, status, partial_sync='error')
示例5: test_empty_storage_dataloss
def test_empty_storage_dataloss():
a = MemoryStorage()
b = MemoryStorage()
a.upload(Item(u'UID:1'))
a.upload(Item(u'UID:2'))
status = {}
sync(a, b, status)
with pytest.raises(StorageEmpty):
sync(MemoryStorage(), b, status)
with pytest.raises(StorageEmpty):
sync(a, MemoryStorage(), status)
示例6: newstorage
def newstorage(self, read_only, flaky_etags):
s = MemoryStorage()
s.read_only = read_only
if flaky_etags:
def get(href):
_, item = s.items[href]
etag = _random_string()
s.items[href] = etag, item
return item, etag
s.get = get
return s
示例7: test_repair_unsafe_uids
def test_repair_unsafe_uids(uid):
assert not href_safe(uid)
s = MemoryStorage()
href, etag = s.upload(Item(u'BEGIN:VCARD\nUID:{}\nEND:VCARD'.format(uid)))
assert s.get(href)[0].uid == uid
repair_storage(s)
new_href = list(s.list())[0][0]
assert href_safe(new_href)
newuid = s.get(new_href)[0].uid
assert href_safe(newuid)
示例8: test_repair_unsafe_uids
def test_repair_unsafe_uids(uid):
s = MemoryStorage()
item = Item(u'BEGIN:VCARD\nUID:123\nEND:VCARD').with_uid(uid)
href, etag = s.upload(item)
assert s.get(href)[0].uid == uid
assert not href_safe(uid)
repair_storage(s, repair_unsafe_uid=True)
new_href = list(s.list())[0][0]
assert href_safe(new_href)
newuid = s.get(new_href)[0].uid
assert href_safe(newuid)
示例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',
'hash': item.hash,
'etag': a.get('1.a')[1]
}, {
'href': '1.b',
'hash': item.hash,
'etag': b.get('1.b')[1]
})
}
old_status = deepcopy(status)
a.update = b.update = a.upload = b.upload = \
lambda *a, **kw: pytest.fail('Method shouldn\'t have been called.')
for _ in (1, 2):
sync(a, b, status)
assert status == old_status
assert items(a) == items(b) == {item.raw}
示例11: test_repair_unsafe_uids
def test_repair_unsafe_uids(uid):
s = MemoryStorage()
item = Item(u'BEGIN:VCARD\nUID:{}\nEND:VCARD'.format(uid))
print(repr(item.raw))
href, etag = s.upload(item)
assert s.get(href)[0].uid == uid
assert not href_safe(uid)
repair_storage(s, repair_unsafe_uid=True)
new_href = list(s.list())[0][0]
assert href_safe(new_href)
newuid = s.get(new_href)[0].uid
assert href_safe(newuid)
示例12: test_ident_conflict
def test_ident_conflict(sync_inbetween):
a = MemoryStorage()
b = MemoryStorage()
status = {}
href_a, etag_a = a.upload(Item(u'UID:aaa'))
href_b, etag_b = a.upload(Item(u'UID:bbb'))
if sync_inbetween:
sync(a, b, status)
a.update(href_a, Item(u'UID:xxx'), etag_a)
a.update(href_b, Item(u'UID:xxx'), etag_b)
with pytest.raises(IdentConflict):
sync(a, b, status)
示例13: test_insert_hash
def test_insert_hash():
a = MemoryStorage()
b = MemoryStorage()
status = {}
item = Item('UID:1')
href, etag = a.upload(item)
sync(a, b, status)
for d in status['1']:
del d['hash']
a.update(href, Item('UID:1\nHAHA:YES'), etag)
sync(a, b, status)
assert 'hash' in status['1'][0] and 'hash' in status['1'][1]
示例14: 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 not items(a) and not items(b)
示例15: 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