Ejemplo n.º 1
0
def test_with_config_instantiation():
    try:
        embed = Config({'spam': 'eggs'})
        config = Config({'brian': embed})
    except Exception:
        assert False, "Instantiation With Config Failed"
    assert config.brian.spam == 'eggs', "Instantiation With Config Failed"
Ejemplo n.º 2
0
def test_toArray_config():
    config = Config({'life': 'brian', 'spam': {'ham': 'rabbit'}})
    assert {
        'life': 'brian',
        'spam': {
            'ham': 'rabbit'
        }
    } == config.toArray(), "Config toArray Not Working"
Ejemplo n.º 3
0
def test_iter_config():
    testagainst = {}
    config = Config({'life': 'brian', 'spam': 'eggs'})
    for key, value in config:
        testagainst[key] = value
    assert {
        'life': 'brian',
        'spam': 'eggs'
    } == testagainst, "Config __iter__ Not Working"
Ejemplo n.º 4
0
def test_itemmethods_config():
    config = Config({
        'life': 'brian',
        'spam': {
            'ham': 'rabbit'
        }
    },
                    allowModifications=True)
    assert config['life'] == 'brian', "Config __getitem__ Not Working"
    config['spam']['ham'] = 'eggs'
    assert config['spam']['ham'] == 'eggs', "Config __setitem__ Not Working"
    del config['life']
    assert {
        'spam': {
            'ham': 'eggs'
        }
    } == config.toArray(), "Config __delitem__ Not Working"

    config.setReadOnly()
    with pytest.raises(RuntimeException):
        config['spam']['ham'] = 'foo'
    with pytest.raises(InvalidArgumentException):
        del config['spam']
Ejemplo n.º 5
0
def test_methods_abstractwriter():
    writer = AbstractWriter()
    conf = Config({})

    assert isinstance(
        writer,
        WriterInterface), "AbstractWriter not instance of WriterInterface"

    with pytest.raises(RuntimeException):
        writer.toFile(
            os.path.join(os.path.dirname(os.path.realpath(__file__)), "test"),
            conf)
    with pytest.raises(RuntimeException):
        writer.toString(conf)

    os.remove(os.path.join(os.path.dirname(os.path.realpath(__file__)),
                           "test"))
Ejemplo n.º 6
0
def test_merge_config():
    config = Config({'life': 'brian', 'spam': {'ham': 'rabbit'}})
    merge = Config({'life': 'meaning', 'spam': {'ham': 'killer', 'new': 'ni'}})
    config.merge(merge)
    assert isinstance(config.spam, Config), "Config merge Not Working"
    assert {
        'life': 'meaning',
        'spam': {
            'ham': 'killer',
            'new': 'ni'
        }
    } == config.toArray(), "Config merge Not Working"
Ejemplo n.º 7
0
def test_replacewithconfig_token():
    conf = {
        "webhost": "www.example.com",
        "database": {
            "adapter": "DBADAPTER",
            "params": {
                "host": "DBHOST",
                "username": "******",
                "password": "******",
                "dbname": "dbproduction"
            }
        }
    }

    config = Config(conf, True)
    token = Token({"DBHOST": "db.example.com", "DBADAPTER": "pdo_mysql"})
    assert config.database.params.host == "DBHOST", "Failed Config construction"
    assert config.database.adapter == "DBADAPTER", "Failed Config construction"
    token.process(config)
    assert config.database.params.host == "db.example.com", "Failed Config token replacement"
    assert config.database.adapter == "pdo_mysql", "Failed Config token replacement"
Ejemplo n.º 8
0
def test_len_config():
    config = Config({'life': 'brian', 'spam': 'eggs'})
    assert len(config) == 2, "Config __len__ Not Working"
Ejemplo n.º 9
0
def test_setattr_getattr_config():
    config = Config({}, allowModifications=True)
    config.spam = 'eggs'
    assert config.spam == 'eggs', "Config __setattr__/__getattr__ Not Working"
Ejemplo n.º 10
0
def test_copy_config():
    l = [1, 2, 3, 4, 5]
    firstconfig = Config({'l': l})
    secondconfig = firstconfig.copy()
    l[0] = 6
    assert secondconfig.l[0] == 1, "Config Not Deep Copied"
Ejemplo n.º 11
0
def test_improper_instantiation():
    with pytest.raises(InvalidArgumentException):
        config = Config(['not', 'a', 'dictionary'])
Ejemplo n.º 12
0
def test_normal_instantiation():
    try:
        config = Config({'spam': 'eggs'})
    except Exception:
        assert False, "Dictionary Instantiation Failed"
Ejemplo n.º 13
0
def test_isReadOnly_config():
    config = Config({'life': 'brian', 'spam': {'ham': 'rabbit'}})
    assert config.isReadOnly(), "Config isReadOnly Not Working"
Ejemplo n.º 14
0
def test_empty_instantiation():
    try:
        config = Config({})
    except Exception:
        assert False, "Empty Dictionary Instantiation Failed"