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@5 | 9 | |
paul@10 | 10 | this_dir = os.path.split(__file__)[0] |
paul@10 | 11 | f = codecs.open(os.path.join(this_dir, "test.ics"), encoding="utf-8") |
paul@7 | 12 | out = codecs.open("tmp.ics", "w", encoding="utf-8") |
paul@7 | 13 | try: |
paul@7 | 14 | doc = vCalendar.iterparse(f) |
paul@8 | 15 | w = vCalendar.iterwrite(out) |
paul@7 | 16 | for name, parameters, value in doc: |
paul@7 | 17 | print "%r, %r, %r" % (name, parameters, value) |
paul@11 | 18 | w.write(name, parameters, value) |
paul@7 | 19 | finally: |
paul@7 | 20 | out.close() |
paul@7 | 21 | f.close() |
paul@5 | 22 | |
paul@11 | 23 | print "--------" |
paul@11 | 24 | |
paul@11 | 25 | f = codecs.open(os.path.join(this_dir, "test.ics"), encoding="utf-8") |
paul@11 | 26 | f2 = codecs.open("tmp.ics", encoding="utf-8") |
paul@11 | 27 | try: |
paul@11 | 28 | doc = vCalendar.iterparse(f) |
paul@11 | 29 | doc2 = vCalendar.iterparse(f2) |
paul@11 | 30 | for (name, parameters, value), (name2, parameters2, value2) in zip(doc, doc2): |
paul@11 | 31 | print "%r, %r, %r" % (name, parameters, value) |
paul@11 | 32 | print "%r, %r, %r" % (name2, parameters2, value2) |
paul@11 | 33 | assert name == name2 |
paul@11 | 34 | assert parameters == parameters2 |
paul@11 | 35 | assert value == value2 |
paul@11 | 36 | finally: |
paul@11 | 37 | f2.close() |
paul@11 | 38 | f.close() |
paul@11 | 39 | |
paul@5 | 40 | # vim: tabstop=4 expandtab shiftwidth=4 |