File: util.py

package info (click to toggle)
reptyr 0.9.0-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, trixie
  • size: 328 kB
  • sloc: ansic: 2,576; python: 76; makefile: 62; sh: 46
file content (17 lines) | stat: -rw-r--r-- 453 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
import os
import errno
import select

def expect_eof(fd):
  r, _, _ = select.select([fd], [], [])
  if fd not in r:
    raise AssertionError("Expected EOF, fd not readable")
  try:
    data = os.read(fd, 1024)
    if len(data) == 0:
      return
    raise AssertionError("Expected EOF, got read: `{}'".format(data))
  except OSError as e:
    if e.errno == errno.EIO:
      return
    raise AssertionError("Expected EOF, other exception: {}".format(e))