@@ -502,12 +502,10 @@ def test_prompt_install(self, env={}, directory: t.Optional[Path] = None):
502
502
** env ,
503
503
}
504
504
505
- rex = re .compile
506
505
expected = [
507
- rex (r"Append the above contents to (?P<file>.*)\?" ), # 0
508
- rex (r"Create (?P<file>.*) with the above contents\?" ), # 1
509
- rex (r"Aborted shell completion installation." ), # 2
510
- rex (rf"Installed autocompletion for { self .shell } " ), # 3
506
+ re .compile (r"\[y/N\]" ), # 0
507
+ re .compile ("Aborted" ), # 1
508
+ re .compile ("Installed" ), # 2
511
509
]
512
510
513
511
install_command = [
@@ -522,23 +520,17 @@ def test_prompt_install(self, env={}, directory: t.Optional[Path] = None):
522
520
523
521
install = pexpect .spawn (self .manage_script , install_command , env = env )
524
522
525
- def wait_for_output (child ) -> t .Tuple [int , t .Optional [str ]]:
526
- index = child .expect (expected )
527
- if index in [0 , 1 ]:
528
- return index , child .match .group ("file" ).decode ()
529
- return index , None
530
-
531
523
# test an abort
532
- idx , _ = wait_for_output ( install )
533
- self .assertLess (idx , 2 )
524
+ idx = install . expect ( expected )
525
+ self .assertEqual (idx , 0 )
534
526
install .sendline ("N" )
535
527
536
528
while True :
537
- idx , _ = wait_for_output ( install )
538
- if idx < 2 :
529
+ idx = install . expect ( expected )
530
+ if idx == 0 :
539
531
install .sendline ("N" )
540
532
else :
541
- self .assertEqual (idx , 2 )
533
+ self .assertEqual (idx , 1 )
542
534
break
543
535
544
536
self .verify_remove (directory = directory )
@@ -547,11 +539,11 @@ def wait_for_output(child) -> t.Tuple[int, t.Optional[str]]:
547
539
install = pexpect .spawn (self .manage_script , install_command , env = env )
548
540
549
541
while True :
550
- idx , _ = wait_for_output ( install )
551
- if idx < 2 :
542
+ idx = install . expect ( expected )
543
+ if idx < 1 :
552
544
install .sendline ("Y" )
553
545
else :
554
- self .assertEqual (idx , 3 )
546
+ self .assertEqual (idx , 2 )
555
547
break
556
548
557
549
self .verify_install (directory = directory )
@@ -566,12 +558,10 @@ def test_prompt_install(self, env={}, directory: t.Optional[Path] = None):
566
558
** env ,
567
559
}
568
560
569
- rex = re .compile
570
- expected_patterns = [
571
- rex (r"Append the above contents to (?P<file>.*)\?" ), # 0
572
- rex (r"Create (?P<file>.*) with the above contents\?" ), # 1
573
- rex (r"Aborted shell completion installation." ), # 2
574
- rex (rf"Installed autocompletion for { self .shell } " ), # 3
561
+ expected = [
562
+ re .compile (r"\[y/N\]" ), # 0
563
+ re .compile ("Aborted" ), # 1
564
+ re .compile ("Installed" ), # 2
575
565
]
576
566
577
567
install_command = [
@@ -604,7 +594,7 @@ def run_with_response(responses: t.List[str]):
604
594
break
605
595
output += line
606
596
607
- matched_index , matched_file = match_output (line )
597
+ matched_index = match_output (line )
608
598
if matched_index is not None :
609
599
process .stdin .write (response + "\n " )
610
600
process .stdin .flush ()
@@ -613,12 +603,12 @@ def run_with_response(responses: t.List[str]):
613
603
process .wait ()
614
604
return output
615
605
616
- def match_output (line : str ) -> t .Tuple [ t . Optional [int ], t . Optional [ str ] ]:
617
- for i , pattern in enumerate (expected_patterns ):
606
+ def match_output (line : str ) -> t .Optional [int ]:
607
+ for i , pattern in enumerate (expected ):
618
608
match = pattern .search (line )
619
609
if match :
620
- return i , match . groupdict (). get ( "file" )
621
- return None , None
610
+ return i
611
+ return None
622
612
623
613
# Test abort sequence
624
614
abort_output = run_with_response (["N" , "N" ])
0 commit comments