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
7from __future__ import absolute_import, print_function
8
9import unittest
10
11import mozunit
12
13from mozprocess import processhandler
14
15
16class ParamTests(unittest.TestCase):
17    def test_process_outputline_handler(self):
18        """Parameter processOutputLine is accepted with a single function"""
19
20        def output(line):
21            print("output " + str(line))
22
23        err = None
24        try:
25            processhandler.ProcessHandler(["ls", "-l"], processOutputLine=output)
26        except (TypeError, AttributeError) as e:
27            err = e
28        self.assertFalse(err)
29
30    def test_process_outputline_handler_list(self):
31        """Parameter processOutputLine is accepted with a list of functions"""
32
33        def output(line):
34            print("output " + str(line))
35
36        err = None
37        try:
38            processhandler.ProcessHandler(["ls", "-l"], processOutputLine=[output])
39        except (TypeError, AttributeError) as e:
40            err = e
41        self.assertFalse(err)
42
43    def test_process_ontimeout_handler(self):
44        """Parameter onTimeout is accepted with a single function"""
45
46        def timeout():
47            print("timeout!")
48
49        err = None
50        try:
51            processhandler.ProcessHandler(["sleep", "2"], onTimeout=timeout)
52        except (TypeError, AttributeError) as e:
53            err = e
54        self.assertFalse(err)
55
56    def test_process_ontimeout_handler_list(self):
57        """Parameter onTimeout is accepted with a list of functions"""
58
59        def timeout():
60            print("timeout!")
61
62        err = None
63        try:
64            processhandler.ProcessHandler(["sleep", "2"], onTimeout=[timeout])
65        except (TypeError, AttributeError) as e:
66            err = e
67        self.assertFalse(err)
68
69    def test_process_onfinish_handler(self):
70        """Parameter onFinish is accepted with a single function"""
71
72        def finish():
73            print("finished!")
74
75        err = None
76        try:
77            processhandler.ProcessHandler(["sleep", "1"], onFinish=finish)
78        except (TypeError, AttributeError) as e:
79            err = e
80        self.assertFalse(err)
81
82    def test_process_onfinish_handler_list(self):
83        """Parameter onFinish is accepted with a list of functions"""
84
85        def finish():
86            print("finished!")
87
88        err = None
89        try:
90            processhandler.ProcessHandler(["sleep", "1"], onFinish=[finish])
91        except (TypeError, AttributeError) as e:
92            err = e
93        self.assertFalse(err)
94
95
96if __name__ == "__main__":
97    mozunit.main()
98