michael@0: #!/usr/bin/env python michael@0: michael@0: # This Source Code Form is subject to the terms of the Mozilla Public michael@0: # License, v. 2.0. If a copy of the MPL was not distributed with this file, michael@0: # You can obtain one at http://mozilla.org/MPL/2.0/. michael@0: michael@0: import unittest michael@0: from mozprocess import processhandler michael@0: michael@0: class ParamTests(unittest.TestCase): michael@0: michael@0: michael@0: def test_process_outputline_handler(self): michael@0: """Parameter processOutputLine is accepted with a single function""" michael@0: def output(line): michael@0: print("output " + str(line)) michael@0: err = None michael@0: try: michael@0: p = processhandler.ProcessHandler(['ls','-l'], processOutputLine=output) michael@0: except (TypeError, AttributeError) as e: michael@0: err = e michael@0: self.assertFalse(err) michael@0: michael@0: def test_process_outputline_handler_list(self): michael@0: """Parameter processOutputLine is accepted with a list of functions""" michael@0: def output(line): michael@0: print("output " + str(line)) michael@0: err = None michael@0: try: michael@0: p = processhandler.ProcessHandler(['ls','-l'], processOutputLine=[output]) michael@0: except (TypeError, AttributeError) as e: michael@0: err = e michael@0: self.assertFalse(err) michael@0: michael@0: michael@0: def test_process_ontimeout_handler(self): michael@0: """Parameter onTimeout is accepted with a single function""" michael@0: def timeout(): michael@0: print("timeout!") michael@0: err = None michael@0: try: michael@0: p = processhandler.ProcessHandler(['sleep', '2'], onTimeout=timeout) michael@0: except (TypeError, AttributeError) as e: michael@0: err = e michael@0: self.assertFalse(err) michael@0: michael@0: def test_process_ontimeout_handler_list(self): michael@0: """Parameter onTimeout is accepted with a list of functions""" michael@0: def timeout(): michael@0: print("timeout!") michael@0: err = None michael@0: try: michael@0: p = processhandler.ProcessHandler(['sleep', '2'], onTimeout=[timeout]) michael@0: except (TypeError, AttributeError) as e: michael@0: err = e michael@0: self.assertFalse(err) michael@0: michael@0: def test_process_onfinish_handler(self): michael@0: """Parameter onFinish is accepted with a single function""" michael@0: def finish(): michael@0: print("finished!") michael@0: err = None michael@0: try: michael@0: p = processhandler.ProcessHandler(['sleep', '1'], onFinish=finish) michael@0: except (TypeError, AttributeError) as e: michael@0: err = e michael@0: self.assertFalse(err) michael@0: michael@0: def test_process_onfinish_handler_list(self): michael@0: """Parameter onFinish is accepted with a list of functions""" michael@0: def finish(): michael@0: print("finished!") michael@0: err = None michael@0: try: michael@0: p = processhandler.ProcessHandler(['sleep', '1'], onFinish=[finish]) michael@0: except (TypeError, AttributeError) as e: michael@0: err = e michael@0: self.assertFalse(err) michael@0: michael@0: michael@0: def main(): michael@0: unittest.main() michael@0: michael@0: if __name__ == '__main__': michael@0: main() michael@0: