diff --git a/src/mog_commons/__init__.py b/src/mog_commons/__init__.py index e160d93..dccb61c 100644 --- a/src/mog_commons/__init__.py +++ b/src/mog_commons/__init__.py @@ -1 +1 @@ -__version__ = '0.1.20' +__version__ = '0.1.21' diff --git a/src/mog_commons/terminal.py b/src/mog_commons/terminal.py index 2362675..a13b49a 100644 --- a/src/mog_commons/terminal.py +++ b/src/mog_commons/terminal.py @@ -63,7 +63,7 @@ def __init__(self, term_type=None, encoding=None, @staticmethod def _can_getch_enable(stdin): - if stdin.isatty(): + if hasattr(stdin, 'isatty') and stdin.isatty(): return os.name == 'nt' or hasattr(stdin, 'fileno') return False @@ -125,7 +125,7 @@ def clear(self): """ Clear the terminal screen. """ - if self.stdout.isatty() or self.term_type == 'mintty': + if hasattr(self.stdout, 'isatty') and self.stdout.isatty() or self.term_type == 'mintty': cmd, shell = { 'posix': ('clear', False), 'nt': ('cls', True), @@ -138,7 +138,7 @@ def clear_input_buffer(self): """ Clear the input buffer. """ - if self.stdin.isatty(): + if hasattr(self.stdin, 'isatty') and self.stdin.isatty(): if os.name == 'nt': while msvcrt.kbhit(): msvcrt.getch() diff --git a/tests/mog_commons/test_terminal.py b/tests/mog_commons/test_terminal.py index 26d75d2..bf65aff 100644 --- a/tests/mog_commons/test_terminal.py +++ b/tests/mog_commons/test_terminal.py @@ -9,6 +9,11 @@ class TestTerminal(TestCase): + def test_clear(self): + with self.withAssertOutput('', '') as (out, err): + # assume this should not raise an error + TerminalHandler(stdout=out, stderr=err).clear() + def test_getch_from_file(self): with open(os.path.join('tests', 'resources', 'test_terminal_input.txt')) as f: t = TerminalHandler(stdin=f)