Skip to content

Commit

Permalink
added reg test
Browse files Browse the repository at this point in the history
  • Loading branch information
shimwell committed May 23, 2024
1 parent 119fb5f commit 8ffeb2b
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 43 deletions.
66 changes: 24 additions & 42 deletions tests/test_convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,49 +14,8 @@
step_files.remove(Path("testing/inputSTEP/large/Triangle.stp"))
suffixes = (".mcnp", ".xml", ".inp", ".py", ".serp")

def compare_files_line_by_line(filename_new: Path, filename_original: Path):

with open(filename_new, 'r') as f:
file_new = f.readlines()
with open(filename_original, 'r') as f:
file_original = f.readlines()

for line_counter, line_new in enumerate(file_new, start=1):
for line_original in file_original:
if line_new != line_original:
print(f"{filename_new} does not match {filename_original}")
print(f"Line {line_counter} different in files")
# else print that line from both files
print(f"\tFile 1: {line_new}", end='')
print(f"\tFile 2: {line_original}", end='')
assert False

# @pytest.mark.parametrize("input_step_file", step_files[:2])
# @pytest.mark.parametrize("suffix", suffixes)
# def test_new_mc_files_match_original(suffix, input_step_file):
"""Test that the text files produced for each MC code match the original files.
If this test fails it might be due to an improved MC code output instead of
a mistake in the PR. You might want to update the MC text file in the regression
test folder with the 'tests/update_regression_test_files.py' script."""

suffix='.serp'
input_step_file=step_files[0]
# sets up an output folder for the results
regression_test_file = Path("tests/regression_test") / input_step_file.stem/ input_step_file.with_suffix(suffix)
output_dir = Path("tests_outputs") / input_step_file.with_suffix("")
output_filename_stem = output_dir / input_step_file.stem
output_filename = output_filename_stem.with_suffix(suffix)
print(output_dir) #'tests_outputs/testing/inputSTEP/tuboshueco'
print(input_step_file.stem)
print(Path(input_step_file.stem).with_suffix(suffix))

compare_files_line_by_line(output_filename, regression_test_file)

print(output_dir)
assert False
# test_new_mc_files_match_original('.serp', step_files[0])

@pytest.mark.parametrize("input_step_file", step_files[:2])
@pytest.mark.parametrize("input_step_file", step_files)
def test_conversion(input_step_file):
"""Test that step files can be converted to openmc and mcnp files"""

Expand Down Expand Up @@ -266,3 +225,26 @@ def test_with_relative_tol_true():
tolerances=geouned.Tolerances(relativeTol=True),
)
geo.start()

@pytest.mark.parametrize("input_step_file", step_files)
@pytest.mark.parametrize("suffix", suffixes)
def test_new_mc_files_match_original(suffix, input_step_file):
"""
Regression test that the checks the text files produced for each MC code match the text files produced previously.
If this test fails it might be due to an improved MC code output instead of a mistake in the PR.
You might want to update the MC text file in the regression test folder with the 'tests/update_regression_test_files.py' script.
"""

# sets up an output folder for the results
regression_test_file = Path("tests/regression_test_files") / input_step_file.parts[-2] / Path(input_step_file.stem) / Path(input_step_file.name).with_suffix(suffix)
output_filename = Path("tests_outputs") / input_step_file.with_suffix("") / Path(input_step_file.stem).with_suffix(suffix)

with open(output_filename, 'r') as f:
file_new = f.readlines()
with open(regression_test_file, 'r') as f:
file_original = f.readlines()
for line_new, line_original in zip(file_new, file_original):
# this lines in the output files are not expected to match as they have the creation data and time
if ' Creation Date' not in line_new and ' Creation Date' not in line_original:
assert line_new == line_original
assert len(file_new) == len(file_original)
3 changes: 2 additions & 1 deletion tests/update_regression_test_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@
for input_step_file in step_files:

# sets up an output folder for the results
output_dir = Path("tests/regression_test") / input_step_file.with_suffix("")
output_dir = Path("tests/regression_test_files") / input_step_file.parts[-2] / Path(input_step_file.name).with_suffix("")
output_dir.mkdir(parents=True, exist_ok=True)
output_filename_stem = output_dir / input_step_file.stem
print(output_filename_stem)

# deletes the output MC files if they already exists
for suffix in suffixes:
Expand Down

0 comments on commit 8ffeb2b

Please sign in to comment.