diff options
author | Collin Winter <collinw@gmail.com> | 2007-04-05 20:08:56 (GMT) |
---|---|---|
committer | Collin Winter <collinw@gmail.com> | 2007-04-05 20:08:56 (GMT) |
commit | 9405609c1725ea86c3cdc9a9ac665649d80d62c6 (patch) | |
tree | d98d47115bcc7395254935f3b40a80c6c3df7e46 /Lib/test/test_normalization.py | |
parent | fe712fb9cacc9d04d80853ae3cd6e134a04610f1 (diff) | |
download | cpython-9405609c1725ea86c3cdc9a9ac665649d80d62c6.zip cpython-9405609c1725ea86c3cdc9a9ac665649d80d62c6.tar.gz cpython-9405609c1725ea86c3cdc9a9ac665649d80d62c6.tar.bz2 |
Convert test_normalization to use unittest.
Diffstat (limited to 'Lib/test/test_normalization.py')
-rw-r--r-- | Lib/test/test_normalization.py | 108 |
1 files changed, 57 insertions, 51 deletions
diff --git a/Lib/test/test_normalization.py b/Lib/test/test_normalization.py index 81bdfbd..00e66fa 100644 --- a/Lib/test/test_normalization.py +++ b/Lib/test/test_normalization.py @@ -1,5 +1,6 @@ -from test.test_support import (verbose, TestFailed, TestSkipped, verify, - open_urlresource) +from test.test_support import run_unittest, open_urlresource +import unittest + import sys import os from unicodedata import normalize @@ -28,61 +29,66 @@ def unistr(data): if x > sys.maxunicode: raise RangeError return u"".join([unichr(x) for x in data]) + +class NormalizationTest(unittest.TestCase): + def test_main(self): + part1_data = {} + for line in open_urlresource(TESTDATAURL): + if '#' in line: + line = line.split('#')[0] + line = line.strip() + if not line: + continue + if line.startswith("@Part"): + part = line.split()[0] + continue + if part == "@Part3": + # XXX we don't support PRI #29 yet, so skip these tests for now + continue + try: + c1,c2,c3,c4,c5 = [unistr(x) for x in line.split(';')[:-1]] + except RangeError: + # Skip unsupported characters; + # try atleast adding c1 if we are in part1 + if part == "@Part1": + try: + c1 = unistr(line.split(';')[0]) + except RangeError: + pass + else: + part1_data[c1] = 1 + continue -def test_main(): - part1_data = {} - for line in open_urlresource(TESTDATAURL): - if '#' in line: - line = line.split('#')[0] - line = line.strip() - if not line: - continue - if line.startswith("@Part"): - part = line.split()[0] - continue - if part == "@Part3": - # XXX we don't support PRI #29 yet, so skip these tests for now - continue - try: - c1,c2,c3,c4,c5 = [unistr(x) for x in line.split(';')[:-1]] - except RangeError: - # Skip unsupported characters; - # try atleast adding c1 if we are in part1 - if part == "@Part1": - try: - c1=unistr(line.split(';')[0]) - except RangeError: - pass - else: - part1_data[c1] = 1 - continue + # Perform tests + self.failUnless(c2 == NFC(c1) == NFC(c2) == NFC(c3), line) + self.failUnless(c4 == NFC(c4) == NFC(c5), line) + self.failUnless(c3 == NFD(c1) == NFD(c2) == NFD(c3), line) + self.failUnless(c5 == NFD(c4) == NFD(c5), line) + self.failUnless(c4 == NFKC(c1) == NFKC(c2) == \ + NFKC(c3) == NFKC(c4) == NFKC(c5), + line) + self.failUnless(c5 == NFKD(c1) == NFKD(c2) == \ + NFKD(c3) == NFKD(c4) == NFKD(c5), + line) - if verbose: - print line + # Record part 1 data + if part == "@Part1": + part1_data[c1] = 1 - # Perform tests - verify(c2 == NFC(c1) == NFC(c2) == NFC(c3), line) - verify(c4 == NFC(c4) == NFC(c5), line) - verify(c3 == NFD(c1) == NFD(c2) == NFD(c3), line) - verify(c5 == NFD(c4) == NFD(c5), line) - verify(c4 == NFKC(c1) == NFKC(c2) == NFKC(c3) == NFKC(c4) == NFKC(c5), - line) - verify(c5 == NFKD(c1) == NFKD(c2) == NFKD(c3) == NFKD(c4) == NFKD(c5), - line) + # Perform tests for all other data + for c in range(sys.maxunicode+1): + X = unichr(c) + if X in part1_data: + continue + self.failUnless(X == NFC(X) == NFD(X) == NFKC(X) == NFKD(X), c) - # Record part 1 data - if part == "@Part1": - part1_data[c1] = 1 + def test_bug_834676(self): + # Check for bug 834676 + normalize('NFC', u'\ud55c\uae00') - # Perform tests for all other data - for c in range(sys.maxunicode+1): - X = unichr(c) - if X in part1_data: - continue - assert X == NFC(X) == NFD(X) == NFKC(X) == NFKD(X), c - # Check for bug 834676 - normalize('NFC',u'\ud55c\uae00') +def test_main(): + run_unittest(NormalizationTest) if __name__ == "__main__": test_main() |