@@ -498,15 +498,21 @@ def test_prompt_install(self, env={}, directory: t.Optional[Path] = None):
498
498
env = {
499
499
** dict (os .environ ),
500
500
"DJANGO_SETTINGS_MODULE" : "tests.settings.completion" ,
501
+ "DJANGO_COLORS" : "nocolor" ,
501
502
** env ,
502
503
}
503
504
504
505
rex = re .compile
505
506
expected = [
506
- rex (r"Append the above contents to (?P<file>.*)\?" ), # 0
507
- rex (r"Create (?P<file>.*) with the above contents\?" ), # 1
508
- rex (r"Aborted shell completion installation." ), # 2
509
- rex (rf"Installed autocompletion for { self .shell } " ), # 3
507
+ rex (
508
+ r"Append\s+the\s+above\s+contents\s+to\s+(?P<file>.*)\?" , re .DOTALL
509
+ ), # 0
510
+ rex (
511
+ r"Create\s+(?P<file>.*)\s+with\s+the\s+above\s+contents\?" ,
512
+ re .DOTALL ,
513
+ ), # 1
514
+ rex (r"Aborted\s+shell\s+completion\s+installation." ), # 2
515
+ rex (rf"Installed\s+autocompletion\s+for\s+{ self .shell } " ), # 3
510
516
]
511
517
512
518
install_command = [
@@ -520,6 +526,7 @@ def test_prompt_install(self, env={}, directory: t.Optional[Path] = None):
520
526
self .verify_remove (directory = directory )
521
527
522
528
install = pexpect .spawn (self .manage_script , install_command , env = env )
529
+ install .setwinsize (24 , 800 )
523
530
524
531
def wait_for_output (child ) -> t .Tuple [int , t .Optional [str ]]:
525
532
index = child .expect (expected )
@@ -544,6 +551,7 @@ def wait_for_output(child) -> t.Tuple[int, t.Optional[str]]:
544
551
545
552
# test an install
546
553
install = pexpect .spawn (self .manage_script , install_command , env = env )
554
+ install .setwinsize (24 , 800 )
547
555
548
556
while True :
549
557
idx , _ = wait_for_output (install )
@@ -555,75 +563,76 @@ def wait_for_output(child) -> t.Tuple[int, t.Optional[str]]:
555
563
556
564
self .verify_install (directory = directory )
557
565
558
- else :
559
-
560
- def test_prompt_install (self , env = {}, directory : t .Optional [Path ] = None ):
561
- env = {
562
- ** dict (os .environ ),
563
- "DJANGO_SETTINGS_MODULE" : "tests.settings.completion" ,
564
- ** env ,
565
- }
566
-
567
- rex = re .compile
568
- expected_patterns = [
569
- rex (r"Append the above contents to (?P<file>.*)\?" ), # 0
570
- rex (r"Create (?P<file>.*) with the above contents\?" ), # 1
571
- rex (r"Aborted shell completion installation." ), # 2
572
- rex (rf"Installed autocompletion for { self .shell } " ), # 3
573
- ]
574
-
575
- install_command = [
576
- self .manage_script ,
577
- "shellcompletion" ,
578
- "--no-color" ,
579
- "--shell" ,
580
- self .shell ,
581
- "install" ,
582
- ]
583
- self .remove ()
584
- self .verify_remove (directory = directory )
585
-
586
- def run_with_response (responses : t .List [str ]):
587
- process = subprocess .Popen (
588
- install_command ,
589
- env = env ,
590
- cwd = directory ,
591
- stdin = subprocess .PIPE ,
592
- stdout = subprocess .PIPE ,
593
- stderr = subprocess .STDOUT ,
594
- text = True ,
595
- )
596
-
597
- output = ""
598
- for response in responses :
599
- while True :
600
- line = process .stdout .readline ()
601
- if not line :
602
- break
603
- output += line
604
-
605
- matched_index , matched_file = match_output (line )
606
- if matched_index is not None :
607
- process .stdin .write (response + "\n " )
608
- process .stdin .flush ()
609
- break
610
-
611
- process .wait ()
612
- return output
613
-
614
- def match_output (line : str ) -> t .Tuple [t .Optional [int ], t .Optional [str ]]:
615
- for i , pattern in enumerate (expected_patterns ):
616
- match = pattern .search (line )
617
- if match :
618
- return i , match .groupdict ().get ("file" )
619
- return None , None
620
-
621
- # Test abort sequence
622
- abort_output = run_with_response (["N" , "N" ])
623
- self .assertIn ("Aborted shell completion installation." , abort_output )
624
- self .verify_remove (directory = directory )
625
-
626
- # Test install sequence
627
- install_output = run_with_response (["Y" , "Y" ])
628
- self .assertIn (f"Installed autocompletion for { self .shell } " , install_output )
629
- self .verify_install (directory = directory )
566
+ # else:
567
+
568
+ # def test_prompt_install(self, env={}, directory: t.Optional[Path] = None):
569
+ # env = {
570
+ # **dict(os.environ),
571
+ # "DJANGO_SETTINGS_MODULE": "tests.settings.completion",
572
+ # "DJANGO_COLORS": "nocolor",
573
+ # **env,
574
+ # }
575
+
576
+ # rex = re.compile
577
+ # expected_patterns = [
578
+ # rex(r"Append the above contents to (?P<file>.*)\?"), # 0
579
+ # rex(r"Create (?P<file>.*) with the above contents\?"), # 1
580
+ # rex(r"Aborted shell completion installation."), # 2
581
+ # rex(rf"Installed autocompletion for {self.shell}"), # 3
582
+ # ]
583
+
584
+ # install_command = [
585
+ # self.manage_script,
586
+ # "shellcompletion",
587
+ # "--no-color",
588
+ # "--shell",
589
+ # self.shell,
590
+ # "install",
591
+ # ]
592
+ # self.remove()
593
+ # self.verify_remove(directory=directory)
594
+
595
+ # def run_with_response(responses: t.List[str]):
596
+ # process = subprocess.Popen(
597
+ # install_command,
598
+ # env=env,
599
+ # cwd=directory,
600
+ # stdin=subprocess.PIPE,
601
+ # stdout=subprocess.PIPE,
602
+ # stderr=subprocess.STDOUT,
603
+ # text=True,
604
+ # )
605
+
606
+ # output = ""
607
+ # for response in responses:
608
+ # while True:
609
+ # line = process.stdout.readline()
610
+ # if not line:
611
+ # break
612
+ # output += line
613
+
614
+ # matched_index, matched_file = match_output(line)
615
+ # if matched_index is not None:
616
+ # process.stdin.write(response + "\n")
617
+ # process.stdin.flush()
618
+ # break
619
+
620
+ # process.wait()
621
+ # return output
622
+
623
+ # def match_output(line: str) -> t.Tuple[t.Optional[int], t.Optional[str]]:
624
+ # for i, pattern in enumerate(expected_patterns):
625
+ # match = pattern.search(line)
626
+ # if match:
627
+ # return i, match.groupdict().get("file")
628
+ # return None, None
629
+
630
+ # # Test abort sequence
631
+ # abort_output = run_with_response(["N", "N"])
632
+ # self.assertIn("Aborted shell completion installation.", abort_output)
633
+ # self.verify_remove(directory=directory)
634
+
635
+ # # Test install sequence
636
+ # install_output = run_with_response(["Y", "Y"])
637
+ # self.assertIn(f"Installed autocompletion for {self.shell}", install_output)
638
+ # self.verify_install(directory=directory)
0 commit comments