Skip to content

Commit

Permalink
Fixed unit test: Exception caught inside generator. Check for sys.exi…
Browse files Browse the repository at this point in the history
…t(1)
  • Loading branch information
pstelzig committed Jun 30, 2024
1 parent 04bd128 commit eaa7aa2
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 9 deletions.
12 changes: 11 additions & 1 deletion tests/test_cli.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import shutil
import unittest
import pathlib
from mopyregtest import cli
Expand Down Expand Up @@ -64,7 +65,13 @@ def test_generate4(self):
str(this_folder / "data/FlawedModels"),
"FlawedModels.DoesNotBuild"]

self.assertRaises(AssertionError, cli.parse_args, cmd_args)
with self.assertRaises(SystemExit) as e:
cli.parse_args(cmd_args)

self.assertEqual(e.exception.code, 1)

# Clean up the generated regression tests as otherwise they will confuse unittest discovery
shutil.rmtree(this_folder / "data/gentests")

return

Expand All @@ -80,6 +87,9 @@ def test_generate5(self):

cli.parse_args(cmd_args)

# Clean up the generated regression tests as otherwise they will confuse unittest discovery
shutil.rmtree(this_folder / "data/gentests")

return

def test_compare1(self):
Expand Down
16 changes: 8 additions & 8 deletions tests/test_compare_results.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,18 +67,18 @@ def test_write_comparison_timeseries1(self):
argument.
"""

compar_file_path = (this_folder / "../examples/test_user_defined_metrics/references/Sine_res_comparison.csv")
compare_file_path = (this_folder / "../examples/test_user_defined_metrics/references/Sine_res_comparison.csv")

if compar_file_path.exists():
os.remove(compar_file_path)
if compare_file_path.exists():
os.remove(compare_file_path)

self.assertRaises(AssertionError, mopyregtest.RegressionTest.compare_csv_files,
reference_result="../examples/test_user_defined_metrics/references/SineNoisy_res.csv",
simulation_result="../examples/test_user_defined_metrics/references/Sine_res.csv",
tol=1e-5,
validated_cols=["y"],
write_comparison=False)
self.assertFalse(compar_file_path.exists())
self.assertFalse(compare_file_path.exists())

return

Expand All @@ -87,17 +87,17 @@ def test_write_comparison_timeseries2(self):
Validate that a comparison timeseries is written on a failed test by default.
"""

compar_file_path = (this_folder / "../examples/test_user_defined_metrics/references/Sine_res_comparison.csv")
compare_file_path = (this_folder / "../examples/test_user_defined_metrics/references/Sine_res_comparison.csv")

if compar_file_path.exists():
os.remove(compar_file_path)
if compare_file_path.exists():
os.remove(compare_file_path)

self.assertRaises(AssertionError, mopyregtest.RegressionTest.compare_csv_files,
reference_result="../examples/test_user_defined_metrics/references/SineNoisy_res.csv",
simulation_result="../examples/test_user_defined_metrics/references/Sine_res.csv",
tol=1e-5,
validated_cols=["y"])
self.assertTrue(compar_file_path.exists())
self.assertTrue(compare_file_path.exists())

return

Expand Down

0 comments on commit eaa7aa2

Please sign in to comment.