예제 #1
0
 def doTest(self, pairs, **kwds):
     lb = LineBreak(**kwds)
     for infn, outfn in pairs:
         instring = self.readText(infn + ".in")
         b = lb.wrap(instring)
         broken = "".join([unicode(x) for x in b])
         outstring = self.readText(outfn + ".out")
         self.assertEqual(broken, outstring)
예제 #2
0
 def doTestArray(self, pairs, **kwds):
     for infn, outfn in pairs:
         instring = self.readText(infn + ".in")
         lb = LineBreak(**kwds)
         broken = [unicode(x) for x in lb.wrap(instring)]
         fp = open(os.path.join("test-data", outfn + ".out"), "rb")
         outstrings = [unicode(x, "utf-8") for x in fp.readlines()]
         fp.close()
         self.assertEqual(broken, outstrings)
예제 #3
0
    def test_00LineBreakTest(self):
        commentRe = re.compile(r"\s*#\s*")
        opRe = re.compile(r"\s*(?:" + unichr(0xF7) + "|" + unichr(0xD7) + r")\s*")

        try:
            fp = open(os.path.join("test-data", "LineBreakTest.txt"), "rb")
        except IOError:
            return

        eaw = {}
        for c in range(1, 0xFFFD):
            eaw[unichr(c)] = eawN
        lb = LineBreak(break_indent=False, width=1, eaw=eaw, format=None, legacy_cm=False)

        print("")
        print(fp.readline().strip())
        print(fp.readline().strip())

        errs = 0
        tests = 0
        for l in fp.readlines():
            l = unicode(l, "utf-8").rstrip()
            a = commentRe.split(l, 1)
            if len(a) > 1:
                desc = a[1]
            else:
                desc = ""
            l = a[0].strip()
            if not len(l):
                continue

            if l.startswith(unichr(0xD7)):  # ÷
                l = l[1:].lstrip()
            if l.endswith(unichr(0xF7)):  # ×
                l = l[:-1].rstrip()

            s = "".join([unichr(int(c, 16)) for c in opRe.split(l) if len(c) > 0])
            b = unistr(0x20, 0xF7, 0x20).join(
                [unistr(0x20, 0xD7, 0x20).join(["%04X" % ord(c) for c in unicode(x)]) for x in lb.wrap(s)]
            )
            try:
                self.assertEqual(b, l)
            except AssertionError:
                import sys
                import traceback

                print("Failed: %s" % desc)
                traceback.print_exc(0)
                errs = errs + 1
            tests = tests + 1
        fp.close()

        if errs > 0:
            raise AssertionError("%d of %d subtests are failed." % (errs, tests))