@@ -44,14 +44,15 @@ def run_repl(
44
44
* ,
45
45
cmdline_args : list [str ] | None = None ,
46
46
cwd : str | None = None ,
47
+ skip : bool = False ,
47
48
) -> tuple [str , int ]:
48
49
temp_dir = None
49
50
if cwd is None :
50
51
temp_dir = tempfile .TemporaryDirectory (ignore_cleanup_errors = True )
51
52
cwd = temp_dir .name
52
53
try :
53
54
return self ._run_repl (
54
- repl_input , env = env , cmdline_args = cmdline_args , cwd = cwd
55
+ repl_input , env = env , cmdline_args = cmdline_args , cwd = cwd , skip = skip ,
55
56
)
56
57
finally :
57
58
if temp_dir is not None :
@@ -64,6 +65,7 @@ def _run_repl(
64
65
env : dict | None ,
65
66
cmdline_args : list [str ] | None ,
66
67
cwd : str ,
68
+ skip : bool ,
67
69
) -> tuple [str , int ]:
68
70
assert pty
69
71
master_fd , slave_fd = pty .openpty ()
@@ -121,7 +123,10 @@ def _run_repl(
121
123
except subprocess .TimeoutExpired :
122
124
process .kill ()
123
125
exit_code = process .wait ()
124
- return "" .join (output ), exit_code
126
+ output = "" .join (output )
127
+ if skip and "can't use pyrepl" in output :
128
+ self .skipTest ("pyrepl not available" )
129
+ return output , exit_code
125
130
126
131
127
132
class TestCursorPosition (TestCase ):
@@ -1282,9 +1287,7 @@ def setUp(self):
1282
1287
def test_exposed_globals_in_repl (self ):
1283
1288
pre = "['__builtins__'"
1284
1289
post = "'__loader__', '__name__', '__package__', '__spec__']"
1285
- output , exit_code = self .run_repl (["sorted(dir())" , "exit()" ])
1286
- if "can't use pyrepl" in output :
1287
- self .skipTest ("pyrepl not available" )
1290
+ output , exit_code = self .run_repl (["sorted(dir())" , "exit()" ], skip = True )
1288
1291
self .assertEqual (exit_code , 0 )
1289
1292
1290
1293
# if `__main__` is not a file (impossible with pyrepl)
@@ -1336,20 +1339,19 @@ def _run_repl_globals_test(self, expectations, *, as_file=False, as_module=False
1336
1339
commands ,
1337
1340
cmdline_args = [str (mod )],
1338
1341
env = clean_env ,
1342
+ skip = True ,
1339
1343
)
1340
1344
elif as_module :
1341
1345
output , exit_code = self .run_repl (
1342
1346
commands ,
1343
1347
cmdline_args = ["-m" , "blue.calx" ],
1344
1348
env = clean_env ,
1345
1349
cwd = td ,
1350
+ skip = True ,
1346
1351
)
1347
1352
else :
1348
1353
self .fail ("Choose one of as_file or as_module" )
1349
1354
1350
- if "can't use pyrepl" in output :
1351
- self .skipTest ("pyrepl not available" )
1352
-
1353
1355
self .assertEqual (exit_code , 0 )
1354
1356
for var , expected in expectations .items ():
1355
1357
with self .subTest (var = var , expected = expected ):
@@ -1387,9 +1389,7 @@ def test_python_basic_repl(self):
1387
1389
"exit()\n " )
1388
1390
1389
1391
env .pop ("PYTHON_BASIC_REPL" , None )
1390
- output , exit_code = self .run_repl (commands , env = env )
1391
- if "can\' t use pyrepl" in output :
1392
- self .skipTest ("pyrepl not available" )
1392
+ output , exit_code = self .run_repl (commands , env = env , skip = True )
1393
1393
self .assertEqual (exit_code , 0 )
1394
1394
self .assertIn ("True" , output )
1395
1395
self .assertNotIn ("False" , output )
@@ -1456,9 +1456,7 @@ def check(output, exitcode):
1456
1456
self .assertIn ("division by zero" , output )
1457
1457
self .assertEqual (exitcode , 0 )
1458
1458
env .pop ("PYTHON_BASIC_REPL" , None )
1459
- output , exit_code = self .run_repl (commands , env = env )
1460
- if "can\' t use pyrepl" in output :
1461
- self .skipTest ("pyrepl not available" )
1459
+ output , exit_code = self .run_repl (commands , env = env , skip = True )
1462
1460
check (output , exit_code )
1463
1461
1464
1462
env ["PYTHON_BASIC_REPL" ] = "1"
@@ -1496,9 +1494,7 @@ def test_not_wiping_history_file(self):
1496
1494
def test_correct_filename_in_syntaxerrors (self ):
1497
1495
env = os .environ .copy ()
1498
1496
commands = "a b c\n exit()\n "
1499
- output , exit_code = self .run_repl (commands , env = env )
1500
- if "can't use pyrepl" in output :
1501
- self .skipTest ("pyrepl not available" )
1497
+ output , exit_code = self .run_repl (commands , env = env , skip = True )
1502
1498
self .assertIn ("SyntaxError: invalid syntax" , output )
1503
1499
self .assertIn ("<python-input-0>" , output )
1504
1500
commands = " b\n exit()\n "
@@ -1525,9 +1521,7 @@ def test_proper_tracebacklimit(self):
1525
1521
env .pop ("PYTHON_BASIC_REPL" , None )
1526
1522
with self .subTest (set_tracebacklimit = set_tracebacklimit ,
1527
1523
basic_repl = basic_repl ):
1528
- output , exit_code = self .run_repl (commands , env = env )
1529
- if "can't use pyrepl" in output :
1530
- self .skipTest ("pyrepl not available" )
1524
+ output , exit_code = self .run_repl (commands , env = env , skip = True )
1531
1525
self .assertIn ("in x1" , output )
1532
1526
if set_tracebacklimit :
1533
1527
self .assertNotIn ("in x2" , output )
@@ -1568,9 +1562,7 @@ def test_readline_history_file(self):
1568
1562
def test_history_survive_crash (self ):
1569
1563
env = os .environ .copy ()
1570
1564
commands = "1\n exit()\n "
1571
- output , exit_code = self .run_repl (commands , env = env )
1572
- if "can't use pyrepl" in output :
1573
- self .skipTest ("pyrepl not available" )
1565
+ output , exit_code = self .run_repl (commands , env = env , skip = True )
1574
1566
1575
1567
with tempfile .NamedTemporaryFile () as hfile :
1576
1568
env ["PYTHON_HISTORY" ] = hfile .name
0 commit comments