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

Side by Side Diff: tests/subprocess2_test.py

Issue 8508017: Standardize the sys.path fix up and fix a few pylint warnings. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/tools/depot_tools
Patch Set: rebase against HEAD Created 9 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 | Annotate | Revision Log
OLDNEW
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 # Copyright (c) 2011 The Chromium Authors. All rights reserved. 2 # Copyright (c) 2011 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 """Unit tests for subprocess2.py.""" 6 """Unit tests for subprocess2.py."""
7 7
8 import logging 8 import logging
9 import optparse 9 import optparse
10 import os 10 import os
11 import sys 11 import sys
12 import time 12 import time
13 import unittest 13 import unittest
14 14
15 try: 15 try:
16 import fcntl 16 import fcntl
17 except ImportError: 17 except ImportError:
18 fcntl = None 18 fcntl = None
19 19
20 ROOT_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) 20 sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
21 sys.path.insert(0, ROOT_DIR)
22 21
23 import subprocess2 22 import subprocess2
24 23
25 # Method could be a function
26 # pylint: disable=R0201
27
28 24
29 def convert_to_crlf(string): 25 def convert_to_crlf(string):
30 """Unconditionally convert LF to CRLF.""" 26 """Unconditionally convert LF to CRLF."""
31 return string.replace('\n', '\r\n') 27 return string.replace('\n', '\r\n')
32 28
33 29
34 def convert_to_cr(string): 30 def convert_to_cr(string):
35 """Unconditionally convert LF to CR.""" 31 """Unconditionally convert LF to CR."""
36 return string.replace('\n', '\r') 32 return string.replace('\n', '\r')
37 33
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
77 73
78 @staticmethod 74 @staticmethod
79 def _fake_Popen(): 75 def _fake_Popen():
80 results = {} 76 results = {}
81 class fake_Popen(object): 77 class fake_Popen(object):
82 returncode = -8 78 returncode = -8
83 def __init__(self, args, **kwargs): 79 def __init__(self, args, **kwargs):
84 assert not results 80 assert not results
85 results.update(kwargs) 81 results.update(kwargs)
86 results['args'] = args 82 results['args'] = args
87 def communicate(self): 83 @staticmethod
84 def communicate():
88 return None, None 85 return None, None
89 subprocess2.Popen = fake_Popen 86 subprocess2.Popen = fake_Popen
90 return results 87 return results
91 88
92 @staticmethod 89 @staticmethod
93 def _fake_subprocess_Popen(): 90 def _fake_subprocess_Popen():
94 results = {} 91 results = {}
95 class fake_Popen(object): 92 class fake_Popen(object):
96 returncode = -8 93 returncode = -8
97 def __init__(self, args, **kwargs): 94 def __init__(self, args, **kwargs):
98 assert not results 95 assert not results
99 results.update(kwargs) 96 results.update(kwargs)
100 results['args'] = args 97 results['args'] = args
101 def communicate(self): 98 @staticmethod
99 def communicate():
102 return None, None 100 return None, None
103 subprocess2.subprocess.Popen = fake_Popen 101 subprocess2.subprocess.Popen = fake_Popen
104 return results 102 return results
105 103
106 def test_check_call_defaults(self): 104 def test_check_call_defaults(self):
107 results = self._fake_communicate() 105 results = self._fake_communicate()
108 self.assertEquals( 106 self.assertEquals(
109 ['stdout', 'stderr'], subprocess2.check_call_out(['foo'], a=True)) 107 ['stdout', 'stderr'], subprocess2.check_call_out(['foo'], a=True))
110 expected = { 108 expected = {
111 'args': ['foo'], 109 'args': ['foo'],
(...skipping 338 matching lines...) Expand 10 before | Expand all | Expand 10 after
450 return options.return_value 448 return options.return_value
451 449
452 450
453 if __name__ == '__main__': 451 if __name__ == '__main__':
454 logging.basicConfig(level= 452 logging.basicConfig(level=
455 [logging.WARNING, logging.INFO, logging.DEBUG][ 453 [logging.WARNING, logging.INFO, logging.DEBUG][
456 min(2, sys.argv.count('-v'))]) 454 min(2, sys.argv.count('-v'))])
457 if len(sys.argv) > 1 and sys.argv[1] == '--child': 455 if len(sys.argv) > 1 and sys.argv[1] == '--child':
458 sys.exit(child_main(sys.argv[2:])) 456 sys.exit(child_main(sys.argv[2:]))
459 unittest.main() 457 unittest.main()
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698