# Path: calliope/exceptions.py
# def _formatwarning(message, category, filename, lineno, line=None):
# def warn(message, _class=ModelWarning):
# def print_warnings_and_raise_errors(warnings=None, errors=None):
# class ModelError(Exception):
# class BackendError(Exception):
# class ModelWarning(Warning):
# class BackendWarning(Warning):
# 
# Path: calliope/test/common/util.py
# def check_error_or_warning(error_warning, test_string_or_strings):
#     if hasattr(error_warning, "list"):
#         output = ",".join(
#             str(error_warning.list[i]) for i in range(len(error_warning.list))
#         )
#     else:
#         output = str(error_warning.value)
# 
#     if isinstance(test_string_or_strings, list):
#         result = all(test_string in output for test_string in test_string_or_strings)
#     else:
#         result = test_string_or_strings in output
# 
#     return result


from calliope import exceptions
from pytest import approx
from calliope.test.common.util import check_error_or_warning
import shutil
import pytest
import pandas as pd
import numpy as np
import calliope
        self.example_tester(solver="gurobi", solver_io="python")

    def test_nationalscale_example_results_cplex(self):
        if shutil.which("cplex"):
            self.example_tester(solver="cplex")
        else:
            pytest.skip("CPLEX not installed")

    def test_nationalscale_example_results_glpk(self):
        if shutil.which("glpsol"):
            self.example_tester(solver="glpk")
        else:
            pytest.skip("GLPK not installed")

    def test_considers_supply_generation_only_in_total_levelised_cost(self):
        # calculation of expected value:
        # costs = model.get_formatted_array("cost").sum(dim="locs")
        # gen = model.get_formatted_array("carrier_prod").sum(dim=["timesteps", "locs"])
        # lcoe = costs.sum(dim="techs") / gen.sel(techs=["ccgt", "csp"]).sum(dim="techs")
        model = calliope.examples.national_scale()
        model.run()

        assert model.results.total_levelised_cost.item() == approx(0.067005, abs=1e-5)

    def test_fails_gracefully_without_timeseries(self):
        override = {
            "nodes.region1.techs.demand_power.constraints.resource": -200,
            "nodes.region2.techs.demand_power.constraints.resource": -400,
            "techs.csp.constraints.resource": 100,
        }

# Path: calliope/exceptions.py
# def _formatwarning(message, category, filename, lineno, line=None):
# def warn(message, _class=ModelWarning):
# def print_warnings_and_raise_errors(warnings=None, errors=None):
# class ModelError(Exception):
# class BackendError(Exception):
# class ModelWarning(Warning):
# class BackendWarning(Warning):
# 
# Path: calliope/test/common/util.py
# def check_error_or_warning(error_warning, test_string_or_strings):
#     if hasattr(error_warning, "list"):
#         output = ",".join(
#             str(error_warning.list[i]) for i in range(len(error_warning.list))
#         )
#     else:
#         output = str(error_warning.value)
# 
#     if isinstance(test_string_or_strings, list):
#         result = all(test_string in output for test_string in test_string_or_strings)
#     else:
#         result = test_string_or_strings in output
# 
#     return result


# Path: calliope/test/test_example_models.py
from calliope import exceptions
from pytest import approx
from calliope.test.common.util import check_error_or_warning
import shutil
import pytest
import pandas as pd
import numpy as np
import calliope

        self.example_tester(solver="gurobi", solver_io="python")

    def test_nationalscale_example_results_cplex(self):
        if shutil.which("cplex"):
            self.example_tester(solver="cplex")
        else:
            pytest.skip("CPLEX not installed")

    def test_nationalscale_example_results_glpk(self):
        if shutil.which("glpsol"):
            self.example_tester(solver="glpk")
        else:
            pytest.skip("GLPK not installed")

    def test_considers_supply_generation_only_in_total_levelised_cost(self):
        # calculation of expected value:
        # costs = model.get_formatted_array("cost").sum(dim="locs")
        # gen = model.get_formatted_array("carrier_prod").sum(dim=["timesteps", "locs"])
        # lcoe = costs.sum(dim="techs") / gen.sel(techs=["ccgt", "csp"]).sum(dim="techs")
        model = calliope.examples.national_scale()
        model.run()

        assert model.results.total_levelised_cost.item() == approx(0.067005, abs=1e-5)

    def test_fails_gracefully_without_timeseries(self):
        override = {
            "nodes.region1.techs.demand_power.constraints.resource": -200,
            "nodes.region2.techs.demand_power.constraints.resource": -400,
            "techs.csp.constraints.resource": 100,
        }

        with pytest.raises(calliope.exceptions.ModelError):