@@ -404,17 +404,29 @@ def compare_outputs(self, test, ref, skip_compare=None):
404
404
# The traceback from the comparison will be stored here.
405
405
self .comparison_traceback = []
406
406
407
- for key in reference_outs .keys ():
407
+ ref_keys = set (reference_outs .keys ())
408
+ test_keys = set (testing_outs .keys ())
408
409
409
- # Check if they have the same keys
410
- if key not in testing_outs .keys ():
411
- self .comparison_traceback .append (
412
- bcolors .FAIL
413
- + "missing key: TESTING %s != REFERENCE %s"
414
- % (testing_outs .keys (), reference_outs .keys ())
415
- + bcolors .ENDC )
416
- return False
410
+ if ref_keys - test_keys :
411
+ self .comparison_traceback .append (
412
+ bcolors .FAIL
413
+ + "Missing output fields from running code: %s"
414
+ % (ref_keys - test_keys )
415
+ + bcolors .ENDC
416
+ )
417
+ return False
418
+ elif test_keys - ref_keys :
419
+ self .comparison_traceback .append (
420
+ bcolors .FAIL
421
+ + "Unexpected output fields from running code: %s"
422
+ % (test_keys - ref_keys )
423
+ + bcolors .ENDC
424
+ )
425
+ return False
426
+
427
+ # If we've got to here, the two dicts must have the same set of keys
417
428
429
+ for key in reference_outs .keys ():
418
430
# Get output values for dictionary entries.
419
431
# We use str() to be sure that the unicode key strings from the
420
432
# reference are also read from the testing dictionary:
@@ -453,9 +465,9 @@ def compare_outputs(self, test, ref, skip_compare=None):
453
465
def format_output_compare (self , key , left , right ):
454
466
"""Format an output for printing"""
455
467
if isinstance (left , six .string_types ):
456
- left = _trim_base64 (output )
468
+ left = _trim_base64 (left )
457
469
if isinstance (right , six .string_types ):
458
- right = _trim_base64 (output )
470
+ right = _trim_base64 (right )
459
471
460
472
self .comparison_traceback .append (
461
473
bcolors .OKBLUE
@@ -474,7 +486,7 @@ def format_output_compare(self, key, left, right):
474
486
else :
475
487
# Fallback repr:
476
488
self .comparison_traceback .append (
477
- + " <<<<<<<<<<<< Reference output from ipynb file:"
489
+ " <<<<<<<<<<<< Reference output from ipynb file:"
478
490
+ bcolors .ENDC )
479
491
self .comparison_traceback .append (_indent (left ))
480
492
self .comparison_traceback .append (
@@ -786,7 +798,6 @@ def coalesce_streams(outputs):
786
798
787
799
# process \r and \b characters
788
800
for output in streams .values ():
789
- backspace_pat
790
801
old = output .text
791
802
while len (output .text ) < len (old ):
792
803
old = output .text
0 commit comments