@@ -501,78 +501,94 @@ def test_multi_install(self):
501
501
finally :
502
502
self .remove_script (script = manage2 )
503
503
504
- if platform .system () != "Windows" :
505
-
506
- def test_prompt_install (self , env = {}, directory : t .Optional [Path ] = None ):
507
- import pexpect
508
-
509
- env = {
510
- ** dict (os .environ ),
511
- "DJANGO_SETTINGS_MODULE" : "tests.settings.completion" ,
512
- "DJANGO_COLORS" : "nocolor" ,
513
- ** env ,
514
- }
515
-
516
- rex = re .compile
517
- expected = [
518
- rex (
519
- r"Append\s+the\s+above\s+contents\s+to\s+(?P<file>.*)\?" , re .DOTALL
520
- ), # 0
521
- rex (
522
- r"Create\s+(?P<file>.*)\s+with\s+the\s+above\s+contents\?" ,
523
- re .DOTALL ,
524
- ), # 1
525
- rex (r"Aborted\s+shell\s+completion\s+installation." ), # 2
526
- rex (rf"Installed\s+autocompletion\s+for\s+{ self .shell } " ), # 3
527
- ]
528
-
529
- install_command = [
530
- "shellcompletion" ,
531
- "--no-color" ,
532
- "--shell" ,
533
- self .shell ,
534
- "install" ,
535
- ]
536
- self .remove ()
537
- self .verify_remove (directory = directory )
504
+ def test_prompt_install (self , env = {}, directory : t .Optional [Path ] = None ):
505
+ import pexpect
506
+
507
+ env = {
508
+ ** dict (os .environ ),
509
+ "DJANGO_SETTINGS_MODULE" : "tests.settings.completion" ,
510
+ "DJANGO_COLORS" : "nocolor" ,
511
+ ** env ,
512
+ }
513
+
514
+ rex = re .compile
515
+ expected = [
516
+ rex (
517
+ r"Append\s+the\s+above\s+contents\s+to\s+(?P<file>.*)\?" , re .DOTALL
518
+ ), # 0
519
+ rex (
520
+ r"Create\s+(?P<file>.*)\s+with\s+the\s+above\s+contents\?" ,
521
+ re .DOTALL ,
522
+ ), # 1
523
+ rex (r"Aborted\s+shell\s+completion\s+installation." ), # 2
524
+ rex (rf"Installed\s+autocompletion\s+for\s+{ self .shell } " ), # 3
525
+ ]
526
+
527
+ install_command = [
528
+ "shellcompletion" ,
529
+ "--no-color" ,
530
+ "--shell" ,
531
+ self .shell ,
532
+ "install" ,
533
+ ]
534
+ self .remove ()
535
+ self .verify_remove (directory = directory )
538
536
537
+ if platform .system () != "Windows" :
539
538
install = pexpect .spawn (self .manage_script , install_command , env = env )
540
539
install .setwinsize (24 , 800 )
540
+ else :
541
+ from pexpect .popen_spawn import PopenSpawn
541
542
542
- def wait_for_output ( child ) -> t . Tuple [ int , t . Optional [ str ]]:
543
- index = child . expect ( expected )
544
- if index in [ 0 , 1 ]:
545
- return index , child . match . group ( "file" ). decode ()
546
- return index , None
543
+ install = PopenSpawn (
544
+ " " . join ([ self . manage_script , * install_command ]),
545
+ env = env ,
546
+ encoding = "utf-8" ,
547
+ )
547
548
548
- # test an abort
549
- idx , _ = wait_for_output (install )
550
- self .assertLess (idx , 2 )
551
- install .sendline ("N" )
549
+ def wait_for_output (child ) -> t .Tuple [int , t .Optional [str ]]:
550
+ index = child .expect (expected )
551
+ if index in [0 , 1 ]:
552
+ return index , child .match .group ("file" )
553
+ return index , None
552
554
553
- while True :
554
- idx , _ = wait_for_output (install )
555
- if idx < 2 :
556
- install .sendline ("N" )
557
- else :
558
- self .assertEqual (idx , 2 )
559
- break
555
+ # test an abort
556
+ idx , _ = wait_for_output (install )
557
+ self .assertLess (idx , 2 )
558
+ install .sendline ("N" )
560
559
561
- self .verify_remove (directory = directory )
560
+ while True :
561
+ idx , _ = wait_for_output (install )
562
+ if idx < 2 :
563
+ install .sendline ("N" )
564
+ else :
565
+ self .assertEqual (idx , 2 )
566
+ break
562
567
563
- # test an install
568
+ self .verify_remove (directory = directory )
569
+
570
+ # test an install
571
+ if platform .system () != "Windows" :
564
572
install = pexpect .spawn (self .manage_script , install_command , env = env )
565
573
install .setwinsize (24 , 800 )
574
+ else :
575
+ from pexpect .popen_spawn import PopenSpawn
576
+
577
+ install = PopenSpawn (
578
+ " " .join ([self .manage_script , * install_command ]),
579
+ env = env ,
580
+ encoding = "utf-8" ,
581
+ )
566
582
567
- while True :
568
- idx , _ = wait_for_output (install )
569
- if idx < 2 :
570
- install .sendline ("Y" )
571
- else :
572
- self .assertEqual (idx , 3 )
573
- break
583
+ while True :
584
+ idx , _ = wait_for_output (install )
585
+ if idx < 2 :
586
+ install .sendline ("Y" )
587
+ else :
588
+ self .assertEqual (idx , 3 )
589
+ break
574
590
575
- self .verify_install (directory = directory )
591
+ self .verify_install (directory = directory )
576
592
577
593
# TODO
578
594
# else:
0 commit comments