1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/testing/mozbase/mozprocess/tests/test_mozprocess_params.py Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,86 @@ 1.4 +#!/usr/bin/env python 1.5 + 1.6 +# This Source Code Form is subject to the terms of the Mozilla Public 1.7 +# License, v. 2.0. If a copy of the MPL was not distributed with this file, 1.8 +# You can obtain one at http://mozilla.org/MPL/2.0/. 1.9 + 1.10 +import unittest 1.11 +from mozprocess import processhandler 1.12 + 1.13 +class ParamTests(unittest.TestCase): 1.14 + 1.15 + 1.16 + def test_process_outputline_handler(self): 1.17 + """Parameter processOutputLine is accepted with a single function""" 1.18 + def output(line): 1.19 + print("output " + str(line)) 1.20 + err = None 1.21 + try: 1.22 + p = processhandler.ProcessHandler(['ls','-l'], processOutputLine=output) 1.23 + except (TypeError, AttributeError) as e: 1.24 + err = e 1.25 + self.assertFalse(err) 1.26 + 1.27 + def test_process_outputline_handler_list(self): 1.28 + """Parameter processOutputLine is accepted with a list of functions""" 1.29 + def output(line): 1.30 + print("output " + str(line)) 1.31 + err = None 1.32 + try: 1.33 + p = processhandler.ProcessHandler(['ls','-l'], processOutputLine=[output]) 1.34 + except (TypeError, AttributeError) as e: 1.35 + err = e 1.36 + self.assertFalse(err) 1.37 + 1.38 + 1.39 + def test_process_ontimeout_handler(self): 1.40 + """Parameter onTimeout is accepted with a single function""" 1.41 + def timeout(): 1.42 + print("timeout!") 1.43 + err = None 1.44 + try: 1.45 + p = processhandler.ProcessHandler(['sleep', '2'], onTimeout=timeout) 1.46 + except (TypeError, AttributeError) as e: 1.47 + err = e 1.48 + self.assertFalse(err) 1.49 + 1.50 + def test_process_ontimeout_handler_list(self): 1.51 + """Parameter onTimeout is accepted with a list of functions""" 1.52 + def timeout(): 1.53 + print("timeout!") 1.54 + err = None 1.55 + try: 1.56 + p = processhandler.ProcessHandler(['sleep', '2'], onTimeout=[timeout]) 1.57 + except (TypeError, AttributeError) as e: 1.58 + err = e 1.59 + self.assertFalse(err) 1.60 + 1.61 + def test_process_onfinish_handler(self): 1.62 + """Parameter onFinish is accepted with a single function""" 1.63 + def finish(): 1.64 + print("finished!") 1.65 + err = None 1.66 + try: 1.67 + p = processhandler.ProcessHandler(['sleep', '1'], onFinish=finish) 1.68 + except (TypeError, AttributeError) as e: 1.69 + err = e 1.70 + self.assertFalse(err) 1.71 + 1.72 + def test_process_onfinish_handler_list(self): 1.73 + """Parameter onFinish is accepted with a list of functions""" 1.74 + def finish(): 1.75 + print("finished!") 1.76 + err = None 1.77 + try: 1.78 + p = processhandler.ProcessHandler(['sleep', '1'], onFinish=[finish]) 1.79 + except (TypeError, AttributeError) as e: 1.80 + err = e 1.81 + self.assertFalse(err) 1.82 + 1.83 + 1.84 +def main(): 1.85 + unittest.main() 1.86 + 1.87 +if __name__ == '__main__': 1.88 + main() 1.89 +