mirror of
https://github.com/openmc-dev/openmc.git
synced 2026-07-28 06:05:58 -04:00
Show colored diffs on test results when there are failures
This commit is contained in:
parent
4ba8568f08
commit
f2a59994d6
2 changed files with 31 additions and 7 deletions
2
setup.py
2
setup.py
|
|
@ -69,7 +69,7 @@ kwargs = {
|
|||
'pandas', 'lxml', 'uncertainties'
|
||||
],
|
||||
'extras_require': {
|
||||
'test': ['pytest', 'pytest-cov'],
|
||||
'test': ['pytest', 'pytest-cov', 'colorama'],
|
||||
'vtk': ['vtk'],
|
||||
},
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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):
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue