MCPcopy Index your code
hub / github.com/python/cpython / run_normalization_tests

Method run_normalization_tests

Lib/test/test_unicodedata.py:1218–1268  ·  view source on GitHub ↗
(self, testdata, ucd)

Source from the content-addressed store, hash-verified

1216 self.run_normalization_tests(testdata, unicodedata.ucd_3_2_0)
1217
1218 def run_normalization_tests(self, testdata, ucd):
1219 part = None
1220 part1_data = set()
1221
1222 NFC = partial(ucd.normalize, "NFC")
1223 NFKC = partial(ucd.normalize, "NFKC")
1224 NFD = partial(ucd.normalize, "NFD")
1225 NFKD = partial(ucd.normalize, "NFKD")
1226 is_normalized = ucd.is_normalized
1227
1228 for line in testdata:
1229 if '#' in line:
1230 line = line.split('#')[0]
1231 line = line.strip()
1232 if not line:
1233 continue
1234 if line.startswith("@Part"):
1235 part = line.split()[0]
1236 continue
1237 c1,c2,c3,c4,c5 = [self.unistr(x) for x in line.split(';')[:-1]]
1238
1239 # Perform tests
1240 self.assertTrue(c2 == NFC(c1) == NFC(c2) == NFC(c3), line)
1241 self.assertTrue(c4 == NFC(c4) == NFC(c5), line)
1242 self.assertTrue(c3 == NFD(c1) == NFD(c2) == NFD(c3), line)
1243 self.assertTrue(c5 == NFD(c4) == NFD(c5), line)
1244 self.assertTrue(c4 == NFKC(c1) == NFKC(c2) == \
1245 NFKC(c3) == NFKC(c4) == NFKC(c5),
1246 line)
1247 self.assertTrue(c5 == NFKD(c1) == NFKD(c2) == \
1248 NFKD(c3) == NFKD(c4) == NFKD(c5),
1249 line)
1250
1251 self.assertTrue(is_normalized("NFC", c2))
1252 self.assertTrue(is_normalized("NFC", c4))
1253
1254 self.assertTrue(is_normalized("NFD", c3))
1255 self.assertTrue(is_normalized("NFD", c5))
1256
1257 self.assertTrue(is_normalized("NFKC", c4))
1258 self.assertTrue(is_normalized("NFKD", c5))
1259
1260 # Record part 1 data
1261 if part == "@Part1":
1262 part1_data.add(c1)
1263
1264 # Perform tests for all other data
1265 for X in iterallchars():
1266 if X in part1_data:
1267 continue
1268 self.assertTrue(X == NFC(X) == NFD(X) == NFKC(X) == NFKD(X), ord(X))
1269
1270 def test_edge_cases(self):
1271 self.assertRaises(TypeError, unicodedata.normalize)

Callers 2

test_normalizationMethod · 0.95

Calls 9

unistrMethod · 0.95
partialClass · 0.90
setFunction · 0.85
iterallcharsFunction · 0.85
assertTrueMethod · 0.80
splitMethod · 0.45
stripMethod · 0.45
startswithMethod · 0.45
addMethod · 0.45

Tested by

no test coverage detected