testing/mozbase/mozprocess/tests/test_mozprocess_params.py

branch
TOR_BUG_9701
changeset 15
b8a032363ba2
equal deleted inserted replaced
-1:000000000000 0:006d0000c483
1 #!/usr/bin/env python
2
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/.
6
7 import unittest
8 from mozprocess import processhandler
9
10 class ParamTests(unittest.TestCase):
11
12
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)
23
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)
34
35
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)
46
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)
57
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)
68
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)
79
80
81 def main():
82 unittest.main()
83
84 if __name__ == '__main__':
85 main()
86

mercurial