vContent

tests/test_calendar_stream.py

28:549fe3cdaf74
2013-05-05 Paul Boddie Updated the version number.
     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 import sys    10     11 this_dir = os.path.split(__file__)[0]    12     13 if len(sys.argv) > 1:    14     filename = sys.argv[1]    15 else:    16     filename = os.path.join(this_dir, "test.ics")    17     18 f = codecs.open(filename, encoding="utf-8")    19 out = codecs.open("tmp.ics", "w", encoding="utf-8")    20 try:    21     doc = vCalendar.iterparse(f)    22     w = vCalendar.iterwrite(out)    23     for name, parameters, value in doc:    24         print "%r, %r, %r" % (name, parameters, value)    25         w.write(name, parameters, value)    26 finally:    27     out.close()    28     f.close()    29     30 print "--------"    31     32 f = codecs.open(filename, encoding="utf-8")    33 f2 = codecs.open("tmp.ics", encoding="utf-8")    34 try:    35     doc = vCalendar.iterparse(f)    36     doc2 = vCalendar.iterparse(f2)    37     for (name, parameters, value), (name2, parameters2, value2) in zip(doc, doc2):    38         print "%r, %r, %r" % (name, parameters, value)    39         print "%r, %r, %r" % (name2, parameters2, value2)    40         assert name == name2    41         assert parameters == parameters2    42         assert value == value2    43 finally:    44     f2.close()    45     f.close()    46     47 # vim: tabstop=4 expandtab shiftwidth=4