Skip to content

Commit fccf9ab

Browse files
gh-131853: Test binary header in msgfmt generated file (GH-131854)
1 parent be2d218 commit fccf9ab

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

Lib/test/test_tools/test_msgfmt.py

+23
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"""Tests for the Tools/i18n/msgfmt.py tool."""
22

33
import json
4+
import struct
45
import sys
56
import unittest
67
from gettext import GNUTranslations
@@ -40,6 +41,28 @@ def test_compilation(self):
4041

4142
self.assertDictEqual(actual._catalog, expected._catalog)
4243

44+
def test_binary_header(self):
45+
with open(data_dir / "general.mo", "rb") as f:
46+
mo_data = f.read()
47+
48+
(
49+
magic,
50+
version,
51+
num_strings,
52+
orig_table_offset,
53+
trans_table_offset,
54+
hash_table_size,
55+
hash_table_offset,
56+
) = struct.unpack("=Iiiiiii", mo_data[:28])
57+
58+
self.assertEqual(magic, 0x950412de)
59+
self.assertEqual(version, 0)
60+
self.assertEqual(num_strings, 9)
61+
self.assertEqual(orig_table_offset, 28)
62+
self.assertEqual(trans_table_offset, 100)
63+
self.assertEqual(hash_table_size, 0)
64+
self.assertEqual(hash_table_offset, 0)
65+
4366
def test_translations(self):
4467
with open(data_dir / 'general.mo', 'rb') as f:
4568
t = GNUTranslations(f)

0 commit comments

Comments
 (0)