Ejemplo n.º 1
0
def test_overwrite_subconfig():
    """Test that subconfig cannot be overwritten"""
    config = Configuration()
    config.nested = Configuration()
    with pytest.raises(ValueError) as exc:
        config.add_option("nested", option_type=str)
    assert "Configuration already contains nested" == str(exc.value)

    with pytest.raises(ValueError) as exc:
        config.nested = Configuration()
    assert "Configuration already contains subconfiguration nested" == str(
        exc.value)
Ejemplo n.º 2
0
def test_help_nested_option():
    """Verify adding documentation to a nested option."""
    config = Configuration()
    config.add_option("option", option_type=str, help="A useless option!")
    config.nested = Configuration()
    config.nested.add_option("option",
                             option_type=str,
                             help="A useless nested option!")

    assert config.help("nested.option") == "A useless nested option!"
    assert config.nested.help("option") == "A useless nested option!"
Ejemplo n.º 3
0
def test_help_nested_option():
    """Verify adding documentation to a nested option."""
    config = Configuration()
    config.add_option('option', option_type=str, help='A useless option!')
    config.nested = Configuration()
    config.nested.add_option('option',
                             option_type=str,
                             help='A useless nested option!')

    assert config.help('nested.option') == 'A useless nested option!'
    assert config.nested.help('option') == 'A useless nested option!'
Ejemplo n.º 4
0
def test_nested_key_curation():
    """Test that both - and _ maps to same options in nested configs as well"""
    config = Configuration()
    config.add_option("test-with-dashes",
                      option_type=str,
                      default="voici_voila")
    config.nested = Configuration()
    config.nested.add_option("test_with_underscores",
                             option_type=str,
                             default="zici")

    assert config["nested"]["test_with_underscores"] == "zici"
    assert config["nested"]["test-with-underscores"] == "zici"

    config["nested"]["test-with-underscores"] = "labas"
    assert config.nested.test_with_underscores == "labas"
Ejemplo n.º 5
0
def test_nested_key_curation():
    """Test that both - and _ maps to same options in nested configs as well"""
    config = Configuration()
    config.add_option('test-with-dashes',
                      option_type=str,
                      default="voici_voila")
    config.nested = Configuration()
    config.nested.add_option('test_with_underscores',
                             option_type=str,
                             default="zici")

    assert config['nested']['test_with_underscores'] == 'zici'
    assert config['nested']['test-with-underscores'] == 'zici'

    config['nested']['test-with-underscores'] = 'labas'
    assert config.nested.test_with_underscores == 'labas'
Ejemplo n.º 6
0
def test_to_dict():
    """Test dictionary representation of the configuration"""
    config = Configuration()
    config.add_option("test", option_type=str, default="voici_voila")
    config.nested = Configuration()
    config.nested.add_option("test2", option_type=str, default="zici")

    assert config.to_dict() == {
        "test": "voici_voila",
        "nested": {
            "test2": "zici"
        }
    }

    config.test = "hello"
    config.nested.test2 = "labas"

    assert config.to_dict() == {"test": "hello", "nested": {"test2": "labas"}}
Ejemplo n.º 7
0
def test_to_dict():
    """Test dictionary representation of the configuration"""
    config = Configuration()
    config.add_option('test', option_type=str, default="voici_voila")
    config.nested = Configuration()
    config.nested.add_option('test2', option_type=str, default="zici")

    assert config.to_dict() == {
        'test': 'voici_voila',
        'nested': {
            'test2': 'zici'
        }
    }

    config.test = 'hello'
    config.nested.test2 = 'labas'

    assert config.to_dict() == {'test': 'hello', 'nested': {'test2': 'labas'}}