From 5a25372a0a21c610c10906cc7a6e93bbab85d294 Mon Sep 17 00:00:00 2001 From: Daniel Hahler Date: Fri, 25 Oct 2019 07:21:14 +0200 Subject: [PATCH] improve, add test --- pyrepl/unix_console.py | 5 ++--- testing/test_unix_console.py | 12 ++++++++++++ 2 files changed, 14 insertions(+), 3 deletions(-) create mode 100644 testing/test_unix_console.py diff --git a/pyrepl/unix_console.py b/pyrepl/unix_console.py index 99aeb8c..a462b2e 100644 --- a/pyrepl/unix_console.py +++ b/pyrepl/unix_console.py @@ -356,9 +356,8 @@ def prepare(self): # per-readline preparations: try: self.__svtermstate = tcgetattr(self.input_fd) - except termios.error: # (25, 'Inappropriate ioctl for device') - # assert not os.fdopen(self.input_fd).isatty() - raise EOFError + except termios.error as exc: + raise EOFError("could not prepare fd %d: %s" % (self.input_fd, exc)) self._prepared = True raw = self.__svtermstate.copy() raw.iflag |= termios.ICRNL diff --git a/testing/test_unix_console.py b/testing/test_unix_console.py new file mode 100644 index 0000000..51bf874 --- /dev/null +++ b/testing/test_unix_console.py @@ -0,0 +1,12 @@ +import pytest + + +def test_eoferror(): + from pyrepl.unix_console import UnixConsole + + console = UnixConsole(f_in=99) + with pytest.raises( + EOFError, + match="^could not prepare fd 99: .*Bad file descriptor" + ): + console.prepare()