##// END OF EJS Templates
Pytest diagnostics improvement for `IPython.testing.tools`...
Nikita Kniazev -
Show More
@@ -6,6 +6,9 b' import pytest'
6 6 import pathlib
7 7 import shutil
8 8
9 # Must register before it gets imported
10 pytest.register_assert_rewrite("IPython.testing.tools")
11
9 12 from .testing import tools
10 13
11 14
@@ -181,7 +181,10 b' def ipexec(fname, options=None, commands=()):'
181 181 -------
182 182 ``(stdout, stderr)`` of ipython subprocess.
183 183 """
184 if options is None: options = []
184 __tracebackhide__ = True
185
186 if options is None:
187 options = []
185 188
186 189 cmdargs = default_argv() + options
187 190
@@ -239,6 +242,7 b" def ipexec_validate(fname, expected_out, expected_err='',"
239 242 -------
240 243 None
241 244 """
245 __tracebackhide__ = True
242 246
243 247 out, err = ipexec(fname, options, commands)
244 248 #print 'OUT', out # dbg
@@ -247,12 +251,16 b" def ipexec_validate(fname, expected_out, expected_err='',"
247 251 # more informative than simply having an empty stdout.
248 252 if err:
249 253 if expected_err:
250 assert err.strip().splitlines() == expected_err.strip().splitlines()
254 assert "\n".join(err.strip().splitlines()) == "\n".join(
255 expected_err.strip().splitlines()
256 )
251 257 else:
252 258 raise ValueError('Running file %r produced error: %r' %
253 259 (fname, err))
254 260 # If no errors or output on stderr was expected, match stdout
255 assert out.strip().splitlines() == expected_out.strip().splitlines()
261 assert "\n".join(out.strip().splitlines()) == "\n".join(
262 expected_out.strip().splitlines()
263 )
256 264
257 265
258 266 class TempFileMixin(unittest.TestCase):
@@ -312,6 +320,8 b' def check_pairs(func, pairs):'
312 320 None. Raises an AssertionError if any output does not match the expected
313 321 value.
314 322 """
323 __tracebackhide__ = True
324
315 325 name = getattr(func, "func_name", getattr(func, "__name__", "<unknown>"))
316 326 for inp, expected in pairs:
317 327 out = func(inp)
@@ -354,6 +364,8 b' class AssertPrints(object):'
354 364 setattr(sys, self.channel, self.buffer if self.suppress else self.tee)
355 365
356 366 def __exit__(self, etype, value, traceback):
367 __tracebackhide__ = True
368
357 369 try:
358 370 if value is not None:
359 371 # If an error was raised, don't check anything else
@@ -381,6 +393,8 b' class AssertNotPrints(AssertPrints):'
381 393
382 394 Counterpart of AssertPrints"""
383 395 def __exit__(self, etype, value, traceback):
396 __tracebackhide__ = True
397
384 398 try:
385 399 if value is not None:
386 400 # If an error was raised, don't check anything else
General Comments 0
You need to be logged in to leave comments. Login now