testing/mozbase/mozprocess/tests/test_mozprocess_params.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 # This Source Code Form is subject to the terms of the Mozilla Public
     4 # License, v. 2.0. If a copy of the MPL was not distributed with this file,
     5 # You can obtain one at http://mozilla.org/MPL/2.0/.
     7 import unittest
     8 from mozprocess import processhandler
    10 class ParamTests(unittest.TestCase):
    13     def test_process_outputline_handler(self):
    14         """Parameter processOutputLine is accepted with a single function"""
    15         def output(line):
    16             print("output " + str(line))
    17         err = None
    18         try:
    19             p = processhandler.ProcessHandler(['ls','-l'], processOutputLine=output)
    20         except (TypeError, AttributeError) as e:
    21             err = e
    22         self.assertFalse(err)
    24     def test_process_outputline_handler_list(self):
    25         """Parameter processOutputLine is accepted with a list of functions"""
    26         def output(line):
    27             print("output " + str(line))
    28         err = None
    29         try:
    30             p = processhandler.ProcessHandler(['ls','-l'], processOutputLine=[output])
    31         except (TypeError, AttributeError) as e:
    32             err = e
    33         self.assertFalse(err)
    36     def test_process_ontimeout_handler(self):
    37         """Parameter onTimeout is accepted with a single function"""
    38         def timeout():
    39             print("timeout!")
    40         err = None
    41         try:
    42             p = processhandler.ProcessHandler(['sleep', '2'], onTimeout=timeout)
    43         except (TypeError, AttributeError) as e:
    44             err = e
    45         self.assertFalse(err)
    47     def test_process_ontimeout_handler_list(self):
    48         """Parameter onTimeout is accepted with a list of functions"""
    49         def timeout():
    50             print("timeout!")
    51         err = None
    52         try:
    53             p = processhandler.ProcessHandler(['sleep', '2'], onTimeout=[timeout])
    54         except (TypeError, AttributeError) as e:
    55             err = e
    56         self.assertFalse(err)
    58     def test_process_onfinish_handler(self):
    59         """Parameter onFinish is accepted with a single function"""
    60         def finish():
    61             print("finished!")
    62         err = None
    63         try:
    64             p = processhandler.ProcessHandler(['sleep', '1'], onFinish=finish)
    65         except (TypeError, AttributeError) as e:
    66             err = e
    67         self.assertFalse(err)
    69     def test_process_onfinish_handler_list(self):
    70         """Parameter onFinish is accepted with a list of functions"""
    71         def finish():
    72             print("finished!")
    73         err = None
    74         try:
    75             p = processhandler.ProcessHandler(['sleep', '1'], onFinish=[finish])
    76         except (TypeError, AttributeError) as e:
    77             err = e
    78         self.assertFalse(err)
    81 def main():
    82     unittest.main()
    84 if __name__ == '__main__':
    85     main()

mercurial