Exemplo n.º 1
0
def test_message_model_dir(ixmp_cli, tmp_env, tmp_path):
    """Configuration keys like 'message model dir' can be registered, set, and used."""
    value = tmp_path

    key = "TEST message model dir"

    # Setting the key without first registering it results in an error
    result = ixmp_cli.invoke(["config", "set", key, str(value)])
    assert 1 == result.exit_code
    assert (
        f"Error: No registered configuration key {repr(key)}" == result.output.strip()
    )

    # Register the key
    config.register(key, Path, Path(__file__).parent / "model")

    # The key can be set
    result = ixmp_cli.invoke(["config", "set", key, str(value)])
    assert 0 == result.exit_code

    # Force re-read of the key from file
    config.read()

    # Configuration value has the expected type
    assert isinstance(config.get(key), Path)
    # Expected value
    assert value == config.get(key)

    # Configuration
    result = ixmp_cli.invoke(["config", "get", key])
    assert str(value) == result.output.strip()

    # Clean for remainder of tests
    config.unregister(key)
    assert key not in config.keys()
Exemplo n.º 2
0
    def __init__(self, name=None, **model_options):
        # Update the default options with any user-provided options
        model_options.setdefault("model_dir", config.get("message model dir"))
        self.cplex_opts = copy(DEFAULT_CPLEX_OPTIONS)
        self.cplex_opts.update(config.get("message solve options") or dict())
        self.cplex_opts.update(model_options.pop("solve_options", {}))

        super().__init__(name, **model_options)
Exemplo n.º 3
0
    def read_version(cls):
        """Retrieve MESSAGE version string from version.gms."""
        version_file = Path(config.get('message model dir'), 'version.gms')
        if not version_file.exists():
            # Only exists here on install
            version_file = Path(__file__).parent / 'model' / 'version.gms'

        s = version_file.read_text()

        return '{}.{}.{}'.format(
            re.search('VERSION_MAJOR "(.+?)"', s).group(1),
            re.search('VERSION_MINOR "(.+?)"', s).group(1),
            re.search('VERSION_PATCH "(.+?)"', s).group(1),
        )
Exemplo n.º 4
0
def db_config_path():
    return config.get('DB_CONFIG_PATH')
Exemplo n.º 5
0
def default_dbprops_file():
    return config.get('DEFAULT_DBPROPS_FILE')
Exemplo n.º 6
0
def db_config_path():
    return config.get('DB_CONFIG_PATH')
Exemplo n.º 7
0
def default_dbprops_file():
    return config.get('DEFAULT_DBPROPS_FILE')