@@ -86,50 +86,48 @@ def test_build_model_callable(self, module_name):
8686 f"{ module_name } .build_model requires specific arguments"
8787 )
8888 except Exception as e :
89- pytest .skip (f"{ module_name } .build_model failed with error: { e } " )
89+ err_msg = str (e )
90+ if (
91+ "No executable found for solver" in err_msg
92+ or "No 'gams' command" in err_msg
93+ ):
94+ pytest .skip (
95+ f"{ module_name } .build_model requires external solver: { e } "
96+ )
97+ else :
98+ pytest .fail (
99+ f"{ module_name } .build_model raised unexpected error: { e } "
100+ )
90101 except ImportError :
91102 pytest .skip (f"Module { module_name } not available" )
92103
93104
94105class TestModelConstruction :
95106 """Test model construction for key modules."""
96107
97- def test_cstr_model_construction (self ):
98- """Test CSTR model construction specifically."""
99- try :
100- import gdplib .cstr
101-
102- model = gdplib .cstr .build_model ()
103- assert model is not None
104- # Basic model validation
105- assert hasattr (model , "component_objects" )
106- except ImportError :
107- pytest .skip ("CSTR module not available" )
108- except Exception as e :
109- pytest .skip (f"CSTR model construction failed: { e } " )
108+ MODELS = ["cstr" , "biofuel" , "gdp_col" ]
110109
111- def test_biofuel_model_construction (self ):
112- """Test biofuel model construction specifically."""
110+ @pytest .mark .parametrize ("module_name" , MODELS )
111+ def test_model_construction (self , module_name ):
112+ """Ensure that selected models can be built successfully."""
113113 try :
114- import gdplib .biofuel
115-
116- model = gdplib .biofuel .build_model ()
117- assert model is not None
118- assert hasattr (model , "component_objects" )
119- except ImportError :
120- pytest .skip ("Biofuel module not available" )
121- except Exception as e :
122- pytest .skip (f"Biofuel model construction failed: { e } " )
123-
124- def test_gdp_col_model_construction (self ):
125- """Test GDP column model construction specifically."""
126- try :
127- import gdplib .gdp_col
114+ module = importlib .import_module (f"gdplib.{ module_name } " )
128115
129- model = gdplib . gdp_col .build_model ()
116+ model = module .build_model ()
130117 assert model is not None
131118 assert hasattr (model , "component_objects" )
132119 except ImportError :
133- pytest .skip ("GDP column module not available" )
120+ pytest .skip (f" { module_name } module not available" )
134121 except Exception as e :
135- pytest .skip (f"GDP column model construction failed: { e } " )
122+ err_msg = str (e )
123+ if (
124+ "No executable found for solver" in err_msg
125+ or "No 'gams' command" in err_msg
126+ ):
127+ pytest .skip (
128+ f"{ module_name } model construction requires external solver: { e } "
129+ )
130+ else :
131+ pytest .fail (
132+ f"{ module_name } model construction raised unexpected error: { e } "
133+ )
0 commit comments