vContent

tests/test_calendar_stream.py

11:428f343f0626
2009-03-14 Paul Boddie Changed the StreamWriter infrastructure in order to provide a more coherent mechanism for encoding data for output, employing the write method as the public method for sending data for output, and fixing the ALTREP output for the test iCalendar file. Introduced encoding parameters in the convenience functions. Added and improved docstrings. Made the streaming tests check the equivalence of the generated files and the original files.
     1 #!/usr/bin/env python     2      3 import codecs, vCalendar, os     4      5 this_dir = os.path.split(__file__)[0]     6 f = codecs.open(os.path.join(this_dir, "test.ics"), encoding="utf-8")     7 out = codecs.open("tmp.ics", "w", encoding="utf-8")     8 try:     9     doc = vCalendar.iterparse(f)    10     w = vCalendar.iterwrite(out)    11     for name, parameters, value in doc:    12         print "%r, %r, %r" % (name, parameters, value)    13         w.write(name, parameters, value)    14 finally:    15     out.close()    16     f.close()    17     18 print "--------"    19     20 f = codecs.open(os.path.join(this_dir, "test.ics"), encoding="utf-8")    21 f2 = codecs.open("tmp.ics", encoding="utf-8")    22 try:    23     doc = vCalendar.iterparse(f)    24     doc2 = vCalendar.iterparse(f2)    25     for (name, parameters, value), (name2, parameters2, value2) in zip(doc, doc2):    26         print "%r, %r, %r" % (name, parameters, value)    27         print "%r, %r, %r" % (name2, parameters2, value2)    28         assert name == name2    29         assert parameters == parameters2    30         assert value == value2    31 finally:    32     f2.close()    33     f.close()    34     35 # vim: tabstop=4 expandtab shiftwidth=4