From 76fae753e9fe61fb4afbfc95f7b553dc9793612d Mon Sep 17 00:00:00 2001 From: Will Benfold Date: Mon, 6 Dec 2021 09:28:49 +0000 Subject: [PATCH] Explicitly define tests so nose can find them --- .../actions/test__hybrid_formulae.py | 99 ++++++++++++------- 1 file changed, 65 insertions(+), 34 deletions(-) diff --git a/lib/iris/tests/unit/fileformats/nc_load_rules/actions/test__hybrid_formulae.py b/lib/iris/tests/unit/fileformats/nc_load_rules/actions/test__hybrid_formulae.py index ca92926542..3413090a3d 100644 --- a/lib/iris/tests/unit/fileformats/nc_load_rules/actions/test__hybrid_formulae.py +++ b/lib/iris/tests/unit/fileformats/nc_load_rules/actions/test__hybrid_formulae.py @@ -238,44 +238,75 @@ def test_two_formulae(self): formula_terms=["a", "b", "depth", "eta", "orog", "sigma"], ) + def test_atmosphere_sigma_coordinate(self): + hybrid_type = "atmosphere_sigma_coordinate" + term_names = hh.CF_COORD_VERTICAL[hybrid_type] + result = self.run_testcase( + formula_root_name=hybrid_type, term_names=term_names + ) + self.check_result( + result, factory_type=hybrid_type, formula_terms=term_names + ) -# Add in tests methods to exercise each (supported) vertical coordinate type -# individually. -# NOTE: hh.CF_COORD_VERTICAL lists all the valid types, but we don't yet -# support all of them. -_SUPPORTED_FORMULA_TYPES = ( - # NOTE: omit "atmosphere_hybrid_height_coordinate" : our basic testcase - "atmosphere_sigma_coordinate", - "atmosphere_hybrid_sigma_pressure_coordinate", - "ocean_sigma_z_coordinate", - "ocean_sigma_coordinate", - "ocean_s_coordinate", - "ocean_s_coordinate_g1", - "ocean_s_coordinate_g2", -) -for hybrid_type in _SUPPORTED_FORMULA_TYPES: + def test_atmosphere_hybrid_sigma_pressure_coordinate(self): + hybrid_type = "atmosphere_hybrid_sigma_pressure_coordinate" + term_names = hh.CF_COORD_VERTICAL[hybrid_type] + result = self.run_testcase( + formula_root_name=hybrid_type, term_names=term_names + ) + self.check_result( + result, factory_type=hybrid_type, formula_terms=term_names + ) + + def test_ocean_sigma_z_coordinate(self): + hybrid_type = "ocean_sigma_z_coordinate" + term_names = hh.CF_COORD_VERTICAL[hybrid_type] + result = self.run_testcase( + formula_root_name=hybrid_type, term_names=term_names + ) + self.check_result( + result, factory_type=hybrid_type, formula_terms=term_names + ) + + def test_ocean_sigma_coordinate(self): + hybrid_type = "ocean_sigma_coordinate" + term_names = hh.CF_COORD_VERTICAL[hybrid_type] + result = self.run_testcase( + formula_root_name=hybrid_type, term_names=term_names + ) + self.check_result( + result, factory_type=hybrid_type, formula_terms=term_names + ) - def construct_inner_func(hybrid_type): + def test_ocean_s_coordinate(self): + hybrid_type = "ocean_s_coordinate" term_names = hh.CF_COORD_VERTICAL[hybrid_type] + result = self.run_testcase( + formula_root_name=hybrid_type, term_names=term_names + ) + self.check_result( + result, factory_type=hybrid_type, formula_terms=term_names + ) - def inner(self): - result = self.run_testcase( - formula_root_name=hybrid_type, term_names=term_names - ) - self.check_result( - result, factory_type=hybrid_type, formula_terms=term_names - ) - - return inner - - # Note: use an intermediate function to generate each test method, simply to - # generate a new local variable for 'hybrid_type' on each iteration. - # Otherwise all the test methods will refer to the *same* 'hybrid_type' - # variable, i.e. the loop variable, which does not work ! - method_name = f"test_{hybrid_type}_coord" - setattr( - Test__formulae_tests, method_name, construct_inner_func(hybrid_type) - ) + def test_ocean_s_coordinate_g1(self): + hybrid_type = "ocean_s_coordinate_g1" + term_names = hh.CF_COORD_VERTICAL[hybrid_type] + result = self.run_testcase( + formula_root_name=hybrid_type, term_names=term_names + ) + self.check_result( + result, factory_type=hybrid_type, formula_terms=term_names + ) + + def test_ocean_s_coordinate_g2(self): + hybrid_type = "ocean_s_coordinate_g2" + term_names = hh.CF_COORD_VERTICAL[hybrid_type] + result = self.run_testcase( + formula_root_name=hybrid_type, term_names=term_names + ) + self.check_result( + result, factory_type=hybrid_type, formula_terms=term_names + ) if __name__ == "__main__":