def test_load_file(type, path):
    c = CatConfig(format=type)
    c.load_from_file(path)
    assert c.foo == 'bar'

    c = CatConfig()
    c.load_from_file(path, format=type)
    assert c.foo == 'bar'

    c = CatConfig(data={'previous_key': 'val'})
    c.load_from_file(path, format=type)
    assert c.previous_key == 'val'
예제 #2
0
# Load
# Load config from string
c = CatConfig()
c.load_from_string("""
{
    "foo": "bar"
}
""")
# Load config when initalizing CatConfig object
c = CatConfig(data={
    'foo': 'bar'
})
# load config from file
c = CatConfig()
c.load_from_file('./tests/assests/test.json')
# Specify config type when initalizing CatConfig object
c = CatConfig(format='json')
c.load_from_file('./tests/assests/test.json')
# Specify config type when loading config file
c = CatConfig()
c.load_from_file('./tests/assests/test.json', format='json')

# Get item
print(c.foo)
# Print: bar
print(bool(c.some.value.does.nt.exists))
# Print: False
print(c['foo'])
# Print: bar