Skip to content

Commit 5c8d1a2

Browse files
committed
try fix prompt install tests
1 parent e47f73b commit 5c8d1a2

File tree

1 file changed

+20
-30
lines changed

1 file changed

+20
-30
lines changed

tests/shellcompletion/__init__.py

Lines changed: 20 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -502,12 +502,10 @@ def test_prompt_install(self, env={}, directory: t.Optional[Path] = None):
502502
**env,
503503
}
504504

505-
rex = re.compile
506505
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
511509
]
512510

513511
install_command = [
@@ -522,23 +520,17 @@ def test_prompt_install(self, env={}, directory: t.Optional[Path] = None):
522520

523521
install = pexpect.spawn(self.manage_script, install_command, env=env)
524522

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-
531523
# test an abort
532-
idx, _ = wait_for_output(install)
533-
self.assertLess(idx, 2)
524+
idx = install.expect(expected)
525+
self.assertEqual(idx, 0)
534526
install.sendline("N")
535527

536528
while True:
537-
idx, _ = wait_for_output(install)
538-
if idx < 2:
529+
idx = install.expect(expected)
530+
if idx == 0:
539531
install.sendline("N")
540532
else:
541-
self.assertEqual(idx, 2)
533+
self.assertEqual(idx, 1)
542534
break
543535

544536
self.verify_remove(directory=directory)
@@ -547,11 +539,11 @@ def wait_for_output(child) -> t.Tuple[int, t.Optional[str]]:
547539
install = pexpect.spawn(self.manage_script, install_command, env=env)
548540

549541
while True:
550-
idx, _ = wait_for_output(install)
551-
if idx < 2:
542+
idx = install.expect(expected)
543+
if idx < 1:
552544
install.sendline("Y")
553545
else:
554-
self.assertEqual(idx, 3)
546+
self.assertEqual(idx, 2)
555547
break
556548

557549
self.verify_install(directory=directory)
@@ -566,12 +558,10 @@ def test_prompt_install(self, env={}, directory: t.Optional[Path] = None):
566558
**env,
567559
}
568560

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
575565
]
576566

577567
install_command = [
@@ -604,7 +594,7 @@ def run_with_response(responses: t.List[str]):
604594
break
605595
output += line
606596

607-
matched_index, matched_file = match_output(line)
597+
matched_index = match_output(line)
608598
if matched_index is not None:
609599
process.stdin.write(response + "\n")
610600
process.stdin.flush()
@@ -613,12 +603,12 @@ def run_with_response(responses: t.List[str]):
613603
process.wait()
614604
return output
615605

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):
618608
match = pattern.search(line)
619609
if match:
620-
return i, match.groupdict().get("file")
621-
return None, None
610+
return i
611+
return None
622612

623613
# Test abort sequence
624614
abort_output = run_with_response(["N", "N"])

0 commit comments

Comments
 (0)