From: Stan Ulbrych <89152624+StanFromIreland@users.noreply.github.com> Date: Sat, 29 Mar 2025 12:27:50 +0000 (+0000) Subject: gh-131853: Test binary header in msgfmt generated file (GH-131854) X-Git-Tag: v3.14.0a7~149 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=fccf9ab33d0b16e6171c533d139b6118503197c1;p=thirdparty%2FPython%2Fcpython.git gh-131853: Test binary header in msgfmt generated file (GH-131854) --- diff --git a/Lib/test/test_tools/test_msgfmt.py b/Lib/test/test_tools/test_msgfmt.py index 55a10888c21f..dafac0562f47 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 @@ 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)