This test looks really weird, use sys.stdin.fileno() instead of the fd of a temporary file.