testing/mozbase/mozprocess/tests/test_mozprocess_output.py

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 #!/usr/bin/env python
michael@0 2
michael@0 3 import io
michael@0 4 import os
michael@0 5 import unittest
michael@0 6 import proctest
michael@0 7 from mozprocess import processhandler
michael@0 8
michael@0 9 here = os.path.dirname(os.path.abspath(__file__))
michael@0 10
michael@0 11 class ProcTestOutput(proctest.ProcTest):
michael@0 12 """ Class to test operations related to output handling """
michael@0 13
michael@0 14 def test_process_output_nonewline(self):
michael@0 15 """
michael@0 16 Process is started, outputs data with no newline
michael@0 17 """
michael@0 18 p = processhandler.ProcessHandler([self.python, "procnonewline.py"],
michael@0 19 cwd=here)
michael@0 20
michael@0 21 p.run()
michael@0 22 p.processOutput(timeout=5)
michael@0 23 p.wait()
michael@0 24
michael@0 25 detected, output = proctest.check_for_process("procnonewline.py")
michael@0 26 self.determine_status(detected,
michael@0 27 output,
michael@0 28 p.proc.returncode,
michael@0 29 p.didTimeout,
michael@0 30 False,
michael@0 31 ())
michael@0 32
michael@0 33 def test_stream_process_output(self):
michael@0 34 """
michael@0 35 Process output stream does not buffer
michael@0 36 """
michael@0 37 expected = '\n'.join([str(n) for n in range(0,10)])
michael@0 38
michael@0 39 stream = io.BytesIO()
michael@0 40 buf = io.BufferedRandom(stream)
michael@0 41
michael@0 42 p = processhandler.ProcessHandler([self.python, "proccountfive.py"],
michael@0 43 cwd=here,
michael@0 44 stream=buf)
michael@0 45
michael@0 46 p.run()
michael@0 47 p.wait()
michael@0 48 for i in range(5, 10):
michael@0 49 stream.write(str(i)+'\n')
michael@0 50
michael@0 51 buf.flush()
michael@0 52 self.assertEquals(stream.getvalue().strip(), expected)
michael@0 53
michael@0 54 # make sure mozprocess doesn't close the stream
michael@0 55 # since mozprocess didn't create it
michael@0 56 self.assertFalse(buf.closed)
michael@0 57 buf.close()
michael@0 58
michael@0 59 detected, output = proctest.check_for_process("proccountfive.py")
michael@0 60 self.determine_status(detected,
michael@0 61 output,
michael@0 62 p.proc.returncode,
michael@0 63 p.didTimeout,
michael@0 64 False,
michael@0 65 ())
michael@0 66
michael@0 67 if __name__ == '__main__':
michael@0 68 unittest.main()

mercurial