Utility to call 'ipython filename' and validate output/error. This function raises an AssertionError if the validation fails. Note that this starts IPython in a subprocess! Parameters ---------- fname : str Name of the file to be executed (should have .py or .ipy extensi
(fname, expected_out, expected_err='',
options=None, commands=())
| 220 | |
| 221 | |
| 222 | def ipexec_validate(fname, expected_out, expected_err='', |
| 223 | options=None, commands=()): |
| 224 | """Utility to call 'ipython filename' and validate output/error. |
| 225 | |
| 226 | This function raises an AssertionError if the validation fails. |
| 227 | |
| 228 | Note that this starts IPython in a subprocess! |
| 229 | |
| 230 | Parameters |
| 231 | ---------- |
| 232 | fname : str |
| 233 | Name of the file to be executed (should have .py or .ipy extension). |
| 234 | |
| 235 | expected_out : str |
| 236 | Expected stdout of the process. |
| 237 | |
| 238 | expected_err : optional, str |
| 239 | Expected stderr of the process. |
| 240 | |
| 241 | options : optional, list |
| 242 | Extra command-line flags to be passed to IPython. |
| 243 | |
| 244 | Returns |
| 245 | ------- |
| 246 | None |
| 247 | """ |
| 248 | |
| 249 | import nose.tools as nt |
| 250 | |
| 251 | out, err = ipexec(fname, options, commands) |
| 252 | #print 'OUT', out # dbg |
| 253 | #print 'ERR', err # dbg |
| 254 | # If there are any errors, we must check those before stdout, as they may be |
| 255 | # more informative than simply having an empty stdout. |
| 256 | if err: |
| 257 | if expected_err: |
| 258 | nt.assert_equal("\n".join(err.strip().splitlines()), "\n".join(expected_err.strip().splitlines())) |
| 259 | else: |
| 260 | raise ValueError('Running file %r produced error: %r' % |
| 261 | (fname, err)) |
| 262 | # If no errors or output on stderr was expected, match stdout |
| 263 | nt.assert_equal("\n".join(out.strip().splitlines()), "\n".join(expected_out.strip().splitlines())) |
| 264 | |
| 265 | |
| 266 | class TempFileMixin(unittest.TestCase): |