@@ -369,15 +369,8 @@ class _(object):
369369
370370 def test_pygettext_output (self ):
371371 """Test that the pygettext output exactly matches snapshots."""
372- for input_file in DATA_DIR .glob ('*.py' ):
373- output_file = input_file .with_suffix ('.pot' )
374- with self .subTest (input_file = f'i18n_data/{ input_file } ' ):
375- contents = input_file .read_text (encoding = 'utf-8' )
376- with temp_cwd (None ):
377- Path (input_file .name ).write_text (contents )
378- assert_python_ok ('-Xutf8' , self .script , '--docstrings' , input_file .name )
379- output = Path ('messages.pot' ).read_text (encoding = 'utf-8' )
380-
372+ for input_file , output_file , output in extract_from_snapshots ():
373+ with self .subTest (input_file = input_file ):
381374 expected = output_file .read_text (encoding = 'utf-8' )
382375 self .assert_POT_equal (expected , output )
383376
@@ -408,15 +401,37 @@ def test_files_list(self):
408401 self .assertNotIn (text3 , data )
409402
410403
411- def update_POT_snapshots ():
412- for input_file in DATA_DIR .glob ('*.py' ):
413- output_file = input_file .with_suffix ('.pot' )
404+ def extract_from_snapshots ():
405+ snapshots = {
406+ 'messages.py' : ('--docstrings' ,),
407+ 'fileloc.py' : ('--docstrings' ,),
408+ 'docstrings.py' : ('--docstrings' ,),
409+ # == Test character escaping
410+ # Escape ascii and unicode:
411+ 'escapes.py' : ('--escape' ,),
412+ # Escape only ascii and let unicode pass through:
413+ ('escapes.py' , 'ascii-escapes.pot' ): (),
414+ }
415+
416+ for filename , args in snapshots .items ():
417+ if isinstance (filename , tuple ):
418+ filename , output_file = filename
419+ output_file = DATA_DIR / output_file
420+ input_file = DATA_DIR / filename
421+ else :
422+ input_file = DATA_DIR / filename
423+ output_file = input_file .with_suffix ('.pot' )
414424 contents = input_file .read_bytes ()
415425 with temp_cwd (None ):
416426 Path (input_file .name ).write_bytes (contents )
417- assert_python_ok ('-Xutf8' , Test_pygettext .script , '--docstrings' , input_file .name )
418- output = Path ('messages.pot' ).read_text (encoding = 'utf-8' )
427+ assert_python_ok ('-Xutf8' , Test_pygettext .script , * args ,
428+ input_file .name )
429+ yield (input_file , output_file ,
430+ Path ('messages.pot' ).read_text (encoding = 'utf-8' ))
431+
419432
433+ def update_POT_snapshots ():
434+ for _ , output_file , output in extract_from_snapshots ():
420435 output = normalize_POT_file (output )
421436 output_file .write_text (output , encoding = 'utf-8' )
422437
0 commit comments