mirror of
https://github.com/samsonjs/vdirsyncer.git
synced 2026-04-27 14:57:41 +00:00
Add testcase for #70
This commit is contained in:
parent
c54836b1cf
commit
f59c8d1fdf
3 changed files with 13 additions and 14 deletions
|
|
@ -18,7 +18,8 @@ vdirsyncer.log.set_level(vdirsyncer.log.logging.DEBUG)
|
||||||
def normalize_item(item):
|
def normalize_item(item):
|
||||||
if not isinstance(item, text_type):
|
if not isinstance(item, text_type):
|
||||||
item = item.raw
|
item = item.raw
|
||||||
return tuple(sorted(_normalize_item(item).splitlines()))
|
return tuple(sorted(_normalize_item(
|
||||||
|
item, use_icalendar=False).splitlines()))
|
||||||
|
|
||||||
|
|
||||||
def assert_item_equals(a, b):
|
def assert_item_equals(a, b):
|
||||||
|
|
|
||||||
|
|
@ -10,22 +10,21 @@
|
||||||
from vdirsyncer.utils.vobject import split_collection, join_collection, \
|
from vdirsyncer.utils.vobject import split_collection, join_collection, \
|
||||||
hash_item
|
hash_item
|
||||||
|
|
||||||
from .. import normalize_item, SIMPLE_TEMPLATE, BARE_EVENT_TEMPLATE, \
|
from .. import normalize_item, VCARD_TEMPLATE, BARE_EVENT_TEMPLATE, \
|
||||||
EVENT_TEMPLATE
|
EVENT_TEMPLATE
|
||||||
|
|
||||||
|
|
||||||
_simple_joined = u'\r\n'.join((
|
_simple_joined = u'\r\n'.join((
|
||||||
u'BEGIN:VADDRESSBOOK',
|
u'BEGIN:VADDRESSBOOK',
|
||||||
SIMPLE_TEMPLATE.format(r=123),
|
VCARD_TEMPLATE.format(r=123),
|
||||||
SIMPLE_TEMPLATE.format(r=345),
|
VCARD_TEMPLATE.format(r=345),
|
||||||
SIMPLE_TEMPLATE.format(r=678),
|
VCARD_TEMPLATE.format(r=678),
|
||||||
u'END:VADDRESSBOOK'
|
u'END:VADDRESSBOOK'
|
||||||
))
|
))
|
||||||
|
|
||||||
_simple_split = [
|
_simple_split = [
|
||||||
SIMPLE_TEMPLATE.format(r=123),
|
VCARD_TEMPLATE.format(r=123),
|
||||||
SIMPLE_TEMPLATE.format(r=345),
|
VCARD_TEMPLATE.format(r=345),
|
||||||
SIMPLE_TEMPLATE.format(r=678)
|
VCARD_TEMPLATE.format(r=678)
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -36,10 +35,7 @@ def test_split_collection_simple():
|
||||||
|
|
||||||
|
|
||||||
def test_join_collection_simple():
|
def test_join_collection_simple():
|
||||||
item_type = _simple_split[0].splitlines()[0][len(u'BEGIN:'):]
|
given = join_collection(_simple_split)
|
||||||
given = join_collection(_simple_split, wrappers={
|
|
||||||
item_type: (u'VADDRESSBOOK', ())
|
|
||||||
})
|
|
||||||
print(given)
|
print(given)
|
||||||
print(_simple_joined)
|
print(_simple_joined)
|
||||||
assert normalize_item(given) == normalize_item(_simple_joined)
|
assert normalize_item(given) == normalize_item(_simple_joined)
|
||||||
|
|
|
||||||
|
|
@ -27,8 +27,10 @@ IGNORE_PROPS = frozenset((
|
||||||
))
|
))
|
||||||
|
|
||||||
|
|
||||||
def normalize_item(text, ignore_props=IGNORE_PROPS):
|
def normalize_item(text, ignore_props=IGNORE_PROPS, use_icalendar=True):
|
||||||
try:
|
try:
|
||||||
|
if not use_icalendar:
|
||||||
|
raise Exception()
|
||||||
lines = to_unicode_lines(icalendar.cal.Component.from_ical(text))
|
lines = to_unicode_lines(icalendar.cal.Component.from_ical(text))
|
||||||
except Exception:
|
except Exception:
|
||||||
lines = sorted(text.splitlines())
|
lines = sorted(text.splitlines())
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue