summaryrefslogtreecommitdiffstats
path: root/testing/mozbase/mozprocess/tests/test_output.py
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-28 14:29:10 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-28 14:29:10 +0000
commit2aa4a82499d4becd2284cdb482213d541b8804dd (patch)
treeb80bf8bf13c3766139fbacc530efd0dd9d54394c /testing/mozbase/mozprocess/tests/test_output.py
parentInitial commit. (diff)
downloadfirefox-2aa4a82499d4becd2284cdb482213d541b8804dd.tar.xz
firefox-2aa4a82499d4becd2284cdb482213d541b8804dd.zip
Adding upstream version 86.0.1.upstream/86.0.1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'testing/mozbase/mozprocess/tests/test_output.py')
-rw-r--r--testing/mozbase/mozprocess/tests/test_output.py78
1 files changed, 78 insertions, 0 deletions
diff --git a/testing/mozbase/mozprocess/tests/test_output.py b/testing/mozbase/mozprocess/tests/test_output.py
new file mode 100644
index 0000000000..d93c1a254b
--- /dev/null
+++ b/testing/mozbase/mozprocess/tests/test_output.py
@@ -0,0 +1,78 @@
+#!/usr/bin/env python
+
+from __future__ import absolute_import
+
+import io
+import os
+
+import mozunit
+import proctest
+from mozprocess import processhandler
+
+here = os.path.dirname(os.path.abspath(__file__))
+
+
+class ProcTestOutput(proctest.ProcTest):
+ """ Class to test operations related to output handling """
+
+ def test_process_output_twice(self):
+ """
+ Process is started, then processOutput is called a second time explicitly
+ """
+ p = processhandler.ProcessHandler(
+ [self.python, self.proclaunch, "process_waittimeout_10s.ini"], cwd=here
+ )
+
+ p.run()
+ p.processOutput(timeout=5)
+ p.wait()
+
+ self.determine_status(p, False, ())
+
+ def test_process_output_nonewline(self):
+ """
+ Process is started, outputs data with no newline
+ """
+ p = processhandler.ProcessHandler(
+ [self.python, os.path.join("scripts", "procnonewline.py")], cwd=here
+ )
+
+ p.run()
+ p.processOutput(timeout=5)
+ p.wait()
+
+ self.determine_status(p, False, ())
+
+ def test_stream_process_output(self):
+ """
+ Process output stream does not buffer
+ """
+ expected = "\n".join([str(n) for n in range(0, 10)])
+
+ stream = io.BytesIO()
+ buf = io.BufferedRandom(stream)
+
+ p = processhandler.ProcessHandler(
+ [self.python, os.path.join("scripts", "proccountfive.py")],
+ cwd=here,
+ stream=buf,
+ )
+
+ p.run()
+ p.wait()
+ for i in range(5, 10):
+ stream.write(str(i).encode("utf8") + "\n".encode("utf8"))
+
+ buf.flush()
+ self.assertEquals(stream.getvalue().strip().decode("utf8"), expected)
+
+ # make sure mozprocess doesn't close the stream
+ # since mozprocess didn't create it
+ self.assertFalse(buf.closed)
+ buf.close()
+
+ self.determine_status(p, False, ())
+
+
+if __name__ == "__main__":
+ mozunit.main()