def test_split_collection_timezones(): items = [ BARE_EVENT_TEMPLATE.format(r=123, uid=123), BARE_EVENT_TEMPLATE.format(r=345, uid=345) ] timezone = (u'BEGIN:VTIMEZONE\r\n' u'TZID:/mozilla.org/20070129_1/Asia/Tokyo\r\n' u'X-LIC-LOCATION:Asia/Tokyo\r\n' u'BEGIN:STANDARD\r\n' u'TZOFFSETFROM:+0900\r\n' u'TZOFFSETTO:+0900\r\n' u'TZNAME:JST\r\n' u'DTSTART:19700101T000000\r\n' u'END:STANDARD\r\n' u'END:VTIMEZONE') full = u'\r\n'.join([u'BEGIN:VCALENDAR'] + items + [timezone, u'END:VCALENDAR']) given = set( normalize_item(item) for item in vobject.split_collection(full)) expected = set( normalize_item(u'\r\n'.join((u'BEGIN:VCALENDAR', item, timezone, u'END:VCALENDAR'))) for item in items) assert given == expected
def test_split_collection_timezones(): items = [ BARE_EVENT_TEMPLATE.format(r=123, uid=123), BARE_EVENT_TEMPLATE.format(r=345, uid=345) ] timezone = ( u'BEGIN:VTIMEZONE\r\n' u'TZID:/mozilla.org/20070129_1/Asia/Tokyo\r\n' u'X-LIC-LOCATION:Asia/Tokyo\r\n' u'BEGIN:STANDARD\r\n' u'TZOFFSETFROM:+0900\r\n' u'TZOFFSETTO:+0900\r\n' u'TZNAME:JST\r\n' u'DTSTART:19700101T000000\r\n' u'END:STANDARD\r\n' u'END:VTIMEZONE' ) full = u'\r\n'.join( [u'BEGIN:VCALENDAR'] + items + [timezone, u'END:VCALENDAR'] ) given = set(normalize_item(item) for item in vobject.split_collection(full)) expected = set( normalize_item(u'\r\n'.join(( u'BEGIN:VCALENDAR', item, timezone, u'END:VCALENDAR' ))) for item in items ) assert given == expected
def test_split_collection_multiple_wrappers(benchmark): joined = u"\r\n".join(u"BEGIN:VADDRESSBOOK\r\n" + x + u"\r\nEND:VADDRESSBOOK\r\n" for x in _simple_split) given = benchmark(lambda: list(vobject.split_collection(joined))) assert [normalize_item(item) for item in given] == [normalize_item(item) for item in _simple_split] assert [x.splitlines() for x in given] == [x.splitlines() for x in _simple_split]
def test_split_collection_simple(benchmark): given = benchmark(lambda: list(vobject.split_collection(_simple_joined))) assert [normalize_item(item) for item in given] == \ [normalize_item(item) for item in _simple_split] assert [x.splitlines() for x in given] == \ [x.splitlines() for x in _simple_split]
def test_split_contacts(): bare = "\r\n".join([VCARD_TEMPLATE.format(r=x, uid=x) for x in range(4)]) with_wrapper = "BEGIN:VADDRESSBOOK\r\n" + bare + "\nEND:VADDRESSBOOK\r\n" for _ in (bare, with_wrapper): split = list(vobject.split_collection(bare)) assert len(split) == 4 assert vobject.join_collection(split).splitlines() == with_wrapper.splitlines()
def test_split_contacts(): bare = '\r\n'.join([VCARD_TEMPLATE.format(r=x, uid=x) for x in range(4)]) with_wrapper = 'BEGIN:VADDRESSBOOK\r\n' + bare + '\nEND:VADDRESSBOOK\r\n' for x in (bare, with_wrapper): split = list(vobject.split_collection(bare)) assert len(split) == 4 assert vobject.join_collection(split).splitlines() == \ with_wrapper.splitlines()
def test_split_collection_simple(): given = list(vobject.split_collection(_simple_joined)) assert [normalize_item(item) for item in given] == \ [normalize_item(item) for item in _simple_split] if vobject.ICALENDAR_ORIGINAL_ORDER_SUPPORT: assert [x.splitlines() for x in given] == \ [x.splitlines() for x in _simple_split]
def test_split_collection_multiple_wrappers(benchmark): joined = u'\r\n'.join(u'BEGIN:VADDRESSBOOK\r\n' + x + u'\r\nEND:VADDRESSBOOK\r\n' for x in _simple_split) given = benchmark(lambda: list(vobject.split_collection(joined))) assert [normalize_item(item) for item in given] == \ [normalize_item(item) for item in _simple_split] assert [x.splitlines() for x in given] == \ [x.splitlines() for x in _simple_split]
def test_split_collection_multiple_wrappers(): joined = u'\r\n'.join(u'BEGIN:VADDRESSBOOK\r\n' + x + u'\r\nEND:VADDRESSBOOK\r\n' for x in _simple_split) given = list(vobject.split_collection(joined)) assert [normalize_item(item) for item in given] == \ [normalize_item(item) for item in _simple_split] if vobject.ICALENDAR_ORIGINAL_ORDER_SUPPORT: assert [x.splitlines() for x in given] == \ [x.splitlines() for x in _simple_split]
def test_split_collection_different_wrappers(): with pytest.raises(ValueError) as exc_info: list(vobject.split_collection(u'BEGIN:VADDRESSBOOK\r\n' u'BEGIN:FOO\r\n' u'END:FOO\r\n' u'END:VADDRESSBOOK\r\n' u'BEGIN:VCALENDAR\r\n' u'BEGIN:FOO\r\n' u'END:FOO\r\n' u'END:VCALENDAR\r\n')) assert 'different types of components at top-level' in \ str(exc_info.value).lower()
def test_split_collection_multiple_wrappers(): joined = u'\r\n'.join( u'BEGIN:VADDRESSBOOK\r\n' + x + u'\r\nEND:VADDRESSBOOK\r\n' for x in _simple_split ) given = list(vobject.split_collection(joined)) assert [normalize_item(item) for item in given] == \ [normalize_item(item) for item in _simple_split] if vobject.ICALENDAR_ORIGINAL_ORDER_SUPPORT: assert [x.splitlines() for x in given] == \ [x.splitlines() for x in _simple_split]
def test_vcard_property_groups(): vcard = dedent(u''' BEGIN:VCARD VERSION:3.0 MYLABEL123.ADR:;;This is the Address 08; Some City;;12345;Germany MYLABEL123.X-ABLABEL: FN:Some Name N:Name;Some;;;Nickname UID:67c15e43-34d2-4f55-a6c6-4adb7aa7e3b2 END:VCARD ''').strip() book = u'BEGIN:VADDRESSBOOK\n' + vcard + u'\nEND:VADDRESSBOOK' splitted = list(vobject.split_collection(book)) assert len(splitted) == 1 assert vobject.Item(vcard).hash == vobject.Item(splitted[0]).hash assert 'is the Address' in vobject.Item(vcard).parsed['MYLABEL123.ADR']
def test_vcard_property_groups(): vcard = textwrap.dedent(u''' BEGIN:VCARD VERSION:3.0 MYLABEL123.ADR:;;This is the Address 08; Some City;;12345;Germany MYLABEL123.X-ABLABEL: FN:Some Name N:Name;Some;;;Nickname UID:67c15e43-34d2-4f55-a6c6-4adb7aa7e3b2 END:VCARD ''').strip() book = u'BEGIN:VADDRESSBOOK\n' + vcard + u'\nEND:VADDRESSBOOK' splitted = list(vobject.split_collection(book)) assert len(splitted) == 1 assert vobject.Item(vcard).hash == vobject.Item(splitted[0]).hash assert 'is the Address' in vobject.Item(vcard).parsed['MYLABEL123.ADR']