buildframework/helium/sf/python/pythoncore/lib/pythoncorecpythontests/test_timeout_launcher.py
equal
deleted
inserted
replaced
16 # |
16 # |
17 #Description: |
17 #Description: |
18 #=============================================================================== |
18 #=============================================================================== |
19 """ unit tests the timeout launcher """ |
19 """ unit tests the timeout launcher """ |
20 |
20 |
21 # pylint: disable-msg=E1101 |
21 # pylint: disable=E1101 |
22 |
22 |
23 import logging |
23 import logging |
24 import sys |
24 import sys |
25 import mocker |
25 import mocker |
26 import subprocess |
26 import subprocess |
36 import win32con |
36 import win32con |
37 import win32api |
37 import win32api |
38 WINDOWS = True |
38 WINDOWS = True |
39 |
39 |
40 |
40 |
41 # pylint: disable-msg=C0103 |
41 # pylint: disable=C0103 |
42 |
42 |
43 class os(object): #has to be named this as it is mocking os method. |
43 class os(object): #has to be named this as it is mocking os method. |
44 """ dummy the os function call""" |
44 """ dummy the os function call""" |
45 |
45 |
46 def kill(self, pid, value): |
46 def kill(self, pid, value): |
62 self.mocker.replay() |
62 self.mocker.replay() |
63 |
63 |
64 sys.argv = ['timeout_launcher.py', '--timeout=1', 'version'] |
64 sys.argv = ['timeout_launcher.py', '--timeout=1', 'version'] |
65 timeout_launcher.main() |
65 timeout_launcher.main() |
66 |
66 |
67 # pylint: disable-msg=W0104 |
67 # pylint: disable=W0104 |
68 |
68 |
69 def test_valid_with_timeout(self): |
69 def test_valid_with_timeout(self): |
70 """test_valid_with_timeout: initial test with valid values and timeout.""" |
70 """test_valid_with_timeout: initial test with valid values and timeout.""" |
71 import timeout_launcher |
71 import timeout_launcher |
72 cmdline = ['dir'] |
72 cmdline = ['dir'] |
102 import timeout_launcher |
102 import timeout_launcher |
103 cmdline = ['dir'] |
103 cmdline = ['dir'] |
104 process = self.mocker.mock() |
104 process = self.mocker.mock() |
105 |
105 |
106 obj = self.mocker.replace("subprocess.Popen") |
106 obj = self.mocker.replace("subprocess.Popen") |
107 obj(' '.join(cmdline), stdout=subprocess.PIPE, stderr=subprocess.STDOUT, shell=True) |
107 shell = True |
|
108 if WINDOWS: |
|
109 shell = False |
|
110 obj(' '.join(cmdline), stdout=subprocess.PIPE, stderr=subprocess.STDOUT, shell=shell) |
108 self.mocker.result(process) |
111 self.mocker.result(process) |
109 |
112 |
110 process.communicate()[0] |
113 process.communicate()[0] |
111 self.mocker.result(None) |
114 self.mocker.result(None) |
112 process.returncode |
115 process.returncode |
170 |
173 |
171 sys.argv = ['--timeout=3', '--', ' '.join(cmdline)] |
174 sys.argv = ['--timeout=3', '--', ' '.join(cmdline)] |
172 failed = False |
175 failed = False |
173 try: |
176 try: |
174 timeout_launcher.main() |
177 timeout_launcher.main() |
175 except: |
178 except Exception: |
176 failed = True |
179 failed = True |
177 assert failed |
180 assert failed |