@@ -45,14 +45,20 @@ def run_repl(
4545 cmdline_args : list [str ] | None = None ,
4646 cwd : str | None = None ,
4747 skip : bool = False ,
48+ timeout : float = SHORT_TIMEOUT ,
4849 ) -> tuple [str , int ]:
4950 temp_dir = None
5051 if cwd is None :
5152 temp_dir = tempfile .TemporaryDirectory (ignore_cleanup_errors = True )
5253 cwd = temp_dir .name
5354 try :
5455 return self ._run_repl (
55- repl_input , env = env , cmdline_args = cmdline_args , cwd = cwd , skip = skip ,
56+ repl_input ,
57+ env = env ,
58+ cmdline_args = cmdline_args ,
59+ cwd = cwd ,
60+ skip = skip ,
61+ timeout = timeout ,
5662 )
5763 finally :
5864 if temp_dir is not None :
@@ -66,6 +72,7 @@ def _run_repl(
6672 cmdline_args : list [str ] | None ,
6773 cwd : str ,
6874 skip : bool ,
75+ timeout : float ,
6976 ) -> tuple [str , int ]:
7077 assert pty
7178 master_fd , slave_fd = pty .openpty ()
@@ -103,7 +110,7 @@ def _run_repl(
103110 os .write (master_fd , repl_input .encode ("utf-8" ))
104111
105112 output = []
106- while select .select ([master_fd ], [], [], SHORT_TIMEOUT )[0 ]:
113+ while select .select ([master_fd ], [], [], timeout )[0 ]:
107114 try :
108115 data = os .read (master_fd , 1024 ).decode ("utf-8" )
109116 if not data :
@@ -114,12 +121,12 @@ def _run_repl(
114121 else :
115122 os .close (master_fd )
116123 process .kill ()
117- process .wait (timeout = SHORT_TIMEOUT )
124+ process .wait (timeout = timeout )
118125 self .fail (f"Timeout while waiting for output, got: { '' .join (output )} " )
119126
120127 os .close (master_fd )
121128 try :
122- exit_code = process .wait (timeout = SHORT_TIMEOUT )
129+ exit_code = process .wait (timeout = timeout )
123130 except subprocess .TimeoutExpired :
124131 process .kill ()
125132 exit_code = process .wait ()
@@ -1561,25 +1568,29 @@ def test_readline_history_file(self):
15611568
15621569 def test_history_survive_crash (self ):
15631570 env = os .environ .copy ()
1564- commands = "1\n exit()\n "
1565- output , exit_code = self .run_repl (commands , env = env , skip = True )
15661571
15671572 with tempfile .NamedTemporaryFile () as hfile :
15681573 env ["PYTHON_HISTORY" ] = hfile .name
1569- commands = "spam\n import time\n time.sleep(1000)\n preved\n "
1574+
1575+ commands = "1\n 2\n 3\n exit()\n "
1576+ output , exit_code = self .run_repl (commands , env = env , skip = True )
1577+
1578+ commands = "spam\n import time\n time.sleep(1000)\n quit\n "
15701579 try :
1571- self .run_repl (commands , env = env )
1580+ self .run_repl (commands , env = env , timeout = 3 )
15721581 except AssertionError :
15731582 pass
15741583
15751584 history = pathlib .Path (hfile .name ).read_text ()
1585+ self .assertIn ("2" , history )
1586+ self .assertIn ("exit()" , history )
15761587 self .assertIn ("spam" , history )
1577- self .assertIn ("time" , history )
1588+ self .assertIn ("import time" , history )
15781589 self .assertNotIn ("sleep" , history )
1579- self .assertNotIn ("preved " , history )
1590+ self .assertNotIn ("quit " , history )
15801591
15811592 def test_keyboard_interrupt_after_isearch (self ):
1582- output , exit_code = self .run_repl ([ "\x12 " , " \x03 " , "exit" ] )
1593+ output , exit_code = self .run_repl ("\x12 \x03 exit \n " )
15831594 self .assertEqual (exit_code , 0 )
15841595
15851596 def test_prompt_after_help (self ):
0 commit comments