Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 1b445d3

Browse files
committed
Fiddled things so that test_normalization is expected to be skipped if
and only if the test input file doesn't exist.
1 parent 65730a4 commit 1b445d3

2 files changed

Lines changed: 60 additions & 39 deletions

File tree

Lib/test/regrtest.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -503,6 +503,10 @@ def printlist(x, width=70, indent=4):
503503
# test_pep277
504504
# The _ExpectedSkips constructor adds this to the set of expected
505505
# skips if not os.path.supports_unicode_filenames.
506+
# test_normalization
507+
# Whether a skip is expected here depends on whether a large test
508+
# input file has been downloaded. test_normalization.skip_expected
509+
# controls that
506510

507511
_expectations = {
508512
'win32':
@@ -528,7 +532,6 @@ def printlist(x, width=70, indent=4):
528532
test_mhlib
529533
test_mpz
530534
test_nis
531-
test_normalization
532535
test_openpty
533536
test_poll
534537
test_pty
@@ -829,12 +832,19 @@ def printlist(x, width=70, indent=4):
829832
class _ExpectedSkips:
830833
def __init__(self):
831834
import os.path
835+
from test import test_normalization
836+
832837
self.valid = False
833838
if sys.platform in _expectations:
834839
s = _expectations[sys.platform]
835840
self.expected = Set(s.split())
841+
836842
if not os.path.supports_unicode_filenames:
837843
self.expected.add('test_pep277')
844+
845+
if test_normalization.skip_expected:
846+
self.expected.add('test_normalization')
847+
838848
self.valid = True
839849

840850
def isvalid(self):

Lib/test/test_normalization.py

Lines changed: 49 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
from test.test_support import verbose, TestFailed, TestSkipped, verify
22
import sys
3+
import os
34
from unicodedata import normalize
4-
try:
5-
data = open("NormalizationTest.txt", "r").readlines()
6-
except IOError:
7-
raise TestSkipped("NormalizationTest.txt not found, download from "
8-
"http://www.unicode.org/Public/UNIDATA/NormalizationTest.txt")
5+
6+
TESTDATAFILE = "NormalizationTest.txt"
7+
skip_expected = not os.path.exists(TESTDATAFILE)
98

109
class RangeError:
1110
pass
@@ -29,40 +28,52 @@ def unistr(data):
2928
raise RangeError
3029
return u"".join([unichr(x) for x in data])
3130

32-
part1_data = {}
33-
for line in data:
34-
if '#' in line:
35-
line = line.split('#')[0]
36-
line = line.strip()
37-
if not line:
38-
continue
39-
if line.startswith("@Part"):
40-
part = line
41-
continue
42-
try:
43-
c1,c2,c3,c4,c5 = [unistr(x) for x in line.split(';')[:-1]]
44-
except RangeError:
45-
# Skip unsupported characters
46-
continue
31+
def test_main():
32+
if skip_expected:
33+
raise TestSkipped(TESTDATAFILE + " not found, download from " +
34+
"http://www.unicode.org/Public/UNIDATA/" + TESTDATAFILE)
35+
36+
data = open(TESTDATAFILE).readlines()
37+
38+
part1_data = {}
39+
for line in data:
40+
if '#' in line:
41+
line = line.split('#')[0]
42+
line = line.strip()
43+
if not line:
44+
continue
45+
if line.startswith("@Part"):
46+
part = line
47+
continue
48+
try:
49+
c1,c2,c3,c4,c5 = [unistr(x) for x in line.split(';')[:-1]]
50+
except RangeError:
51+
# Skip unsupported characters
52+
continue
53+
54+
if verbose:
55+
print line
4756

48-
if verbose:
49-
print line
57+
# Perform tests
58+
verify(c2 == NFC(c1) == NFC(c2) == NFC(c3), line)
59+
verify(c4 == NFC(c4) == NFC(c5), line)
60+
verify(c3 == NFD(c1) == NFD(c2) == NFD(c3), line)
61+
verify(c5 == NFD(c4) == NFD(c5), line)
62+
verify(c4 == NFKC(c1) == NFKC(c2) == NFKC(c3) == NFKC(c4) == NFKC(c5),
63+
line)
64+
verify(c5 == NFKD(c1) == NFKD(c2) == NFKD(c3) == NFKD(c4) == NFKD(c5),
65+
line)
5066

51-
# Perform tests
52-
verify(c2 == NFC(c1) == NFC(c2) == NFC(c3), line)
53-
verify(c4 == NFC(c4) == NFC(c5), line)
54-
verify(c3 == NFD(c1) == NFD(c2) == NFD(c3), line)
55-
verify(c5 == NFD(c4) == NFD(c5), line)
56-
verify(c4 == NFKC(c1) == NFKC(c2) == NFKC(c3) == NFKC(c4) == NFKC(c5), line)
57-
verify(c5 == NFKD(c1) == NFKD(c2) == NFKD(c3) == NFKD(c4) == NFKD(c5), line)
67+
# Record part 1 data
68+
if part == "@Part1":
69+
part1_data[c1] = 1
5870

59-
# Record part 1 data
60-
if part == "@Part1":
61-
part1_data[c1] = 1
71+
# Perform tests for all other data
72+
for c in range(sys.maxunicode+1):
73+
X = unichr(c)
74+
if X in part1_data:
75+
continue
76+
assert X == NFC(X) == NFD(X) == NFKC(X) == NFKD(X), c
6277

63-
# Perform tests for all other data
64-
for c in range(sys.maxunicode+1):
65-
X = unichr(c)
66-
if X in part1_data:
67-
continue
68-
assert X == NFC(X) == NFD(X) == NFKC(X) == NFKD(X), c
78+
if __name__ == "__main__":
79+
test_main()

0 commit comments

Comments
 (0)