How to use the orion.core.io.config.Configuration function in orion

To help you get started, we’ve selected a few orion examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Epistimio / orion / tests / unittests / core / io / test_config.py View on Github external
def test_local_precedence(yaml_path):
    """Test local setting has precedence over env var values"""
    config = Configuration()
    config.add_option('test', option_type=str, default="voici_voila", env_var="TOP_SECRET_MESSAGE")
    assert config.test == "voici_voila"

    config.load_yaml(yaml_path)
    assert config.test == "from my yaml!"

    os.environ['TOP_SECRET_MESSAGE'] = 'coussi_coussa'
    assert config.test == "coussi_coussa"

    config.test = "comme_ci_comme_ca"
    assert config.test == "comme_ci_comme_ca"

    del os.environ['TOP_SECRET_MESSAGE']
github Epistimio / orion / tests / unittests / core / io / test_config.py View on Github external
def test_set_value_of_subconfig_directly():
    """Test that we can access subconfig and set value directly"""
    config = Configuration()
    config.sub = Configuration()
    config.sub.add_option('test', option_type=str)

    with pytest.raises(ConfigurationError):
        config.test

    config.sub.test = "1"
    assert config.sub.test == "1"
    config.sub.test = 1
    assert config.sub.test == "1"
github Epistimio / orion / tests / unittests / core / io / test_config.py View on Github external
def test_set_subconfig():
    """Test that setting a subconfig works"""
    config = Configuration()
    config.test = Configuration()

    assert isinstance(config.test, Configuration)

    with pytest.raises(ConfigurationError):
        config.test.voici_voila
github Epistimio / orion / tests / unittests / core / io / test_config.py View on Github external
def test_set_subconfig():
    """Test that setting a subconfig works"""
    config = Configuration()
    config.test = Configuration()

    assert isinstance(config.test, Configuration)

    with pytest.raises(ConfigurationError):
        config.test.voici_voila
github Epistimio / orion / tests / unittests / core / io / test_config.py View on Github external
def test_set_int_value():
    """Test that an integer option can have its value set"""
    config = Configuration()
    config.add_option('test', option_type=int)

    with pytest.raises(ConfigurationError) as exc:
        config.test

    config.test = 1
    assert config.test == 1
    config.test = "1"
    assert config.test == 1
    with pytest.raises(TypeError) as exc:
        config.test = "voici_voila"
    assert " cannot be set to voici_voila with type " in str(exc.value)
github Epistimio / orion / tests / unittests / core / io / test_config.py View on Github external
def test_set_invalid_subconfig_value_like_dict():
    """Test that deep keys cannot be set if subconfig does not exist"""
    config = Configuration()
    with pytest.raises(BaseException) as exc:
        config['sub.test'] = "1"
    assert 'Configuration does not have an attribute \'sub\'.' in str(exc.value)
github Epistimio / orion / tests / unittests / core / io / test_config.py View on Github external
def test_set_non_existing_option():
    """Test that setting a non existing option crash"""
    config = Configuration()
    with pytest.raises(TypeError) as exc:
        config.test = 1
    assert "Can only set test as a Configuration, not " in str(exc.value)
github Epistimio / orion / src / orion / core / __init__.py View on Github external
def define_worker_config(config):
    """Create and define the fields of the worker configuration."""
    worker_config = Configuration()

    worker_config.add_option(
        'heartbeat', option_type=int, default=120)
    worker_config.add_option(
        'max_broken', option_type=int, default=3)
    worker_config.add_option(
        'max_idle_time', option_type=int, default=60)

    config.worker = worker_config
github Epistimio / orion / src / orion / core / __init__.py View on Github external
def define_config():
    """Create and define the fields of the configuration object."""
    config = Configuration()
    define_database_config(config)
    define_worker_config(config)

    config.add_option(
        'user_script_config', option_type=str, default='config')

    return config