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

Side by Side Diff: third_party/WebKit/Tools/Scripts/webkitpy/common/system/executive_unittest.py

Issue 2248653002: Revert of Fix pylint warnings in webkitpy/common/. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Manual Revert (Patch Set 1 causes patch failure in read_checksum_from_png_unittest.py) Created 4 years, 4 months 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 # Copyright (C) 2010 Google Inc. All rights reserved. 1 # Copyright (C) 2010 Google Inc. All rights reserved.
2 # Copyright (C) 2009 Daniel Bates (dbates@intudata.com). All rights reserved. 2 # Copyright (C) 2009 Daniel Bates (dbates@intudata.com). All rights reserved.
3 # 3 #
4 # Redistribution and use in source and binary forms, with or without 4 # Redistribution and use in source and binary forms, with or without
5 # modification, are permitted provided that the following conditions are 5 # modification, are permitted provided that the following conditions are
6 # met: 6 # met:
7 # 7 #
8 # * Redistributions of source code must retain the above copyright 8 # * Redistributions of source code must retain the above copyright
9 # notice, this list of conditions and the following disclaimer. 9 # notice, this list of conditions and the following disclaimer.
10 # * Redistributions in binary form must reproduce the above 10 # * Redistributions in binary form must reproduce the above
(...skipping 10 matching lines...) Expand all
21 # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 21 # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22 # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 23 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 29
30 import os 30 import os
31 import errno
32 import signal
31 import subprocess 33 import subprocess
32 import sys 34 import sys
33 import unittest 35 import unittest
34 36
35 # Since we execute this script directly as part of the unit tests, we need to en sure 37 # Since we execute this script directly as part of the unit tests, we need to en sure
36 # that Tools/Scripts is in sys.path for the next imports to work correctly. 38 # that Tools/Scripts is in sys.path for the next imports to work correctly.
37 SCRIPT_DIR = os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(os. path.abspath(__file__))))) 39 script_dir = os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(os. path.abspath(__file__)))))
38 if SCRIPT_DIR not in sys.path: 40 if script_dir not in sys.path:
39 sys.path.append(SCRIPT_DIR) 41 sys.path.append(script_dir)
42
40 43
41 from webkitpy.common.system.executive import Executive, ScriptError 44 from webkitpy.common.system.executive import Executive, ScriptError
42 from webkitpy.common.system.filesystem_mock import MockFileSystem 45 from webkitpy.common.system.filesystem_mock import MockFileSystem
43 46
44 47
45 class ScriptErrorTest(unittest.TestCase): 48 class ScriptErrorTest(unittest.TestCase):
46 49
47 def test_message_with_output(self): 50 def test_message_with_output(self):
48 error = ScriptError('My custom message!', '', -1) 51 error = ScriptError('My custom message!', '', -1)
49 self.assertEqual(error.message_with_output(), 'My custom message!') 52 self.assertEqual(error.message_with_output(), 'My custom message!')
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
133 encoded_tor = unicode_tor_input.encode(encoding) 136 encoded_tor = unicode_tor_input.encode(encoding)
134 # On Windows, we expect the unicode->mbcs->unicode roundtrip to be 137 # On Windows, we expect the unicode->mbcs->unicode roundtrip to be
135 # lossy. On other platforms, we expect a lossless roundtrip. 138 # lossy. On other platforms, we expect a lossless roundtrip.
136 if sys.platform == 'win32': 139 if sys.platform == 'win32':
137 unicode_tor_output = encoded_tor.decode(encoding) 140 unicode_tor_output = encoded_tor.decode(encoding)
138 else: 141 else:
139 unicode_tor_output = unicode_tor_input 142 unicode_tor_output = unicode_tor_input
140 143
141 executive = Executive() 144 executive = Executive()
142 145
143 output = executive.run_command(command_line('cat'), input_func=unicode_t or_input) 146 output = executive.run_command(command_line('cat'), input=unicode_tor_in put)
144 self.assertEqual(output, unicode_tor_output) 147 self.assertEqual(output, unicode_tor_output)
145 148
146 output = executive.run_command(command_line('echo', unicode_tor_input)) 149 output = executive.run_command(command_line('echo', unicode_tor_input))
147 self.assertEqual(output, unicode_tor_output) 150 self.assertEqual(output, unicode_tor_output)
148 151
149 output = executive.run_command(command_line('echo', unicode_tor_input), decode_output=False) 152 output = executive.run_command(command_line('echo', unicode_tor_input), decode_output=False)
150 self.assertEqual(output, encoded_tor) 153 self.assertEqual(output, encoded_tor)
151 154
152 # Make sure that str() input also works. 155 # Make sure that str() input also works.
153 output = executive.run_command(command_line('cat'), input_func=encoded_t or, decode_output=False) 156 output = executive.run_command(command_line('cat'), input=encoded_tor, d ecode_output=False)
154 self.assertEqual(output, encoded_tor) 157 self.assertEqual(output, encoded_tor)
155 158
156 def test_kill_process(self): 159 def test_kill_process(self):
157 executive = Executive() 160 executive = Executive()
158 process = subprocess.Popen(never_ending_command(), stdout=subprocess.PIP E) 161 process = subprocess.Popen(never_ending_command(), stdout=subprocess.PIP E)
159 self.assertEqual(process.poll(), None) # Process is running 162 self.assertEqual(process.poll(), None) # Process is running
160 executive.kill_process(process.pid) 163 executive.kill_process(process.pid)
161 164
162 # Killing again should fail silently. 165 # Killing again should fail silently.
163 executive.kill_process(process.pid) 166 executive.kill_process(process.pid)
(...skipping 22 matching lines...) Expand all
186 executive = Executive() 189 executive = Executive()
187 pids = executive.running_pids() 190 pids = executive.running_pids()
188 self.assertIn(os.getpid(), pids) 191 self.assertIn(os.getpid(), pids)
189 192
190 def test_run_in_parallel_assert_nonempty(self): 193 def test_run_in_parallel_assert_nonempty(self):
191 self.assertRaises(AssertionError, Executive().run_in_parallel, []) 194 self.assertRaises(AssertionError, Executive().run_in_parallel, [])
192 195
193 196
194 def main(platform, stdin, stdout, cmd, args): 197 def main(platform, stdin, stdout, cmd, args):
195 if platform == 'win32' and hasattr(stdout, 'fileno'): 198 if platform == 'win32' and hasattr(stdout, 'fileno'):
196 # The module msvcrt and os.O_BINARY are not available on non-Windows. 199 import msvcrt
197 import msvcrt # pylint: disable=import-error 200 msvcrt.setmode(stdout.fileno(), os.O_BINARY)
198 msvcrt.setmode(stdout.fileno(), os.O_BINARY) # pylint: disable=no-membe r
199 if cmd == '--cat': 201 if cmd == '--cat':
200 stdout.write(stdin.read()) 202 stdout.write(stdin.read())
201 elif cmd == '--echo': 203 elif cmd == '--echo':
202 stdout.write(' '.join(args)) 204 stdout.write(' '.join(args))
203 return 0 205 return 0
204 206
205 if __name__ == '__main__' and len(sys.argv) > 1 and sys.argv[1] in ('--cat', '-- echo'): 207 if __name__ == '__main__' and len(sys.argv) > 1 and sys.argv[1] in ('--cat', '-- echo'):
206 sys.exit(main(sys.platform, sys.stdin, sys.stdout, sys.argv[1], sys.argv[2:] )) 208 sys.exit(main(sys.platform, sys.stdin, sys.stdout, sys.argv[1], sys.argv[2:] ))
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698