testing/mozbase/mozprocess/tests/test_mozprocess_poll.py

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

     1 #!/usr/bin/env python
     3 import os
     4 import signal
     5 import unittest
     7 import mozinfo
     8 from mozprocess import processhandler
    10 import proctest
    13 here = os.path.dirname(os.path.abspath(__file__))
    16 class ProcTestPoll(proctest.ProcTest):
    17     """ Class to test process poll """
    19     def test_poll_before_run(self):
    20         """Process is not started, and poll() is called"""
    22         p = processhandler.ProcessHandler([self.python, self.proclaunch,
    23                                           "process_normal_finish_python.ini"],
    24                                           cwd=here)
    25         self.assertRaises(AttributeError, p.poll)
    27     def test_poll_while_running(self):
    28         """Process is started, and poll() is called"""
    30         p = processhandler.ProcessHandler([self.python, self.proclaunch,
    31                                           "process_normal_finish_python.ini"],
    32                                           cwd=here)
    33         p.run()
    34         returncode = p.poll()
    36         self.assertEqual(returncode, None)
    38         detected, output = proctest.check_for_process(self.proclaunch)
    39         self.determine_status(detected,
    40                               output,
    41                               returncode,
    42                               p.didTimeout,
    43                               True)
    44         p.kill()
    46     def test_poll_after_kill(self):
    47         """Process is killed, and poll() is called"""
    49         p = processhandler.ProcessHandler([self.python, self.proclaunch,
    50                                           "process_normal_finish_python.ini"],
    51                                           cwd=here)
    52         p.run()
    53         returncode = p.kill()
    55         # We killed the process, so the returncode should be < 0
    56         self.assertLess(returncode, 0)
    57         self.assertEqual(returncode, p.poll())
    59         detected, output = proctest.check_for_process(self.proclaunch)
    60         self.determine_status(detected,
    61                               output,
    62                               returncode,
    63                               p.didTimeout)
    65     def test_poll_after_kill_no_process_group(self):
    66         """Process (no group) is killed, and poll() is called"""
    68         p = processhandler.ProcessHandler([self.python, self.proclaunch,
    69                                           "process_normal_finish_no_process_group.ini"],
    70                                           cwd=here,
    71                                           ignore_children=True
    72                                           )
    73         p.run()
    74         returncode = p.kill()
    76         # We killed the process, so the returncode should be < 0
    77         self.assertLess(returncode, 0)
    78         self.assertEqual(returncode, p.poll())
    80         detected, output = proctest.check_for_process(self.proclaunch)
    81         self.determine_status(detected,
    82                               output,
    83                               returncode,
    84                               p.didTimeout)
    86     def test_poll_after_double_kill(self):
    87         """Process is killed twice, and poll() is called"""
    89         p = processhandler.ProcessHandler([self.python, self.proclaunch,
    90                                           "process_normal_finish_python.ini"],
    91                                           cwd=here)
    92         p.run()
    93         p.kill()
    94         returncode = p.kill()
    96         # We killed the process, so the returncode should be < 0
    97         self.assertLess(returncode, 0)
    98         self.assertEqual(returncode, p.poll())
   100         detected, output = proctest.check_for_process(self.proclaunch)
   101         self.determine_status(detected,
   102                               output,
   103                               returncode,
   104                               p.didTimeout)
   106     def test_poll_after_external_kill(self):
   107         """Process is killed externally, and poll() is called"""
   109         p = processhandler.ProcessHandler([self.python, self.proclaunch,
   110                                           "process_normal_finish_python.ini"],
   111                                           cwd=here)
   112         p.run()
   113         os.kill(p.pid, signal.SIGTERM)
   114         returncode = p.wait()
   116         # We killed the process, so the returncode should be < 0
   117         self.assertEqual(returncode, -signal.SIGTERM)
   118         self.assertEqual(returncode, p.poll())
   120         detected, output = proctest.check_for_process(self.proclaunch)
   121         self.determine_status(detected,
   122                               output,
   123                               returncode,
   124                               p.didTimeout)
   126 if __name__ == '__main__':
   127     unittest.main()

mercurial