<s> import pytest <EOL> import tempfile <EOL> from calliope . utils import AttrDict <EOL> from . import common <EOL> from . common import assert_almost_equal , solver <EOL> class TestModel : <EOL> @ pytest . fixture ( scope = '<STR_LIT>' ) <EOL> def model ( self ) : <EOL> locations = """<STR_LIT>""" <EOL> config_run = """<STR_LIT>""" <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 = AttrDict ( { '<STR_LIT>' : solver } ) ) <EOL> model . run ( ) <EOL> return model <EOL> def test_model_solves ( self , model ) : <EOL> assert str ( model . results . solver . termination_condition ) == '<STR_LIT>' <EOL> def test_model_balanced ( self , model ) : <EOL> sol = model . solution <EOL> assert sol [ '<STR_LIT:e>' ] . loc [ dict ( c = '<STR_LIT>' , y = '<STR_LIT>' ) ] . sum ( dim = '<STR_LIT:x>' ) . mean ( ) == <NUM_LIT:100> <EOL> assert ( sol [ '<STR_LIT:e>' ] . loc [ dict ( c = '<STR_LIT>' , y = '<STR_LIT>' ) ] . sum ( dim = '<STR_LIT:x>' ) == <EOL> - <NUM_LIT:1> * sol [ '<STR_LIT:e>' ] . loc [ dict ( c = '<STR_LIT>' , y = '<STR_LIT>' ) ] . sum ( dim = '<STR_LIT:x>' ) ) . all ( ) <EOL> def test_model_costs ( self , model ) : <EOL> sol = model . solution <EOL> assert_almost_equal ( sol [ '<STR_LIT>' ] . to_pandas ( ) . loc [ '<STR_LIT>' , '<STR_LIT>' ] , <NUM_LIT:0.1> ) </s>
