@@ -260,9 +260,8 @@ class DeleteWantTest(unittest.TestCase):
260260 (13 , 4 , "abcde\t abd\t " ),
261261 (16 , 4 , "abcde\t abd\t \t " ),
262262 ]),
263- ("\t abcd" , [
264- (2 , 4 , "" ),
265- (5 , 4 , "\t a" ),
263+ (" " , [
264+ (2 , 2 , " " ),
266265 ]),
267266 ]
268267
@@ -274,30 +273,27 @@ def mock_delete_trail_char_and_space(self, want, chars, tabwidth):
274273 have = len (chars .expandtabs (tabwidth ))
275274 if have <= want or chars [- 1 ] not in " \t " :
276275 break
277- return ncharsdeleted , chars
276+ return chars
277+
278+ def do_tests (self ):
279+ ew = Editor ()
280+ for dat in self .data :
281+ test_str = dat [0 ]
282+ for da in dat [1 ]:
283+ with self .subTest (want = da [0 ], tabwidth = da [1 ], input = test_str ):
284+ res = ew .delete_trail_char_and_space (da [0 ], test_str , da [1 ])
285+ self .assertEqual (res , da [2 ])
278286
279287 def test_delete_trail_char_and_space (self ):
280- with unittest .mock .patch .object (Editor , '__init__' , return_value = None ) as mock_init :
288+ with unittest .mock .patch .object (Editor , '__init__' , return_value = None ):
281289 initial_time_new = time .time ()
282- ew = Editor ()
283- for dat in self .data :
284- test_str = dat [0 ]
285- for da in dat [1 ]:
286- with self .subTest (want = da [0 ], tabwidth = da [1 ], input = test_str ):
287- res_str = ew .delete_trail_char_and_space (da [0 ], test_str , da [1 ])[1 ]
288- self .assertEqual (res_str , da [2 ])
290+ self .do_tests ()
289291 time_new = time .time () - initial_time_new
290-
291- initial_time_old = time .time ()
292+
292293 with unittest .mock .patch .object (Editor , 'delete_trail_char_and_space' , self .mock_delete_trail_char_and_space ):
293- ew = Editor ()
294- for dat in self .data :
295- test_str = dat [0 ]
296- for da in dat [1 ]:
297- with self .subTest (want = da [0 ], tabwidth = da [1 ], input = test_str ):
298- res_str = ew .delete_trail_char_and_space (da [0 ], test_str , da [1 ])[1 ]
299- self .assertEqual (res_str , da [2 ])
300- time_old = time .time () - initial_time_old
294+ initial_time_old = time .time ()
295+ self .do_tests ()
296+ time_old = time .time () - initial_time_old
301297
302298 self .assertGreaterEqual (time_old / time_new , 10 )
303299
0 commit comments