(self)
| 1373 | self.assertEqual(uni, puny.decode("punycode")) |
| 1374 | |
| 1375 | def test_decode_invalid(self): |
| 1376 | testcases = [ |
| 1377 | (b"xn--w&", "strict", UnicodeDecodeError("punycode", b"", 5, 6, "")), |
| 1378 | (b"&egbpdaj6bu4bxfgehfvwxn", "strict", UnicodeDecodeError("punycode", b"", 0, 1, "")), |
| 1379 | (b"egbpdaj6bu&4bx&fgehfvwxn", "strict", UnicodeDecodeError("punycode", b"", 10, 11, "")), |
| 1380 | (b"egbpdaj6bu4bxfgehfvwxn&", "strict", UnicodeDecodeError("punycode", b"", 22, 23, "")), |
| 1381 | (b"\xFFProprostnemluvesky-uyb24dma41a", "strict", UnicodeDecodeError("ascii", b"", 0, 1, "")), |
| 1382 | (b"Pro\xFFprostnemluvesky-uyb24dma41a", "strict", UnicodeDecodeError("ascii", b"", 3, 4, "")), |
| 1383 | (b"Proprost&nemluvesky-uyb24&dma41a", "strict", UnicodeDecodeError("punycode", b"", 25, 26, "")), |
| 1384 | (b"Proprostnemluvesky&-&uyb24dma41a", "strict", UnicodeDecodeError("punycode", b"", 20, 21, "")), |
| 1385 | (b"Proprostnemluvesky-&uyb24dma41a", "strict", UnicodeDecodeError("punycode", b"", 19, 20, "")), |
| 1386 | (b"Proprostnemluvesky-uyb24d&ma41a", "strict", UnicodeDecodeError("punycode", b"", 25, 26, "")), |
| 1387 | (b"Proprostnemluvesky-uyb24dma41a&", "strict", UnicodeDecodeError("punycode", b"", 30, 31, "")), |
| 1388 | (b"xn--w&", "ignore", "xn-"), |
| 1389 | ] |
| 1390 | for puny, errors, expected in testcases: |
| 1391 | with self.subTest(puny=puny, errors=errors): |
| 1392 | if isinstance(expected, Exception): |
| 1393 | with self.assertRaises(UnicodeDecodeError) as cm: |
| 1394 | puny.decode("punycode", errors) |
| 1395 | exc = cm.exception |
| 1396 | self.assertEqual(exc.encoding, expected.encoding) |
| 1397 | self.assertEqual(exc.object, puny) |
| 1398 | self.assertEqual(exc.start, expected.start) |
| 1399 | self.assertEqual(exc.end, expected.end) |
| 1400 | else: |
| 1401 | self.assertEqual(puny.decode("punycode", errors), expected) |
| 1402 | |
| 1403 | |
| 1404 | # From http://www.gnu.org/software/libidn/draft-josefsson-idn-test-vectors.html |
nothing calls this directly
no test coverage detected