Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion tests/test_basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def test_basic_model_construction(self):
except (ImportError, AttributeError):
pytest.skip("biofuel module or build_model not available")
except Exception as e:
pytest.skip(f"Model construction failed: {e}")
pytest.fail(f"Model construction raised unexpected error: {e}")


# (Line intentionally left blank for clarity and to maintain spacing.)
8 changes: 5 additions & 3 deletions tests/test_model_structure.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,8 @@ class TestModelFunctionality:

def test_models_return_pyomo_objects(self):
"""Test that build_model functions return proper Pyomo model objects."""
# Test a few key models
test_modules = ["cstr", "biofuel", "gdp_col"]
# Test all available modules
test_modules = self.GDPLIB_MODULES

for module_name in test_modules:
try:
Expand All @@ -142,7 +142,9 @@ def test_models_return_pyomo_objects(self):
), f"{module_name} model has no components"

except Exception as e:
pytest.skip(f"{module_name} model construction failed: {e}")
pytest.fail(
f"{module_name} model construction raised unexpected error: {e}"
)
except ImportError:
pytest.skip(f"Module {module_name} not available")

Expand Down
66 changes: 32 additions & 34 deletions tests/test_module_imports.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,50 +86,48 @@ def test_build_model_callable(self, module_name):
f"{module_name}.build_model requires specific arguments"
)
except Exception as e:
pytest.skip(f"{module_name}.build_model failed with error: {e}")
err_msg = str(e)
if (
"No executable found for solver" in err_msg
or "No 'gams' command" in err_msg
):
pytest.skip(
f"{module_name}.build_model requires external solver: {e}"
)
else:
pytest.fail(
f"{module_name}.build_model raised unexpected error: {e}"
)
except ImportError:
pytest.skip(f"Module {module_name} not available")


class TestModelConstruction:
"""Test model construction for key modules."""

def test_cstr_model_construction(self):
"""Test CSTR model construction specifically."""
try:
import gdplib.cstr
"""Test model construction for all GDPlib modules."""

model = gdplib.cstr.build_model()
assert model is not None
# Basic model validation
assert hasattr(model, "component_objects")
except ImportError:
pytest.skip("CSTR module not available")
except Exception as e:
pytest.skip(f"CSTR model construction failed: {e}")
MODELS = TestModuleImports.GDPLIB_MODULES

def test_biofuel_model_construction(self):
"""Test biofuel model construction specifically."""
@pytest.mark.parametrize("module_name", MODELS)
def test_model_construction(self, module_name):
"""Ensure that selected models can be built successfully."""
try:
import gdplib.biofuel

model = gdplib.biofuel.build_model()
assert model is not None
assert hasattr(model, "component_objects")
except ImportError:
pytest.skip("Biofuel module not available")
except Exception as e:
pytest.skip(f"Biofuel model construction failed: {e}")

def test_gdp_col_model_construction(self):
"""Test GDP column model construction specifically."""
try:
import gdplib.gdp_col
module = importlib.import_module(f"gdplib.{module_name}")

model = gdplib.gdp_col.build_model()
model = module.build_model()
assert model is not None
assert hasattr(model, "component_objects")
except ImportError:
pytest.skip("GDP column module not available")
pytest.skip(f"{module_name} module not available")
except Exception as e:
pytest.skip(f"GDP column model construction failed: {e}")
err_msg = str(e)
if (
"No executable found for solver" in err_msg
or "No 'gams' command" in err_msg
):
pytest.skip(
f"{module_name} model construction requires external solver: {e}"
)
else:
pytest.fail(
f"{module_name} model construction raised unexpected error: {e}"
)
2 changes: 1 addition & 1 deletion tests/test_pip_installation.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,4 +122,4 @@ def test_pip_install_scenario(self):
else:
pytest.fail(f"Import failed: {e}")
except Exception as e:
pytest.skip(f"Model construction failed (may require solver): {e}")
pytest.fail(f"Model construction raised unexpected error: {e}")
Loading