"Fossies" - the Fresh Open Source Software Archive

Member "reptyr-reptyr-0.8.0/test/util.py" (29 Sep 2020, 453 Bytes) of package /linux/privat/reptyr-reptyr-0.8.0.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Python source code syntax highlighting (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file.

    1 import os
    2 import errno
    3 import select
    4 
    5 def expect_eof(fd):
    6   r, _, _ = select.select([fd], [], [])
    7   if fd not in r:
    8     raise AssertionError("Expected EOF, fd not readable")
    9   try:
   10     data = os.read(fd, 1024)
   11     if len(data) == 0:
   12       return
   13     raise AssertionError("Expected EOF, got read: `{}'".format(data))
   14   except OSError as e:
   15     if e.errno == errno.EIO:
   16       return
   17     raise AssertionError("Expected EOF, other expection: {}".format(e))