vContent

Annotated tests/test_calendar_stream.py

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