Skip to content

Commit 5cd3c9f

Browse files
committed
Add test for content-type
1 parent 431fd4c commit 5cd3c9f

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

Lib/test/test_gettext.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -664,6 +664,21 @@ def test_ignore_comments_in_headers_issue36239(self):
664664
t = gettext.GNUTranslations(fp)
665665
self.assertEqual(t.info()["plural-forms"], "nplurals=2; plural=(n != 1);")
666666

667+
def test_raise_descriptive_error_for_incorrect_content_type(self):
668+
with open(MOFILE, 'wb') as fp:
669+
# below is msgfmt run on such a PO file:
670+
# msgid ""
671+
# msgstr ""
672+
# "Content-Type: text/plain; charste=UTF-8\n"
673+
fp.write(
674+
b'\xde\x12\x04\x95\x00\x00\x00\x00\x01\x00\x00\x00\x1c\x00\x00\x00$\x00\x00\x00\x03\x00\x00\x00,\x00'
675+
b'\x00\x00\x00\x00\x00\x008\x00\x00\x007\x00\x00\x009\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00'
676+
b'\x00\x00\x00\x00Content-Type: text/plain; charste=UTF-8\n\x00'
677+
)
678+
with self.assertRaisesRegex(ValueError, "invalid content-type syntax"):
679+
with open(MOFILE, 'rb') as fp:
680+
gettext.GNUTranslations(fp)
681+
667682
def test_raise_descriptive_error_for_incorrect_plural_forms(self):
668683
with open(MOFILE, 'wb') as fp:
669684
# below is msgfmt run on such a PO file:

0 commit comments

Comments
 (0)