示例#1
0
 def test_generate_scenarios(self):
     runner = CliRunner()
     with runner.isolated_filesystem() as tempdir:
         out_file = os.path.join(tempdir, 'scenarios.yaml')
         result = runner.invoke(cli.generate_scenarios, [
             _MODEL_NATIONAL,
             out_file,
             'cold_fusion',
             'run1;run2',
             'group_share_cold_fusion_cap;group_share_cold_fusion_prod',
         ])
         assert result.exit_code == 0
         assert os.path.isfile(out_file)
         scenarios = AttrDict.from_yaml(out_file)
         assert 'scenario_0' not in scenarios['scenarios']
         assert scenarios['scenarios'][
             'scenario_1'] == 'cold_fusion,run1,group_share_cold_fusion_cap'
示例#2
0
 def test_generate_scenarios(self):
     runner = CliRunner()
     with runner.isolated_filesystem() as tempdir:
         out_file = os.path.join(tempdir, "scenarios.yaml")
         result = runner.invoke(
             cli.generate_scenarios,
             [
                 _MODEL_NATIONAL,
                 out_file,
                 "cold_fusion",
                 "run1;run2",
                 "cold_fusion_cap_share;cold_fusion_prod_share",
             ],
         )
         assert result.exit_code == 0
         assert os.path.isfile(out_file)
         scenarios = AttrDict.from_yaml(out_file)
         assert "scenario_0" not in scenarios["scenarios"]
         assert scenarios["scenarios"]["scenario_1"] == [
             "cold_fusion",
             "run1",
             "cold_fusion_cap_share",
         ]
示例#3
0
import os

import calliope
from calliope import AttrDict


constraint_sets = AttrDict.from_yaml(os.path.join(os.path.dirname(__file__), 'constraint_sets.yaml'))

_defaults_files = {
    k: os.path.join(os.path.dirname(calliope.__file__), 'config', k + '.yaml')
    for k in ['model', 'defaults']
}
defaults = AttrDict.from_yaml(_defaults_files['defaults'])
defaults_model = AttrDict.from_yaml(_defaults_files['model'])


def build_test_model(override_dict=None, override_groups=None):
    this_path = os.path.dirname(__file__)
    model_location = os.path.join(this_path, 'test_model', 'model.yaml')
    override_location = os.path.join(this_path, 'test_model', 'overrides.yaml')
    if override_groups:
        override_file = override_location + ':' + override_groups
    else:
        override_file = None

    return calliope.Model(
        model_location, override_dict=override_dict,
        override_file=override_file
    )
示例#4
0
import os
import sys

import pytest
from pyomo.core.expr.current import identify_variables

import calliope
from calliope import AttrDict

constraint_sets = AttrDict.from_yaml(
    os.path.join(os.path.dirname(__file__), "constraint_sets.yaml"))

defaults = AttrDict.from_yaml(
    os.path.join(os.path.dirname(calliope.__file__), "config",
                 "defaults.yaml"))

python36_or_higher = pytest.mark.skipif(
    sys.version_info < (3, 6),
    reason="Requires ordered dicts from Python >= 3.6")


def build_test_model(override_dict=None,
                     scenario=None,
                     model_file="model.yaml"):
    return calliope.Model(
        os.path.join(os.path.dirname(__file__), "test_model", model_file),
        override_dict=override_dict,
        scenario=scenario,
    )

示例#5
0
import sys
import ast

import pytest
from pyomo.core.expr.current import identify_variables
import pyomo.core as po

import calliope
from calliope import AttrDict


constraint_sets = {
    k: [ast.literal_eval(i) for i in v]
    for k, v in AttrDict.from_yaml(
        os.path.join(os.path.dirname(__file__), "constraint_sets.yaml")
    )
    .as_dict_flat()
    .items()
}

defaults = AttrDict.from_yaml(
    os.path.join(os.path.dirname(calliope.__file__), "config", "defaults.yaml")
)

subsets_config = AttrDict.from_yaml(
    os.path.join(os.path.dirname(calliope.__file__), "config", "subsets.yaml")
)

python36_or_higher = pytest.mark.skipif(
    sys.version_info < (3, 6), reason="Requires ordered dicts from Python >= 3.6"
)
示例#6
0
import os
import sys

import pytest

import calliope
from calliope import AttrDict


constraint_sets = AttrDict.from_yaml(os.path.join(os.path.dirname(__file__), 'constraint_sets.yaml'))

_defaults_files = {
    k: os.path.join(os.path.dirname(calliope.__file__), 'config', k + '.yaml')
    for k in ['model', 'defaults']
}
defaults = AttrDict.from_yaml(_defaults_files['defaults'])
defaults_model = AttrDict.from_yaml(_defaults_files['model'])


python36_or_higher = pytest.mark.skipif(
    sys.version_info < (3, 6),
    reason="Requires ordered dicts from Python >= 3.6"
)


def build_test_model(override_dict=None, scenario=None, minimal=False):
    this_path = os.path.dirname(__file__)
    model = 'model_minimal.yaml' if minimal is True else 'model.yaml'

    model_location = os.path.join(this_path, 'test_model', model)