mirror of
https://github.com/python/cpython.git
synced 2025-08-01 07:33:08 +00:00
Convert test_normalization to use unittest.
This commit is contained in:
parent
fe712fb9ca
commit
9405609c17
1 changed files with 61 additions and 55 deletions
|
@ -1,5 +1,6 @@
|
||||||
from test.test_support import (verbose, TestFailed, TestSkipped, verify,
|
from test.test_support import run_unittest, open_urlresource
|
||||||
open_urlresource)
|
import unittest
|
||||||
|
|
||||||
import sys
|
import sys
|
||||||
import os
|
import os
|
||||||
from unicodedata import normalize
|
from unicodedata import normalize
|
||||||
|
@ -29,7 +30,8 @@ def unistr(data):
|
||||||
raise RangeError
|
raise RangeError
|
||||||
return u"".join([unichr(x) for x in data])
|
return u"".join([unichr(x) for x in data])
|
||||||
|
|
||||||
def test_main():
|
class NormalizationTest(unittest.TestCase):
|
||||||
|
def test_main(self):
|
||||||
part1_data = {}
|
part1_data = {}
|
||||||
for line in open_urlresource(TESTDATAURL):
|
for line in open_urlresource(TESTDATAURL):
|
||||||
if '#' in line:
|
if '#' in line:
|
||||||
|
@ -50,24 +52,23 @@ def test_main():
|
||||||
# try atleast adding c1 if we are in part1
|
# try atleast adding c1 if we are in part1
|
||||||
if part == "@Part1":
|
if part == "@Part1":
|
||||||
try:
|
try:
|
||||||
c1=unistr(line.split(';')[0])
|
c1 = unistr(line.split(';')[0])
|
||||||
except RangeError:
|
except RangeError:
|
||||||
pass
|
pass
|
||||||
else:
|
else:
|
||||||
part1_data[c1] = 1
|
part1_data[c1] = 1
|
||||||
continue
|
continue
|
||||||
|
|
||||||
if verbose:
|
|
||||||
print line
|
|
||||||
|
|
||||||
# Perform tests
|
# Perform tests
|
||||||
verify(c2 == NFC(c1) == NFC(c2) == NFC(c3), line)
|
self.failUnless(c2 == NFC(c1) == NFC(c2) == NFC(c3), line)
|
||||||
verify(c4 == NFC(c4) == NFC(c5), line)
|
self.failUnless(c4 == NFC(c4) == NFC(c5), line)
|
||||||
verify(c3 == NFD(c1) == NFD(c2) == NFD(c3), line)
|
self.failUnless(c3 == NFD(c1) == NFD(c2) == NFD(c3), line)
|
||||||
verify(c5 == NFD(c4) == NFD(c5), line)
|
self.failUnless(c5 == NFD(c4) == NFD(c5), line)
|
||||||
verify(c4 == NFKC(c1) == NFKC(c2) == NFKC(c3) == NFKC(c4) == NFKC(c5),
|
self.failUnless(c4 == NFKC(c1) == NFKC(c2) == \
|
||||||
|
NFKC(c3) == NFKC(c4) == NFKC(c5),
|
||||||
line)
|
line)
|
||||||
verify(c5 == NFKD(c1) == NFKD(c2) == NFKD(c3) == NFKD(c4) == NFKD(c5),
|
self.failUnless(c5 == NFKD(c1) == NFKD(c2) == \
|
||||||
|
NFKD(c3) == NFKD(c4) == NFKD(c5),
|
||||||
line)
|
line)
|
||||||
|
|
||||||
# Record part 1 data
|
# Record part 1 data
|
||||||
|
@ -79,10 +80,15 @@ def test_main():
|
||||||
X = unichr(c)
|
X = unichr(c)
|
||||||
if X in part1_data:
|
if X in part1_data:
|
||||||
continue
|
continue
|
||||||
assert X == NFC(X) == NFD(X) == NFKC(X) == NFKD(X), c
|
self.failUnless(X == NFC(X) == NFD(X) == NFKC(X) == NFKD(X), c)
|
||||||
|
|
||||||
|
def test_bug_834676(self):
|
||||||
# Check for bug 834676
|
# Check for bug 834676
|
||||||
normalize('NFC',u'\ud55c\uae00')
|
normalize('NFC', u'\ud55c\uae00')
|
||||||
|
|
||||||
|
|
||||||
|
def test_main():
|
||||||
|
run_unittest(NormalizationTest)
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
test_main()
|
test_main()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue