|
11 | 11 | import sys |
12 | 12 | import tempfile |
13 | 13 | from pkgutil import ModuleInfo |
14 | | -from unittest import TestCase, skipUnless, skipIf, SkipTest |
| 14 | +from unittest import TestCase, skipUnless, SkipTest |
15 | 15 | from unittest.mock import Mock, patch |
16 | 16 | from test.support import force_not_colorized, make_clean_env, Py_DEBUG |
17 | 17 | from test.support import has_subprocess_support, SHORT_TIMEOUT, STDLIB_DIR |
|
27 | 27 | multiline_input, |
28 | 28 | code_to_events, |
29 | 29 | ) |
| 30 | +from _pyrepl import terminfo |
30 | 31 | from _pyrepl.console import Event |
31 | 32 | from _pyrepl._module_completer import ( |
32 | 33 | ImportParser, |
@@ -1530,8 +1531,20 @@ def test_dumb_terminal_exits_cleanly(self): |
1530 | 1531 | self.assertNotIn("Traceback", output) |
1531 | 1532 |
|
1532 | 1533 |
|
| 1534 | +def supports_pyrepl(): |
| 1535 | + # pyrepl falls back to the basic REPL if the terminal lacks any of the |
| 1536 | + # capabilities which UnixConsole requires. This covers an unset or |
| 1537 | + # "dumb" TERM as well, they are resolved to the "dumb" capabilities. |
| 1538 | + try: |
| 1539 | + info = terminfo.TermInfo(None) |
| 1540 | + except Exception: |
| 1541 | + return False |
| 1542 | + return all(info.get(cap) is not None |
| 1543 | + for cap in ("bel", "clear", "cup", "el")) |
| 1544 | + |
| 1545 | + |
1533 | 1546 | @skipUnless(pty, "requires pty") |
1534 | | -@skipIf((os.environ.get("TERM") or "dumb") == "dumb", "can't use pyrepl in dumb terminal") |
| 1547 | +@skipUnless(supports_pyrepl(), "can't use pyrepl in this terminal") |
1535 | 1548 | class TestMain(ReplTestCase): |
1536 | 1549 | def setUp(self): |
1537 | 1550 | # Cleanup from PYTHON* variables to isolate from local |
|
0 commit comments