Beispiel #1
0
def test_long_output():
    """
    Test that output thread in the Command class captures all of the output.
    (and also it does not hang the command by filling up the pipe)

    By default stderr is redirected to stdout.
    """
    # in bytes, should be enough to fill a pipe
    num_lines = 5000
    line_length = 1000
    num_bytes = num_lines * (line_length + 1)
    with tempfile.NamedTemporaryFile() as file:
        for _ in range(num_lines):
            file.write(b'A' * line_length)
            file.write(b'\n')
        file.flush()
        assert os.path.getsize(file.name) == num_bytes

        cmd = Command(["/bin/cat", file.name])
        cmd.execute()

        assert cmd.getstate() == Command.FINISHED
        assert cmd.getretcode() == 0
        assert cmd.geterroutput() is None
        assert len("".join(cmd.getoutput())) == num_bytes
Beispiel #2
0
 def test_stderr(self):
     cmd = Command(["/bin/cat", "/foo/bar", "/etc/passwd"],
                   redirect_stderr=False)
     cmd.execute()
     self.assertEqual(Command.FINISHED, cmd.getstate())
     self.assertNotEqual(0, cmd.getretcode())
     # The error could contain localized output strings so check just
     # for the path itself.
     self.assertTrue("/foo/bar" in "\n".join(cmd.geterroutput()))
     self.assertFalse("/foo/bar" in "\n".join(cmd.getoutput()))
     self.assertTrue("root" in "\n".join(cmd.getoutput()))
Beispiel #3
0
def test_stderr():
    cmd = Command(["/bin/cat", "/foo/bar", "/etc/passwd"],
                  redirect_stderr=False)
    cmd.execute()
    assert cmd.getstate() == Command.FINISHED
    assert cmd.getretcode() != 0
    # The error could contain localized output strings so check just
    # for the path itself.
    assert '/foo/bar' in "\n".join(cmd.geterroutput())
    assert '/foo/bar' not in "\n".join(cmd.getoutput())
    assert 'root' in "\n".join(cmd.getoutput())
Beispiel #4
0
def test_stderr():
    cmd = Command(["/bin/cat", "/foo/bar", "/etc/passwd"],
                  redirect_stderr=False)
    cmd.execute()
    assert cmd.getstate() == Command.FINISHED
    assert cmd.getretcode() != 0
    # The error could contain localized output strings so check just
    # for the path itself.
    assert '/foo/bar' in "\n".join(cmd.geterroutput())
    assert '/foo/bar' not in "\n".join(cmd.getoutput())
    assert 'root' in "\n".join(cmd.getoutput())