tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

test_params.py (2728B)


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