@@ -393,13 +393,14 @@ def test_case_handling(tmpdir, capsys):
393393 assert f .read ().decode ('utf-8' ) == 'this has an ASCII error'
394394
395395
396- def test_case_handling_in_fixes (tmpdir , capsys ):
397- """Test that the case of fixes is similar to the mispelled word."""
396+ def _helper_test_case_handling_in_fixes (tmpdir , capsys , reason ):
398397 d = str (tmpdir )
399- with open (op .join (d , 'dictionary_with_reason.txt' ), 'w' ) as f :
400- fix = 'adopter, adaptor'
401- reason = 'these are different words!'
402- f .write (f'adoptor->{ fix } , { reason } \n ' )
398+
399+ with open (op .join (d , 'dictionary.txt' ), 'w' ) as f :
400+ if reason :
401+ f .write ('adoptor->adopter, adaptor, reason\n ' )
402+ else :
403+ f .write ('adoptor->adopter, adaptor,\n ' )
403404 dictionary_name = f .name
404405
405406 # the mispelled word is entirely lowercase
@@ -408,33 +409,45 @@ def test_case_handling_in_fixes(tmpdir, capsys):
408409 code , stdout , _ = cs .main ('-D' , dictionary_name , f .name , std = True )
409410 # all suggested fixes must be lowercase too
410411 assert 'adopter, adaptor' in stdout
412+ # the reason, if any, must not be modified
413+ if reason :
414+ assert 'reason' in stdout
411415
412416 # the mispelled word is capitalized
413417 with open (op .join (d , 'bad.txt' ), 'w' ) as f :
414418 f .write ('Early Adoptor\n ' )
415419 code , stdout , _ = cs .main ('-D' , dictionary_name , f .name , std = True )
416420 # all suggested fixes must be capitalized too
417421 assert 'Adopter, Adaptor' in stdout
418- # the reason, however, must not be modified
419- assert reason in stdout
422+ # the reason, if any, must not be modified
423+ if reason :
424+ assert 'reason' in stdout
420425
421426 # the mispelled word is entirely uppercase
422427 with open (op .join (d , 'bad.txt' ), 'w' ) as f :
423428 f .write ('EARLY ADOPTOR\n ' )
424429 code , stdout , _ = cs .main ('-D' , dictionary_name , f .name , std = True )
425430 # all suggested fixes must be uppercase too
426431 assert 'ADOPTER, ADAPTOR' in stdout
427- # the reason, however, must not be modified
428- assert reason in stdout
432+ # the reason, if any, must not be modified
433+ if reason :
434+ assert 'reason' in stdout
429435
430436 # the mispelled word mixes lowercase and uppercase
431437 with open (op .join (d , 'bad.txt' ), 'w' ) as f :
432438 f .write ('EaRlY AdOpToR\n ' )
433439 code , stdout , _ = cs .main ('-D' , dictionary_name , f .name , std = True )
434440 # all suggested fixes should be lowercase
435441 assert 'adopter, adaptor' in stdout
436- # the reason, however, must not be modified
437- assert reason in stdout
442+ # the reason, if any, must not be modified
443+ if reason :
444+ assert 'reason' in stdout
445+
446+
447+ def test_case_handling_in_fixes (tmpdir , capsys ):
448+ """Test that the case of fixes is similar to the mispelled word."""
449+ _helper_test_case_handling_in_fixes (tmpdir , capsys , reason = False )
450+ _helper_test_case_handling_in_fixes (tmpdir , capsys , reason = True )
438451
439452
440453def test_context (tmpdir , capsys ):
0 commit comments