6
6
import select
7
7
import subprocess
8
8
import sys
9
- from unittest import TestCase
9
+ from unittest import TestCase , skipUnless
10
10
from unittest .mock import patch
11
11
from test .support import force_not_colorized
12
12
22
22
from _pyrepl .readline import ReadlineAlikeReader , ReadlineConfig
23
23
from _pyrepl .readline import multiline_input as readline_multiline_input
24
24
25
+ try :
26
+ import pty
27
+ except ImportError :
28
+ pty = None
25
29
26
30
class TestCursorPosition (TestCase ):
27
31
def prepare_reader (self , events ):
@@ -835,16 +839,16 @@ def test_bracketed_paste_single_line(self):
835
839
self .assertEqual (output , input_code )
836
840
837
841
842
+ @skipUnless (pty , "requires pty" )
838
843
class TestMain (TestCase ):
839
844
@force_not_colorized
840
845
def test_exposed_globals_in_repl (self ):
841
846
expected_output = (
842
- '[" __annotations__", " __builtins__", " __doc__", " __loader__", '
843
- '" __name__", " __package__", " __spec__"]'
847
+ "[ \' __annotations__\' , \' __builtins__\' , \' __doc__\' , \' __loader__\' , "
848
+ " \' __name__\' , \' __package__\' , \' __spec__\' ]"
844
849
)
845
850
output , exit_code = self .run_repl (["sorted(dir())" , "exit" ])
846
851
self .assertEqual (exit_code , 0 )
847
- output = output .replace ("\' " , '"' )
848
852
self .assertIn (expected_output , output )
849
853
850
854
def test_dumb_terminal_exits_cleanly (self ):
@@ -857,10 +861,6 @@ def test_dumb_terminal_exits_cleanly(self):
857
861
self .assertNotIn ("Traceback" , output )
858
862
859
863
def run_repl (self , repl_input : str | list [str ], env : dict | None = None ) -> tuple [str , int ]:
860
- try :
861
- import pty
862
- except ImportError :
863
- self .skipTest ("pty module not available" )
864
864
master_fd , slave_fd = pty .openpty ()
865
865
process = subprocess .Popen (
866
866
[sys .executable , "-i" , "-u" ],
0 commit comments