test_start.py (1422B)
1 #!/usr/bin/env python 2 3 from time import sleep 4 from unittest.mock import patch 5 6 import mozunit 7 from mozrunner import RunnerNotStartedError 8 from pytest import raises 9 10 11 def test_start_process(runner): 12 """Start the process and test properties""" 13 assert runner.process_handler is None 14 15 runner.start() 16 17 assert runner.is_running() 18 assert runner.process_handler is not None 19 20 21 def test_start_process_called_twice(runner): 22 """Start the process twice and test that first process is gone""" 23 runner.start() 24 # Bug 925480 25 # Make a copy until mozprocess can kill a specific process 26 process_handler = runner.process_handler 27 28 runner.start() 29 30 try: 31 assert process_handler.wait(1) not in [None, 0] 32 finally: 33 process_handler.kill() 34 35 36 def test_start_with_timeout(runner): 37 """Start the process and set a timeout""" 38 runner.start(timeout=0.1) 39 sleep(1) 40 41 assert not runner.is_running() 42 43 44 def test_start_with_outputTimeout(runner): 45 """Start the process and set a timeout""" 46 runner.start(outputTimeout=0.1) 47 sleep(1) 48 49 assert not runner.is_running() 50 51 52 def test_fail_to_start(runner): 53 with patch("mozprocess.ProcessHandler.__init__") as ph_mock: 54 ph_mock.side_effect = Exception("Boom!") 55 with raises(RunnerNotStartedError): 56 runner.start(outputTimeout=0.1) 57 sleep(1) 58 59 60 if __name__ == "__main__": 61 mozunit.main()