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