def test_stdsim_line_buffering(base_app): # This exercises the case of writing binary data that contains new lines/carriage returns to a StdSim # when line buffering is on. The output should immediately be flushed to the underlying stream. import os import tempfile file = tempfile.NamedTemporaryFile(mode='wt') file.line_buffering = True stdsim = cu.StdSim(file, echo=True) saved_size = os.path.getsize(file.name) bytes_to_write = b'hello\n' stdsim.buffer.write(bytes_to_write) assert os.path.getsize(file.name) == saved_size + len(bytes_to_write) saved_size = os.path.getsize(file.name) bytes_to_write = b'hello\r' stdsim.buffer.write(bytes_to_write) assert os.path.getsize(file.name) == saved_size + len(bytes_to_write)
def stringio_sim(): import io stdsim = cu.StdSim(io.StringIO(), echo=True) return stdsim
def stdout_sim(): stdsim = cu.StdSim(sys.stdout) return stdsim
def sc_app(): c = SubcommandsExample() c.stdout = utils.StdSim(c.stdout) return c
def stdout_sim(): stdsim = cu.StdSim(sys.stdout, echo=True) return stdsim