summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_normalization.py
diff options
context:
space:
mode:
authorTim Peters <tim.peters@gmail.com>2002-11-24 18:53:11 (GMT)
committerTim Peters <tim.peters@gmail.com>2002-11-24 18:53:11 (GMT)
commit1b445d3fcfcc06e5360e83b978efdb9b1c980278 (patch)
treedd7c86f5d1a726c63f66bc569096a1db3570dab9 /Lib/test/test_normalization.py
parent65730a4de80b5446d4bd3301098c1c053af99b27 (diff)
downloadcpython-1b445d3fcfcc06e5360e83b978efdb9b1c980278.zip
cpython-1b445d3fcfcc06e5360e83b978efdb9b1c980278.tar.gz
cpython-1b445d3fcfcc06e5360e83b978efdb9b1c980278.tar.bz2
Fiddled things so that test_normalization is expected to be skipped if
and only if the test input file doesn't exist.
Diffstat (limited to 'Lib/test/test_normalization.py')
-rw-r--r--Lib/test/test_normalization.py87
1 files changed, 49 insertions, 38 deletions
diff --git a/Lib/test/test_normalization.py b/Lib/test/test_normalization.py
index fb88762..b673739 100644
--- a/Lib/test/test_normalization.py
+++ b/Lib/test/test_normalization.py
@@ -1,11 +1,10 @@
from test.test_support import verbose, TestFailed, TestSkipped, verify
import sys
+import os
from unicodedata import normalize
-try:
- data = open("NormalizationTest.txt", "r").readlines()
-except IOError:
- raise TestSkipped("NormalizationTest.txt not found, download from "
- "http://www.unicode.org/Public/UNIDATA/NormalizationTest.txt")
+
+TESTDATAFILE = "NormalizationTest.txt"
+skip_expected = not os.path.exists(TESTDATAFILE)
class RangeError:
pass
@@ -29,40 +28,52 @@ def unistr(data):
raise RangeError
return u"".join([unichr(x) for x in data])
-part1_data = {}
-for line in data:
- if '#' in line:
- line = line.split('#')[0]
- line = line.strip()
- if not line:
- continue
- if line.startswith("@Part"):
- part = line
- continue
- try:
- c1,c2,c3,c4,c5 = [unistr(x) for x in line.split(';')[:-1]]
- except RangeError:
- # Skip unsupported characters
- continue
+def test_main():
+ if skip_expected:
+ raise TestSkipped(TESTDATAFILE + " not found, download from " +
+ "http://www.unicode.org/Public/UNIDATA/" + TESTDATAFILE)
+
+ data = open(TESTDATAFILE).readlines()
+
+ part1_data = {}
+ for line in data:
+ if '#' in line:
+ line = line.split('#')[0]
+ line = line.strip()
+ if not line:
+ continue
+ if line.startswith("@Part"):
+ part = line
+ continue
+ try:
+ c1,c2,c3,c4,c5 = [unistr(x) for x in line.split(';')[:-1]]
+ except RangeError:
+ # Skip unsupported characters
+ continue
+
+ if verbose:
+ print line
- if verbose:
- print line
+ # 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
- 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)
+ # Record part 1 data
+ if part == "@Part1":
+ part1_data[c1] = 1
- # Record part 1 data
- if part == "@Part1":
- part1_data[c1] = 1
+ # 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
-# 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
+if __name__ == "__main__":
+ test_main()