]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-131853: Test binary header in msgfmt generated file (GH-131854)
authorStan Ulbrych <89152624+StanFromIreland@users.noreply.github.com>
Sat, 29 Mar 2025 12:27:50 +0000 (12:27 +0000)
committerGitHub <noreply@github.com>
Sat, 29 Mar 2025 12:27:50 +0000 (14:27 +0200)
Lib/test/test_tools/test_msgfmt.py

index 55a10888c21f70b4598d4e8bcf24eea413991a65..dafac0562f472df3ce1dc8aa2b4a44a93fad0ce8 100644 (file)
@@ -1,6 +1,7 @@
 """Tests for the Tools/i18n/msgfmt.py tool."""
 
 import json
+import struct
 import sys
 import unittest
 from gettext import GNUTranslations
@@ -40,6 +41,28 @@ class CompilationTest(unittest.TestCase):
 
                     self.assertDictEqual(actual._catalog, expected._catalog)
 
+    def test_binary_header(self):
+        with open(data_dir / "general.mo", "rb") as f:
+            mo_data = f.read()
+
+        (
+            magic,
+            version,
+            num_strings,
+            orig_table_offset,
+            trans_table_offset,
+            hash_table_size,
+            hash_table_offset,
+        ) = struct.unpack("=Iiiiiii", mo_data[:28])
+
+        self.assertEqual(magic, 0x950412de)
+        self.assertEqual(version, 0)
+        self.assertEqual(num_strings, 9)
+        self.assertEqual(orig_table_offset, 28)
+        self.assertEqual(trans_table_offset, 100)
+        self.assertEqual(hash_table_size, 0)
+        self.assertEqual(hash_table_offset, 0)
+
     def test_translations(self):
         with open(data_dir / 'general.mo', 'rb') as f:
             t = GNUTranslations(f)