<s> import pytest <EOL> import tempfile <EOL> from calliope . utils import AttrDict <EOL> from . import common <EOL> from . common import assert_almost_equal , solver , _add_test_path <EOL> def create_and_run_model ( override , iterative_warmstart = False ) : <EOL> locations = """<STR_LIT>""" <EOL> config_run = """<STR_LIT>""" <EOL> override = AttrDict . from_yaml_string ( override ) <EOL> override . set_key ( '<STR_LIT>' , solver ) <EOL> with tempfile . NamedTemporaryFile ( ) as f : <EOL> f . write ( locations . encode ( '<STR_LIT:utf-8>' ) ) <EOL> f . read ( ) <EOL> model = common . simple_model ( config_run = config_run , <EOL> config_locations = f . name , <EOL> override = override , <EOL> path = _add_test_path ( '<STR_LIT>' ) ) <EOL> model . run ( iterative_warmstart ) <EOL> return model <EOL> class TestModel : <EOL> def test_model_subset_t_from_middata ( self ) : <EOL> override = """<STR_LIT>""" <EOL> model = create_and_run_model ( override ) <EOL> assert str ( model . results . solver . termination_condition ) == '<STR_LIT>' <EOL> sol = model . solution <EOL> assert sol [ '<STR_LIT:e>' ] . loc [ dict ( c = '<STR_LIT>' , y = '<STR_LIT>' ) ] . sum ( dim = [ '<STR_LIT:x>' , '<STR_LIT:t>' ] ) == <NUM_LIT> <EOL> def test_model_time_res_uniform ( self ) : <EOL> override = """<STR_LIT>""" <EOL> model = create_and_run_model ( override ) <EOL> assert len ( model . data . time_res_series ) == <NUM_LIT:4> <EOL> assert str ( model . results . solver . termination_condition ) == '<STR_LIT>' <EOL> sol = model . solution <EOL> assert sol [ '<STR_LIT:e>' ] . loc [ dict ( c = '<STR_LIT>' , y = '<STR_LIT>' ) ] . sum ( dim = [ '<STR_LIT:x>' , '<STR_LIT:t>' ] ) == <NUM_LIT> <EOL> def test_model_time_res_uniform_subset_t_from_start ( self ) : <EOL> override = """<STR_LIT>""" <EOL> model = create_and_run_model ( override ) <EOL> assert len ( model . data . time_res_series ) == <NUM_LIT:2> <EOL> assert str ( model . results . solver . termination_condition ) == '<STR_LIT>' <EOL> sol = model . solution <EOL> assert sol [ '<STR_LIT:e>' ] . loc [ dict ( c = '<STR_LIT>' , y = '<STR_LIT>' ) ] . sum ( dim = [ '<STR_LIT:x>' , '<STR_LIT:t>' ] ) == <NUM_LIT> <EOL> def test_model_time_res_uniform_subset_t_from_middata ( self ) : <EOL> override = """<STR_LIT>""" <EOL> model = create_and_run_model ( override ) <EOL> assert len ( model . data . time_res_series ) == <NUM_LIT:2> <EOL> assert str ( model . results . solver . termination_condition ) == '<STR_LIT>' <EOL> sol = model . solution <EOL> assert sol [ '<STR_LIT:e>' ] . loc [ dict ( c = '<STR_LIT>' , y = '<STR_LIT>' ) ] . sum ( dim = [ '<STR_LIT:x>' , '<STR_LIT:t>' ] ) == <NUM_LIT> <EOL> def test_model_subset_t_operational ( self ) : <EOL> override = """<STR_LIT>""" <EOL> model = create_and_run_model ( override ) <EOL> assert str ( model . results . solver . termination_condition ) == '<STR_LIT>' <EOL> sol = model . solution <EOL> assert sol [ '<STR_LIT:e>' ] . loc [ dict ( c = '<STR_LIT>' , y = '<STR_LIT>' ) ] . sum ( dim = [ '<STR_LIT:x>' , '<STR_LIT:t>' ] ) == <NUM_LIT> <EOL> def test_model_time_res_uniform_subset_t_operational ( self ) : <EOL> override = """<STR_LIT>""" <EOL> model = create_and_run_model ( override ) <EOL> assert len ( model . data . time_res_series ) == <NUM_LIT:4> <EOL> assert str ( model . results . solver . termination_condition ) == '<STR_LIT>' <EOL> sol = model . solution <EOL> assert sol [ '<STR_LIT:e>' ] . loc [ dict ( c = '<STR_LIT>' , y = '<STR_LIT>' ) ] . sum ( dim = [ '<STR_LIT:x>' , '<STR_LIT:t>' ] ) == <NUM_LIT> </s>
