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 = ("BEGIN:VTIMEZONE\r\n" "TZID:/mozilla.org/20070129_1/Asia/Tokyo\r\n" "X-LIC-LOCATION:Asia/Tokyo\r\n" "BEGIN:STANDARD\r\n" "TZOFFSETFROM:+0900\r\n" "TZOFFSETTO:+0900\r\n" "TZNAME:JST\r\n" "DTSTART:19700101T000000\r\n" "END:STANDARD\r\n" "END:VTIMEZONE") full = "\r\n".join(["BEGIN:VCALENDAR"] + items + [timezone, "END:VCALENDAR"]) given = {normalize_item(item) for item in vobject.split_collection(full)} expected = { normalize_item("\r\n".join( ("BEGIN:VCALENDAR", item, timezone, "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(vobject.Item(item).hash for item in vobject.split_collection(full)) expected = set( vobject.Item(u'\r\n'.join(( u'BEGIN:VCALENDAR', item, timezone, u'END:VCALENDAR' ))).hash for item in items ) assert given == expected
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_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_collection_simple(benchmark): given = benchmark(lambda: list(vobject.split_collection(_simple_joined))) assert [vobject.Item(item).hash for item in given] == \ [vobject.Item(item).hash 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 _ 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_multiple_wrappers(benchmark): joined = "\r\n".join("BEGIN:VADDRESSBOOK\r\n" + x + "\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(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 [vobject.Item(item).hash for item in given] == \ [vobject.Item(item).hash 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, check_roundtrip): check_roundtrip(_simple_split) given = benchmark(lambda: list(vobject.split_collection(_simple_joined))) assert [vobject.Item(item).hash for item in given] == \ [vobject.Item(item).hash 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(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(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))) check_roundtrip(given) assert [vobject.Item(item).hash for item in given] == \ [vobject.Item(item).hash for item in _simple_split] assert [x.splitlines() for x in given] == \ [x.splitlines() for x in _simple_split]
def inner(split): joined = benchmark(lambda: vobject.join_collection(split)) split2 = benchmark(lambda: list(vobject.split_collection(joined))) assert [vobject.Item(item).hash for item in split] == \ [vobject.Item(item).hash for item in split2]
def inner(split): joined = benchmark(lambda: vobject.join_collection(split)) split2 = benchmark(lambda: list(vobject.split_collection(joined))) assert [vobject.Item(item).hash for item in split] == \ [vobject.Item(item).hash for item in split2]