@@ -43,14 +43,15 @@ def run_repl(
43
43
* ,
44
44
cmdline_args : list [str ] | None = None ,
45
45
cwd : str | None = None ,
46
+ skip : bool = False ,
46
47
) -> tuple [str , int ]:
47
48
temp_dir = None
48
49
if cwd is None :
49
50
temp_dir = tempfile .TemporaryDirectory (ignore_cleanup_errors = True )
50
51
cwd = temp_dir .name
51
52
try :
52
53
return self ._run_repl (
53
- repl_input , env = env , cmdline_args = cmdline_args , cwd = cwd
54
+ repl_input , env = env , cmdline_args = cmdline_args , cwd = cwd , skip = skip ,
54
55
)
55
56
finally :
56
57
if temp_dir is not None :
@@ -63,6 +64,7 @@ def _run_repl(
63
64
env : dict | None ,
64
65
cmdline_args : list [str ] | None ,
65
66
cwd : str ,
67
+ skip : bool ,
66
68
) -> tuple [str , int ]:
67
69
assert pty
68
70
master_fd , slave_fd = pty .openpty ()
@@ -119,7 +121,10 @@ def _run_repl(
119
121
except subprocess .TimeoutExpired :
120
122
process .kill ()
121
123
exit_code = process .wait ()
122
- return "" .join (output ), exit_code
124
+ output = "" .join (output )
125
+ if skip and "can't use pyrepl" in output :
126
+ self .skipTest ("pyrepl not available" )
127
+ return output , exit_code
123
128
124
129
125
130
class TestCursorPosition (TestCase ):
@@ -1082,9 +1087,7 @@ def setUp(self):
1082
1087
def test_exposed_globals_in_repl (self ):
1083
1088
pre = "['__annotations__', '__builtins__'"
1084
1089
post = "'__loader__', '__name__', '__package__', '__spec__']"
1085
- output , exit_code = self .run_repl (["sorted(dir())" , "exit()" ])
1086
- if "can't use pyrepl" in output :
1087
- self .skipTest ("pyrepl not available" )
1090
+ output , exit_code = self .run_repl (["sorted(dir())" , "exit()" ], skip = True )
1088
1091
self .assertEqual (exit_code , 0 )
1089
1092
1090
1093
# if `__main__` is not a file (impossible with pyrepl)
@@ -1136,20 +1139,19 @@ def _run_repl_globals_test(self, expectations, *, as_file=False, as_module=False
1136
1139
commands ,
1137
1140
cmdline_args = [str (mod )],
1138
1141
env = clean_env ,
1142
+ skip = True ,
1139
1143
)
1140
1144
elif as_module :
1141
1145
output , exit_code = self .run_repl (
1142
1146
commands ,
1143
1147
cmdline_args = ["-m" , "blue.calx" ],
1144
1148
env = clean_env ,
1145
1149
cwd = td ,
1150
+ skip = True ,
1146
1151
)
1147
1152
else :
1148
1153
self .fail ("Choose one of as_file or as_module" )
1149
1154
1150
- if "can't use pyrepl" in output :
1151
- self .skipTest ("pyrepl not available" )
1152
-
1153
1155
self .assertEqual (exit_code , 0 )
1154
1156
for var , expected in expectations .items ():
1155
1157
with self .subTest (var = var , expected = expected ):
@@ -1187,9 +1189,7 @@ def test_python_basic_repl(self):
1187
1189
"exit()\n " )
1188
1190
1189
1191
env .pop ("PYTHON_BASIC_REPL" , None )
1190
- output , exit_code = self .run_repl (commands , env = env )
1191
- if "can\' t use pyrepl" in output :
1192
- self .skipTest ("pyrepl not available" )
1192
+ output , exit_code = self .run_repl (commands , env = env , skip = True )
1193
1193
self .assertEqual (exit_code , 0 )
1194
1194
self .assertIn ("True" , output )
1195
1195
self .assertNotIn ("False" , output )
@@ -1256,9 +1256,7 @@ def check(output, exitcode):
1256
1256
self .assertIn ("division by zero" , output )
1257
1257
self .assertEqual (exitcode , 0 )
1258
1258
env .pop ("PYTHON_BASIC_REPL" , None )
1259
- output , exit_code = self .run_repl (commands , env = env )
1260
- if "can\' t use pyrepl" in output :
1261
- self .skipTest ("pyrepl not available" )
1259
+ output , exit_code = self .run_repl (commands , env = env , skip = True )
1262
1260
check (output , exit_code )
1263
1261
1264
1262
env ["PYTHON_BASIC_REPL" ] = "1"
@@ -1296,9 +1294,7 @@ def test_not_wiping_history_file(self):
1296
1294
def test_correct_filename_in_syntaxerrors (self ):
1297
1295
env = os .environ .copy ()
1298
1296
commands = "a b c\n exit()\n "
1299
- output , exit_code = self .run_repl (commands , env = env )
1300
- if "can't use pyrepl" in output :
1301
- self .skipTest ("pyrepl not available" )
1297
+ output , exit_code = self .run_repl (commands , env = env , skip = True )
1302
1298
self .assertIn ("SyntaxError: invalid syntax" , output )
1303
1299
self .assertIn ("<python-input-0>" , output )
1304
1300
commands = " b\n exit()\n "
@@ -1325,9 +1321,7 @@ def test_proper_tracebacklimit(self):
1325
1321
env .pop ("PYTHON_BASIC_REPL" , None )
1326
1322
with self .subTest (set_tracebacklimit = set_tracebacklimit ,
1327
1323
basic_repl = basic_repl ):
1328
- output , exit_code = self .run_repl (commands , env = env )
1329
- if "can't use pyrepl" in output :
1330
- self .skipTest ("pyrepl not available" )
1324
+ output , exit_code = self .run_repl (commands , env = env , skip = True )
1331
1325
self .assertIn ("in x1" , output )
1332
1326
if set_tracebacklimit :
1333
1327
self .assertNotIn ("in x2" , output )
0 commit comments