Skip to content

Commit ef0073f

Browse files
committed
Simplify model-specific construction tests
1 parent fbf6eab commit ef0073f

File tree

4 files changed

+36
-36
lines changed

4 files changed

+36
-36
lines changed

tests/test_basic.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ def test_basic_model_construction(self):
6868
except (ImportError, AttributeError):
6969
pytest.skip("biofuel module or build_model not available")
7070
except Exception as e:
71-
pytest.skip(f"Model construction failed: {e}")
71+
pytest.fail(f"Model construction raised unexpected error: {e}")
7272

7373

7474
# (Line intentionally left blank for clarity and to maintain spacing.)

tests/test_model_structure.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,9 @@ def test_models_return_pyomo_objects(self):
142142
), f"{module_name} model has no components"
143143

144144
except Exception as e:
145-
pytest.skip(f"{module_name} model construction failed: {e}")
145+
pytest.fail(
146+
f"{module_name} model construction raised unexpected error: {e}"
147+
)
146148
except ImportError:
147149
pytest.skip(f"Module {module_name} not available")
148150

tests/test_module_imports.py

Lines changed: 31 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -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

94105
class 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+
)

tests/test_pip_installation.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,4 +122,4 @@ def test_pip_install_scenario(self):
122122
else:
123123
pytest.fail(f"Import failed: {e}")
124124
except Exception as e:
125-
pytest.skip(f"Model construction failed (may require solver): {e}")
125+
pytest.fail(f"Model construction raised unexpected error: {e}")

0 commit comments

Comments
 (0)