https://github.com/python/cpython/commit/fccf9ab33d0b16e6171c533d139b6118503197c1
commit: fccf9ab33d0b16e6171c533d139b6118503197c1
branch: main
author: Stan Ulbrych <89152624+stanfromirel...@users.noreply.github.com>
committer: serhiy-storchaka <storch...@gmail.com>
date: 2025-03-29T14:27:50+02:00
summary:

gh-131853: Test binary header in msgfmt generated file (GH-131854)

files:
M Lib/test/test_tools/test_msgfmt.py

diff --git a/Lib/test/test_tools/test_msgfmt.py 
b/Lib/test/test_tools/test_msgfmt.py
index 55a10888c21f70..dafac0562f472d 100644
--- a/Lib/test/test_tools/test_msgfmt.py
+++ b/Lib/test/test_tools/test_msgfmt.py
@@ -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 @@ def test_compilation(self):
 
                     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)

_______________________________________________
Python-checkins mailing list -- python-checkins@python.org
To unsubscribe send an email to python-checkins-le...@python.org
https://mail.python.org/mailman3/lists/python-checkins.python.org/
Member address: arch...@mail-archive.com

Reply via email to