99
1010from  test .support .os_helper  import  temp_cwd 
1111from  test .support .script_helper  import  assert_python_failure , assert_python_ok 
12- from  test .test_tools  import  skip_if_missing , toolsdir 
12+ from  test .test_tools  import  imports_under_tool ,  skip_if_missing , toolsdir 
1313
1414
1515skip_if_missing ('i18n' )
1818script_dir  =  Path (toolsdir ) /  'i18n' 
1919msgfmt  =  script_dir  /  'msgfmt.py' 
2020
21+ with  imports_under_tool ("i18n" ):
22+     from  msgfmt  import  _hashpjw 
23+ 
2124
2225def  compile_messages (po_file , mo_file ):
2326    assert_python_ok (msgfmt , '-o' , mo_file , po_file )
@@ -42,7 +45,25 @@ def test_compilation(self):
4245                    self .assertDictEqual (actual ._catalog , expected ._catalog )
4346
4447    def  test_hash_table (self ):
45-         pass 
48+         # Check _hashpjw generates correct hash values 
49+         self .assertEqual (_hashpjw (b"stan" ), 502398 )
50+         self .assertEqual (_hashpjw (b"foo" ), 27999 )
51+ 
52+         # Check hash table is generated correctly for general.po 
53+         with  temp_cwd ():
54+             tmp_mo_file  =  "messages.mo" 
55+             compile_messages (data_dir  /  "general.po" , tmp_mo_file )
56+             with  open (tmp_mo_file , "rb" ) as  f :
57+                 mo_data  =  f .read ()
58+ 
59+             header  =  struct .unpack ("=7I" , mo_data [:28 ])
60+             hash_table_size , hash_table_offset  =  header [5 :7 ]
61+ 
62+             hash_tab  =  struct .unpack (f"={ hash_table_size }  ,
63+                                        mo_data [hash_table_offset  : hash_table_offset  +  (hash_table_size  *  4 )])
64+ 
65+             self .assertEqual (hash_tab , (1 , 3 , 0 , 8 , 9 , 7 , 2 , 0 , 4 , 5 , 0 , 6 , 0 ))
66+ 
4667
4768    def  test_binary_header (self ):
4869        with  temp_cwd ():
0 commit comments