| OLD | NEW |
| 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 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 61 | 61 |
| 62 def test_message_with_tuple(self): | 62 def test_message_with_tuple(self): |
| 63 error = ScriptError('', ('my', 'command'), -1, 'My output.', '/Users/use
rname/blah') | 63 error = ScriptError('', ('my', 'command'), -1, 'My output.', '/Users/use
rname/blah') |
| 64 self.assertEqual(error.message_with_output(), | 64 self.assertEqual(error.message_with_output(), |
| 65 'Failed to run "(\'my\', \'command\')" exit_code: -1 cw
d: /Users/username/blah\n\noutput: My output.') | 65 'Failed to run "(\'my\', \'command\')" exit_code: -1 cw
d: /Users/username/blah\n\noutput: My output.') |
| 66 | 66 |
| 67 | 67 |
| 68 def never_ending_command(): | 68 def never_ending_command(): |
| 69 """Arguments for a command that will never end (useful for testing process | 69 """Arguments for a command that will never end (useful for testing process |
| 70 killing). It should be a process that is unlikely to already be running | 70 killing). It should be a process that is unlikely to already be running |
| 71 because all instances will be killed.""" | 71 because all instances will be killed. |
| 72 """ |
| 72 if sys.platform == 'win32': | 73 if sys.platform == 'win32': |
| 73 return ['wmic'] | 74 return ['wmic'] |
| 74 return ['yes'] | 75 return ['yes'] |
| 75 | 76 |
| 76 | 77 |
| 77 def command_line(cmd, *args): | 78 def command_line(cmd, *args): |
| 78 return [sys.executable, __file__, '--' + cmd] + list(args) | 79 return [sys.executable, __file__, '--' + cmd] + list(args) |
| 79 | 80 |
| 80 | 81 |
| 81 class ExecutiveTest(unittest.TestCase): | 82 class ExecutiveTest(unittest.TestCase): |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 120 self.assertEqual('echo 1', executive.command_for_printing(['echo', 1])) | 121 self.assertEqual('echo 1', executive.command_for_printing(['echo', 1])) |
| 121 | 122 |
| 122 def test_popen_args(self): | 123 def test_popen_args(self): |
| 123 executive = Executive() | 124 executive = Executive() |
| 124 # Explicitly naming the 'args' argument should not throw an exception. | 125 # Explicitly naming the 'args' argument should not throw an exception. |
| 125 executive.popen(args=command_line('echo', 1), stdout=executive.PIPE).wai
t() | 126 executive.popen(args=command_line('echo', 1), stdout=executive.PIPE).wai
t() |
| 126 | 127 |
| 127 def test_run_command_with_unicode(self): | 128 def test_run_command_with_unicode(self): |
| 128 """Validate that it is safe to pass unicode() objects | 129 """Validate that it is safe to pass unicode() objects |
| 129 to Executive.run* methods, and they will return unicode() | 130 to Executive.run* methods, and they will return unicode() |
| 130 objects by default unless decode_output=False""" | 131 objects by default unless decode_output=False |
| 132 """ |
| 131 unicode_tor_input = u"WebKit \u2661 Tor Arne Vestb\u00F8!" | 133 unicode_tor_input = u"WebKit \u2661 Tor Arne Vestb\u00F8!" |
| 132 if sys.platform == 'win32': | 134 if sys.platform == 'win32': |
| 133 encoding = 'mbcs' | 135 encoding = 'mbcs' |
| 134 else: | 136 else: |
| 135 encoding = 'utf-8' | 137 encoding = 'utf-8' |
| 136 encoded_tor = unicode_tor_input.encode(encoding) | 138 encoded_tor = unicode_tor_input.encode(encoding) |
| 137 # On Windows, we expect the unicode->mbcs->unicode roundtrip to be | 139 # On Windows, we expect the unicode->mbcs->unicode roundtrip to be |
| 138 # lossy. On other platforms, we expect a lossless roundtrip. | 140 # lossy. On other platforms, we expect a lossless roundtrip. |
| 139 if sys.platform == 'win32': | 141 if sys.platform == 'win32': |
| 140 unicode_tor_output = encoded_tor.decode(encoding) | 142 unicode_tor_output = encoded_tor.decode(encoding) |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 199 import msvcrt | 201 import msvcrt |
| 200 msvcrt.setmode(stdout.fileno(), os.O_BINARY) | 202 msvcrt.setmode(stdout.fileno(), os.O_BINARY) |
| 201 if cmd == '--cat': | 203 if cmd == '--cat': |
| 202 stdout.write(stdin.read()) | 204 stdout.write(stdin.read()) |
| 203 elif cmd == '--echo': | 205 elif cmd == '--echo': |
| 204 stdout.write(' '.join(args)) | 206 stdout.write(' '.join(args)) |
| 205 return 0 | 207 return 0 |
| 206 | 208 |
| 207 if __name__ == '__main__' and len(sys.argv) > 1 and sys.argv[1] in ('--cat', '--
echo'): | 209 if __name__ == '__main__' and len(sys.argv) > 1 and sys.argv[1] in ('--cat', '--
echo'): |
| 208 sys.exit(main(sys.platform, sys.stdin, sys.stdout, sys.argv[1], sys.argv[2:]
)) | 210 sys.exit(main(sys.platform, sys.stdin, sys.stdout, sys.argv[1], sys.argv[2:]
)) |
| OLD | NEW |