Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(14)

Delta Between Two Patch Sets: Lib/test/test_unicode.py

Issue 9682: socket.create_connection error message for domain subpart with invalid length is very confusing
Left Patch Set: Created 6 years, 10 months ago
Right Patch Set: Created 6 years, 9 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « Lib/encodings/idna.py ('k') | no next file » | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
1 """ Test script for the Unicode implementation. 1 """ Test script for the Unicode implementation.
2 2
3 Written by Marc-Andre Lemburg (mal@lemburg.com). 3 Written by Marc-Andre Lemburg (mal@lemburg.com).
4 4
5 (c) Copyright CNRI, All Rights Reserved. NO WARRANTY. 5 (c) Copyright CNRI, All Rights Reserved. NO WARRANTY.
6 6
7 """#" 7 """#"
8 import _string 8 import _string
9 import codecs 9 import codecs
10 import itertools 10 import itertools
11 import struct 11 import struct
12 import sys 12 import sys
13 13
14 import unittest 14 import unittest
15 from encodings.idna import \ 15 from encodings.idna import ToASCII
r.david.murray 2013/04/27 03:04:44 I would prefer to do black box testing: don't test
16 validate_max_length, \
17 validate_min_length, \
18 ToASCII
19 import warnings 16 import warnings
20 from test import support, string_tests 17 from test import support, string_tests
21 from unittest import mock 18 from unittest import mock
22 19
23 # Error handling (bad decoder return) 20 # Error handling (bad decoder return)
24 def search_function(encoding): 21 def search_function(encoding):
25 def decode1(input, errors="strict"): 22 def decode1(input, errors="strict"):
26 return 42 # not a tuple 23 return 42 # not a tuple
27 def encode1(input, errors="strict"): 24 def encode1(input, errors="strict"):
28 return 42 # not a tuple 25 return 42 # not a tuple
(...skipping 1643 matching lines...) Expand 10 before | Expand all | Expand 10 after
1672 ('F4 8F BF C0', FFFDx2), ('F4 8F BF FF', FFFDx2) 1669 ('F4 8F BF C0', FFFDx2), ('F4 8F BF FF', FFFDx2)
1673 ] 1670 ]
1674 for seq, res in sequences: 1671 for seq, res in sequences:
1675 self.assertCorrectUTF8Decoding(self.to_bytestring(seq), res, 1672 self.assertCorrectUTF8Decoding(self.to_bytestring(seq), res,
1676 'invalid continuation byte') 1673 'invalid continuation byte')
1677 1674
1678 def test_codecs_idna(self): 1675 def test_codecs_idna(self):
1679 # Test whether trailing dot is preserved 1676 # Test whether trailing dot is preserved
1680 self.assertEqual("www.python.org.".encode("idna"), b"www.python.org.") 1677 self.assertEqual("www.python.org.".encode("idna"), b"www.python.org.")
1681 1678
1682 def test_max_length_validation(self):
1683 expected = "Z" * 64
1684 label = expected.encode('ascii')
1685 with self.assertRaisesRegexp(UnicodeError, expected):
1686 validate_max_length(label)
1687
1688 def test_min_length_validation(self):
1689 label = "".encode('ascii')
1690 labels = "abcdefg".encode('ascii')
1691 with self.assertRaisesRegexp(UnicodeError, " in 'abcdefg'"):
1692 validate_min_length(label, labels)
1693
1694 with self.assertRaisesRegexp(UnicodeError, "empty label"):
1695 validate_min_length(label)
1696
1697 def test_min_codecs_error_messages(self): 1679 def test_min_codecs_error_messages(self):
1698 # Test Empty 1680 # Test Empty
1699 self.assertRaisesRegexp( 1681 self.assertRaisesRegexp(
1700 UnicodeError, 1682 UnicodeError,
1701 '1..com', 1683 '1..com',
1702 '1..com'.encode, 1684 '1..com'.encode,
1703 'idna') 1685 'idna')
1704 1686
1705 def test_max_codecs_errors_messages(self): 1687 def test_max_codecs_errors_messages(self):
1706 # Test label greater then 64 1688 # Test label greater then 64
(...skipping 22 matching lines...) Expand all
1729 1711
1730 def test_min_label_encode_ascii(self): 1712 def test_min_label_encode_ascii(self):
1731 with self.assertRaisesRegexp(UnicodeError, "empty label"): 1713 with self.assertRaisesRegexp(UnicodeError, "empty label"):
1732 ToASCII('') 1714 ToASCII('')
1733 1715
1734 def test_max_label_encode_ascii(self): 1716 def test_max_label_encode_ascii(self):
1735 label = "Z" * 64 1717 label = "Z" * 64
1736 with self.assertRaisesRegexp(UnicodeError, label): 1718 with self.assertRaisesRegexp(UnicodeError, label):
1737 ToASCII(label) 1719 ToASCII(label)
1738 1720
1739 @mock.patch('encodings.idna.nameprep') 1721 @mock.patch('encodings.idna.nameprep')
r.david.murray 2013/04/27 03:04:44 I don't understand the purpose of these tests. Ca
mmilkin 2013/04/27 16:04:56 Sure, the ToASCII function has many calls to valid
1740 def test_escaped_min_label(self, nameprep): 1722 def test_escaped_min_label(self, nameprep):
1741 label = mock.Mock() 1723 label = mock.Mock()
1742 label.encode.side_effect = UnicodeError 1724 label.encode.side_effect = UnicodeError
1743 nameprep.return_value = '' 1725 nameprep.return_value = ''
1744 with self.assertRaisesRegexp(UnicodeError, "empty label"): 1726 with self.assertRaisesRegexp(UnicodeError, "empty label"):
1745 ToASCII(label) 1727 ToASCII(label)
1746 1728
1747 @mock.patch('encodings.idna.nameprep') 1729 @mock.patch('encodings.idna.nameprep')
1748 def test_escaped_max_label(self, nameprep): 1730 def test_escaped_max_label(self, nameprep):
1749 mock_label = mock.Mock() 1731 mock_label = mock.Mock()
(...skipping 688 matching lines...) Expand 10 before | Expand all | Expand 10 after
2438 "obj", 2420 "obj",
2439 [(True, 'arg'), 2421 [(True, 'arg'),
2440 (False, 'key1'), 2422 (False, 'key1'),
2441 (False, 'key2'), 2423 (False, 'key2'),
2442 ]]) 2424 ]])
2443 self.assertRaises(TypeError, _string.formatter_field_name_split, 1) 2425 self.assertRaises(TypeError, _string.formatter_field_name_split, 1)
2444 2426
2445 2427
2446 if __name__ == "__main__": 2428 if __name__ == "__main__":
2447 unittest.main() 2429 unittest.main()
LEFTRIGHT

RSS Feeds Recent Issues | This issue
This is Rietveld 894c83f36cb7+