diff --git a/setup.py b/setup.py index aff7834d7b..99db831484 100755 --- a/setup.py +++ b/setup.py @@ -69,7 +69,7 @@ kwargs = { 'pandas', 'lxml', 'uncertainties' ], 'extras_require': { - 'test': ['pytest', 'pytest-cov'], + 'test': ['pytest', 'pytest-cov', 'colorama'], 'vtk': ['vtk'], }, } diff --git a/tests/testing_harness.py b/tests/testing_harness.py index 0d3c4bec00..2266189c05 100644 --- a/tests/testing_harness.py +++ b/tests/testing_harness.py @@ -10,9 +10,25 @@ import sys import numpy as np import openmc from openmc.examples import pwr_core +from colorama import Fore, init from tests.regression_tests import config +init() + + +def colorize(diff): + """Produce colored diff for test results""" + for line in diff: + if line.startswith('+'): + yield Fore.RED + line + Fore.RESET + elif line.startswith('-'): + yield Fore.GREEN + line + Fore.RESET + elif line.startswith('^'): + yield Fore.BLUE + line + Fore.RESET + else: + yield line + class TestHarness(object): """General class for running OpenMC regression tests.""" @@ -108,11 +124,17 @@ class TestHarness(object): shutil.copyfile('results_test.dat', 'results_true.dat') def _compare_results(self): - """Make sure the current results agree with the _true standard.""" + """Make sure the current results agree with the reference.""" compare = filecmp.cmp('results_test.dat', 'results_true.dat') if not compare: + expected = open('results_true.dat').readlines() + actual = open('results_test.dat').readlines() + diff = unified_diff(expected, actual, 'results_true.dat', + 'results_test.dat') + print('Result differences:') + print(''.join(colorize(diff))) os.rename('results_test.dat', 'results_error.dat') - assert compare, 'Results do not agree.' + assert compare, 'Results do not agree' def _cleanup(self): """Delete statepoints, tally, and test files.""" @@ -325,11 +347,13 @@ class PyAPITestHarness(TestHarness): """Make sure the current inputs agree with the _true standard.""" compare = filecmp.cmp('inputs_test.dat', 'inputs_true.dat') if not compare: + expected = open('inputs_true.dat', 'r').readlines() + actual = open('inputs_error.dat', 'r').readlines() + diff = unified_diff(expected, actual, 'inputs_true.dat', + 'inputs_error.dat') + print('Input differences:') + print(''.join(colorize(diff))) os.rename('inputs_test.dat', 'inputs_error.dat') - for line in unified_diff(open('inputs_true.dat', 'r').readlines(), - open('inputs_error.dat', 'r').readlines(), - 'inputs_true.dat', 'inputs_error.dat'): - print(line, end='') assert compare, 'Input files are broken.' def _cleanup(self):