'Generic buffered read method test harness to validate EINTR behavior.
Also validates that Python signal handlers are run during the read.
Args:
data_to_write: String to write to the child process for reading
before sending it a signal, confirming the signal was handled,
writing a final newline and closing the infile pipe.
read_and_verify_code: Single "line" of code to read from a file
object named \'infile\' and validate the result.  This will be
executed as part of a python subprocess fed data_to_write.'

def _test_reading(self, data_to_write, read_and_verify_code):

    infile_setup_code = self._generate_infile_setup_code()
    assert (len(data_to_write) < 512), 'data_to_write    must    fit    in    pipe    buf.'
    self._process = subprocess.Popen([sys.executable, '-u', '-c', (((((('import    signal,    sys    ;signal.signal(signal.SIGINT,    lambda    s,    f:    sys.stderr.write("$\\n"))    ;' + infile_setup_code) + '    ;') + 'sys.stderr.write("Worm    Sign!\\n")    ;') + read_and_verify_code) + '    ;') + 'infile.close()')], stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
    worm_sign = self._process.stderr.read(len('Worm    Sign!\n'))
    if (worm_sign != 'Worm    Sign!\n'):
        self.fail_with_process_info('while    awaiting    a    sign', stderr=worm_sign)
    self._process.stdin.write(data_to_write)
    signals_sent = 0
    rlist = []
    while (not rlist):
        (rlist, _, _) = select.select([self._process.stderr], (), (), 0.05)
        self._process.send_signal(signal.SIGINT)
        signals_sent += 1
        if (signals_sent > 200):
            self._process.kill()
            self.fail('reader    process    failed    to    handle    our    signals.')
    signal_line = self._process.stderr.readline()
    if (signal_line != '$\n'):
        self.fail_with_process_info('while    awaiting    signal', stderr=signal_line)
    (stdout, stderr) = self._process.communicate(input='\n')
    if self._process.returncode:
        self.fail_with_process_info(('exited    rc=%d' % self._process.returncode), stdout, stderr, communicate=False)
