Exemple #1
0
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)
Exemple #2
0
def stringio_sim():
    import io
    stdsim = cu.StdSim(io.StringIO(), echo=True)
    return stdsim
Exemple #3
0
def stdout_sim():
    stdsim = cu.StdSim(sys.stdout)
    return stdsim
Exemple #4
0
def sc_app():
    c = SubcommandsExample()
    c.stdout = utils.StdSim(c.stdout)
    return c
Exemple #5
0
def stdout_sim():
    stdsim = cu.StdSim(sys.stdout, echo=True)
    return stdsim