|
13 | 13 | import tempfile |
14 | 14 | from functools import partial |
15 | 15 | from pkgutil import ModuleInfo |
16 | | -from unittest import TestCase, skipUnless, skipIf, SkipTest |
| 16 | +from unittest import TestCase, skipUnless, SkipTest |
17 | 17 | from unittest.mock import Mock, patch |
18 | 18 | import warnings |
19 | 19 | from test.support import ( |
|
37 | 37 | code_to_events, |
38 | 38 | ) |
39 | 39 | from _colorize import ANSIColors, get_theme |
| 40 | +from _pyrepl import terminfo |
40 | 41 | from _pyrepl.console import Event |
41 | 42 | from _pyrepl.completing_reader import stripcolor |
42 | 43 | from _pyrepl._module_completer import ( |
@@ -1998,8 +1999,20 @@ def test_dumb_terminal_exits_cleanly(self): |
1998 | 1999 | self.assertNotIn("Traceback", output) |
1999 | 2000 |
|
2000 | 2001 |
|
| 2002 | +def supports_pyrepl(): |
| 2003 | + # pyrepl falls back to the basic REPL if the terminal lacks any of the |
| 2004 | + # capabilities which UnixConsole requires. This covers an unset or |
| 2005 | + # "dumb" TERM as well, they are resolved to the "dumb" capabilities. |
| 2006 | + try: |
| 2007 | + info = terminfo.TermInfo(None) |
| 2008 | + except Exception: |
| 2009 | + return False |
| 2010 | + return all(info.get(cap) is not None |
| 2011 | + for cap in ("bel", "clear", "cup", "el")) |
| 2012 | + |
| 2013 | + |
2001 | 2014 | @skipUnless(pty, "requires pty") |
2002 | | -@skipIf((os.environ.get("TERM") or "dumb") == "dumb", "can't use pyrepl in dumb terminal") |
| 2015 | +@skipUnless(supports_pyrepl(), "can't use pyrepl in this terminal") |
2003 | 2016 | class TestMain(ReplTestCase): |
2004 | 2017 | def setUp(self): |
2005 | 2018 | # Cleanup from PYTHON* variables to isolate from local |
|
0 commit comments