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