From fccf9ab33d0b16e6171c533d139b6118503197c1 Mon Sep 17 00:00:00 2001 From: Stan Ulbrych <89152624+StanFromIreland@users.noreply.github.com> Date: Sat, 29 Mar 2025 12:27:50 +0000 Subject: gh-131853: Test binary header in msgfmt generated file (GH-131854) --- Lib/test/test_tools/test_msgfmt.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/Lib/test/test_tools/test_msgfmt.py b/Lib/test/test_tools/test_msgfmt.py index 55a1088..dafac05 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) -- cgit v0.12