1 #!/usr/bin/env python 2 3 """ 4 Perform a round trip with an input calendar, comparing the result to the 5 original. 6 """ 7 8 import codecs, vCalendar, os 9 10 this_dir = os.path.split(__file__)[0] 11 f = codecs.open(os.path.join(this_dir, "test.ics"), encoding="utf-8") 12 out = codecs.open("tmp.ics", "w", encoding="utf-8") 13 try: 14 doc = vCalendar.iterparse(f) 15 w = vCalendar.iterwrite(out) 16 for name, parameters, value in doc: 17 print "%r, %r, %r" % (name, parameters, value) 18 w.write(name, parameters, value) 19 finally: 20 out.close() 21 f.close() 22 23 print "--------" 24 25 f = codecs.open(os.path.join(this_dir, "test.ics"), encoding="utf-8") 26 f2 = codecs.open("tmp.ics", encoding="utf-8") 27 try: 28 doc = vCalendar.iterparse(f) 29 doc2 = vCalendar.iterparse(f2) 30 for (name, parameters, value), (name2, parameters2, value2) in zip(doc, doc2): 31 print "%r, %r, %r" % (name, parameters, value) 32 print "%r, %r, %r" % (name2, parameters2, value2) 33 assert name == name2 34 assert parameters == parameters2 35 assert value == value2 36 finally: 37 f2.close() 38 f.close() 39 40 # vim: tabstop=4 expandtab shiftwidth=4