Skip to content

Commit 6ae6273

Browse files
committed
Add some more tests
1 parent 5be0eaa commit 6ae6273

File tree

1 file changed

+17
-11
lines changed

1 file changed

+17
-11
lines changed

Lib/test/test_email/test_email.py

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -730,20 +730,26 @@ def test_nonascii_add_header_with_tspecial(self):
730730

731731
def test_invalid_headers(self):
732732
invalid_headers = [
733-
('Invalid Header', 'Contains space'),
734-
('Tab\tHeader', 'Contains tab'),
735-
('Colon:Header', 'Contains colon'),
733+
('Invalid Header', 'contains space'),
734+
('Tab\tHeader', 'contains tab'),
735+
('Colon:Header', 'contains colon'),
736736
('', 'Empty name'),
737-
('Header\x7F', 'Non-ASCII character'),
738-
('Header\x1F', 'Control character'),
739-
(' LeadingSpace', 'Starts with space'),
740-
('TrailingSpace ', 'Ends with space'),
737+
(' LeadingSpace', 'starts with space'),
738+
('TrailingSpace ', 'ends with space'),
741739
]
742740
for name, value in invalid_headers:
743-
with self.subTest(header=name):
744-
with self.assertRaises(ValueError) as cm:
745-
self.message.add_header(name, value)
746-
self.assertIn("Invalid header", str(cm.exception))
741+
with self.assertRaises(ValueError) as cm:
742+
Message().add_header(name, value)
743+
self.assertIn("Invalid header field name", str(cm.exception))
744+
745+
invalid_headers = [
746+
('Header\x7F', 'Non-ASCII character'),
747+
('Header\x1F', 'control character'),
748+
]
749+
for name, value in invalid_headers:
750+
with self.assertRaises(ValueError) as cm:
751+
Message().add_header(name, value)
752+
self.assertIn(f"Header field name {name!r} contains invalid characters", str(cm.exception))
747753

748754
def test_binary_quopri_payload(self):
749755
for charset in ('latin-1', 'ascii'):

0 commit comments

Comments
 (0)