testing/mozbase/mozprocess/tests/test_mozprocess_output.py

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

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

mercurial