Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(36)

Side by Side Diff: native_client_sdk/src/tools/tests/httpd_test.py

Issue 720233003: [NaCl SDK] Convert python scripts from optparse to argparse. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. 2 # Copyright (c) 2012 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be 3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file. 4 # found in the LICENSE file.
5 5
6 import os 6 import os
7 import Queue 7 import Queue
8 import sys 8 import sys
9 import subprocess 9 import subprocess
10 import threading 10 import threading
(...skipping 29 matching lines...) Expand all
40 if self.process and self.process.returncode is None: 40 if self.process and self.process.returncode is None:
41 self.process.kill() 41 self.process.kill()
42 42
43 @staticmethod 43 @staticmethod
44 def _SubprocessThread(process, queue): 44 def _SubprocessThread(process, queue):
45 stdout, stderr = process.communicate() 45 stdout, stderr = process.communicate()
46 queue.put((process.returncode, stdout, stderr)) 46 queue.put((process.returncode, stdout, stderr))
47 47
48 def _Run(self, args=None, timeout=None): 48 def _Run(self, args=None, timeout=None):
49 args = args or [] 49 args = args or []
50 run_py = os.path.join(PARENT_DIR, 'run.py') 50 cmd = [sys.executable, os.path.join(PARENT_DIR, 'run.py')]
binji 2014/11/13 23:57:05 seems unrelated
Sam Clegg 2014/11/30 17:55:14 Done.
51 cmd = [sys.executable, run_py]
52 cmd.extend(args) 51 cmd.extend(args)
53 self.process = subprocess.Popen(cmd, stdout=subprocess.PIPE, 52 self.process = subprocess.Popen(cmd, stdout=subprocess.PIPE,
54 stderr=subprocess.PIPE) 53 stderr=subprocess.PIPE)
55 queue = Queue.Queue() 54 queue = Queue.Queue()
56 thread = threading.Thread(target=RunTest._SubprocessThread, 55 thread = threading.Thread(target=RunTest._SubprocessThread,
57 args=(self.process, queue)) 56 args=(self.process, queue))
58 thread.daemon = True 57 thread.daemon = True
59 thread.start() 58 thread.start()
60 thread.join(timeout) 59 thread.join(timeout)
61 if not thread.is_alive(): 60 if not thread.is_alive():
(...skipping 12 matching lines...) Expand all
74 if http_request_type: 73 if http_request_type:
75 args.append('--' + http_request_type) 74 args.append('--' + http_request_type)
76 if sleep: 75 if sleep:
77 args.extend(['--sleep', str(sleep)]) 76 args.extend(['--sleep', str(sleep)])
78 if expect_to_be_killed: 77 if expect_to_be_killed:
79 args.append('--expect-to-be-killed') 78 args.append('--expect-to-be-killed')
80 return args 79 return args
81 80
82 def testQuit(self): 81 def testQuit(self):
83 args = self._GetChromeMockArgs('?quit=1', 'get', sleep=10) 82 args = self._GetChromeMockArgs('?quit=1', 'get', sleep=10)
84 _, stdout, _ = self._Run(args, timeout=20) 83 rtn, stdout, _ = self._Run(args, timeout=20)
85 self.assertTrue('Starting' in stdout) 84 self.assertEqual(rtn, 0)
86 self.assertTrue('Expected to be killed' not in stdout) 85 self.assertIn('Starting', stdout)
86 self.assertNotIn('Expected to be killed', stdout)
87 87
88 def testSubprocessDies(self): 88 def testSubprocessDies(self):
89 args = self._GetChromeMockArgs(page=None, http_request_type=None, sleep=0, 89 args = self._GetChromeMockArgs(page=None, http_request_type=None, sleep=0,
90 expect_to_be_killed=False) 90 expect_to_be_killed=False)
91 returncode, stdout, _ = self._Run(args, timeout=10) 91 returncode, stdout, _ = self._Run(args, timeout=10)
92 self.assertNotEqual(-1, returncode) 92 self.assertNotEqual(-1, returncode)
93 self.assertTrue('Starting' in stdout) 93 self.assertIn('Starting', stdout)
94 94
95 95
96 if __name__ == '__main__': 96 if __name__ == '__main__':
97 unittest.main() 97 unittest.main()
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698