|
3 | 3 | import errno |
4 | 4 | import logging |
5 | 5 | import socket |
| 6 | +import sys |
6 | 7 | import time |
7 | 8 | import unittest |
8 | 9 | import unittest.mock |
@@ -234,8 +235,57 @@ def cb(loop): |
234 | 235 | self.assertEqual([handle], list(self.loop._ready)) |
235 | 236 |
|
236 | 237 | def test_run_until_complete_type_error(self): |
237 | | - self.assertRaises( |
238 | | - TypeError, self.loop.run_until_complete, 'blah') |
| 238 | + self.assertRaises(TypeError, |
| 239 | + self.loop.run_until_complete, 'blah') |
| 240 | + |
| 241 | + def test_subprocess_exec_invalid_args(self): |
| 242 | + args = [sys.executable, '-c', 'pass'] |
| 243 | + |
| 244 | + # missing program parameter (empty args) |
| 245 | + self.assertRaises(TypeError, |
| 246 | + self.loop.run_until_complete, self.loop.subprocess_exec, |
| 247 | + asyncio.SubprocessProtocol) |
| 248 | + |
| 249 | + # exepected multiple arguments, not a list |
| 250 | + self.assertRaises(TypeError, |
| 251 | + self.loop.run_until_complete, self.loop.subprocess_exec, |
| 252 | + asyncio.SubprocessProtocol, args) |
| 253 | + |
| 254 | + # program arguments must be strings, not int |
| 255 | + self.assertRaises(TypeError, |
| 256 | + self.loop.run_until_complete, self.loop.subprocess_exec, |
| 257 | + asyncio.SubprocessProtocol, sys.executable, 123) |
| 258 | + |
| 259 | + # universal_newlines, shell, bufsize must not be set |
| 260 | + self.assertRaises(TypeError, |
| 261 | + self.loop.run_until_complete, self.loop.subprocess_exec, |
| 262 | + asyncio.SubprocessProtocol, *args, universal_newlines=True) |
| 263 | + self.assertRaises(TypeError, |
| 264 | + self.loop.run_until_complete, self.loop.subprocess_exec, |
| 265 | + asyncio.SubprocessProtocol, *args, shell=True) |
| 266 | + self.assertRaises(TypeError, |
| 267 | + self.loop.run_until_complete, self.loop.subprocess_exec, |
| 268 | + asyncio.SubprocessProtocol, *args, bufsize=4096) |
| 269 | + |
| 270 | + def test_subprocess_shell_invalid_args(self): |
| 271 | + # exepected a string, not an int or a list |
| 272 | + self.assertRaises(TypeError, |
| 273 | + self.loop.run_until_complete, self.loop.subprocess_shell, |
| 274 | + asyncio.SubprocessProtocol, 123) |
| 275 | + self.assertRaises(TypeError, |
| 276 | + self.loop.run_until_complete, self.loop.subprocess_shell, |
| 277 | + asyncio.SubprocessProtocol, [sys.executable, '-c', 'pass']) |
| 278 | + |
| 279 | + # universal_newlines, shell, bufsize must not be set |
| 280 | + self.assertRaises(TypeError, |
| 281 | + self.loop.run_until_complete, self.loop.subprocess_shell, |
| 282 | + asyncio.SubprocessProtocol, 'exit 0', universal_newlines=True) |
| 283 | + self.assertRaises(TypeError, |
| 284 | + self.loop.run_until_complete, self.loop.subprocess_shell, |
| 285 | + asyncio.SubprocessProtocol, 'exit 0', shell=True) |
| 286 | + self.assertRaises(TypeError, |
| 287 | + self.loop.run_until_complete, self.loop.subprocess_shell, |
| 288 | + asyncio.SubprocessProtocol, 'exit 0', bufsize=4096) |
239 | 289 |
|
240 | 290 |
|
241 | 291 | class MyProto(asyncio.Protocol): |
|
0 commit comments