@@ -4564,31 +4564,39 @@ def __init__(self):
45644564 actual = self .get_suggestion (Outer (), 'target' )
45654565 self .assertIn ("'.normal.target'" , actual )
45664566
4567+ @force_not_colorized
45674568 def test_cross_language (self ):
45684569 cases = [
4569- # (obj, attr, expected_substring)
4570- ([], 'push' , "'.append'" ),
4571- ([], 'concat' , "'.extend'" ),
4572- ([], 'addAll' , "'.extend'" ),
4573- ([], 'contains' , "Use 'x in list'." ),
4574- ([], 'add' , "Did you mean to use a 'set' object?" ),
4575- ('' , 'toUpperCase' , "'.upper'" ),
4576- ('' , 'toLowerCase' , "'.lower'" ),
4577- ('' , 'trimStart' , "'.lstrip'" ),
4578- ('' , 'trimEnd' , "'.rstrip'" ),
4579- ({}, 'keySet' , "'.keys'" ),
4580- ({}, 'entrySet' , "'.items'" ),
4581- ({}, 'entries' , "'.items'" ),
4582- ({}, 'putAll' , "'.update'" ),
4583- ({}, 'put' , "d[k] = v" ),
4570+ # (type, attr, hint_attr)
4571+ (list , 'push' , 'append' ),
4572+ (list , 'concat' , 'extend' ),
4573+ (list , 'addAll' , 'extend' ),
4574+ (str , 'toUpperCase' , 'upper' ),
4575+ (str , 'toLowerCase' , 'lower' ),
4576+ (str , 'trimStart' , 'lstrip' ),
4577+ (str , 'trimEnd' , 'rstrip' ),
4578+ (dict , 'keySet' , 'keys' ),
4579+ (dict , 'entrySet' , 'items' ),
4580+ (dict , 'entries' , 'items' ),
4581+ (dict , 'putAll' , 'update' ),
4582+ ]
4583+ for test_type , attr , hint_attr in cases :
4584+ with self .subTest (type = test_type .__name__ , attr = attr ):
4585+ obj = test_type ()
4586+ actual = self .get_suggestion (obj , attr )
4587+ self .assertEndsWith (actual , f"Did you mean '.{ hint_attr } '?" )
4588+
4589+ cases = [
4590+ # (type, attr, hint)
4591+ (list , 'contains' , "Use 'x in list'." ),
4592+ (list , 'add' , "Did you mean to use a 'set' object?" ),
4593+ (dict , 'put' , "Use d[k] = v." ),
45844594 ]
4585- for obj , attr , expected in cases :
4586- with self .subTest (type = type (obj ).__name__ , attr = attr ):
4595+ for test_type , attr , expected in cases :
4596+ with self .subTest (type = test_type , attr = attr ):
4597+ obj = test_type ()
45874598 actual = self .get_suggestion (obj , attr )
4588- self .assertIn (expected , actual )
4589- # push hint should not repeat the wrong attribute name
4590- actual = self .get_suggestion ([], 'push' )
4591- self .assertNotIn ("instead of" , actual )
4599+ self .assertEndsWith (actual , expected )
45924600
45934601 def test_cross_language_levenshtein_takes_priority (self ):
45944602 # Levenshtein catches trim->strip and indexOf->index before
0 commit comments