From 55ab4cc7c745179a82a58bd0cdc3abe9c360fdf2 Mon Sep 17 00:00:00 2001 From: "Navid C. Constantinou" Date: Tue, 23 Apr 2024 12:20:55 +0300 Subject: [PATCH] cleaner tests --- tests/test_expt_class.py | 36 ++++++++++++++++-------------------- 1 file changed, 16 insertions(+), 20 deletions(-) diff --git a/tests/test_expt_class.py b/tests/test_expt_class.py index 33c115ad..35b3fb42 100644 --- a/tests/test_expt_class.py +++ b/tests/test_expt_class.py @@ -317,16 +317,24 @@ def test_ocean_forcing( arakawa_grid="A", ) + # test whether ValueError is raised if IC is missing a variable + error_msg_missing_tracer = ( + "Error while reading initial condition tracers. Terminating!" + ) + error_msg_missing_velocity = ( + "Error while reading initial condition velocities. Terminating!" + ) + error_msg_missing_free_surface = ( + "Error while reading initial condition free surface. Terminating!" + ) + with pytest.raises(ValueError) as excinfo: expt.initial_condition( tmp_path / "ic_without_u_unprocessed", varnames, arakawa_grid="A", ) - assert ( - str(excinfo.value) - == "Error while reading initial condition velocities. Terminating!" - ) + assert str(excinfo.value) == error_msg_missing_velocity with pytest.raises(ValueError) as excinfo: expt.initial_condition( @@ -334,10 +342,7 @@ def test_ocean_forcing( varnames, arakawa_grid="A", ) - assert ( - str(excinfo.value) - == "Error while reading initial condition velocities. Terminating!" - ) + assert str(excinfo.value) == error_msg_missing_velocity with pytest.raises(ValueError) as excinfo: expt.initial_condition( @@ -345,10 +350,7 @@ def test_ocean_forcing( varnames, arakawa_grid="A", ) - assert ( - str(excinfo.value) - == "Error while reading initial condition tracers. Terminating!" - ) + assert str(excinfo.value) == error_msg_missing_tracer with pytest.raises(ValueError) as excinfo: expt.initial_condition( @@ -356,10 +358,7 @@ def test_ocean_forcing( varnames, arakawa_grid="A", ) - assert ( - str(excinfo.value) - == "Error while reading initial condition tracers. Terminating!" - ) + assert str(excinfo.value) == error_msg_missing_tracer with pytest.raises(ValueError) as excinfo: expt.initial_condition( @@ -367,10 +366,7 @@ def test_ocean_forcing( varnames, arakawa_grid="A", ) - assert ( - str(excinfo.value) - == "Error while reading initial condition free surface. Terminating!" - ) + assert str(excinfo.value) == error_msg_missing_free_surface @pytest.mark.parametrize(