示例#1
0
def test_load_config(config0_dir):
    with pytest.raises(IOError):
        config.load_config('nonexistent')

    c = config.load_config(config0_dir)
    DEFAULT = config.default_config()
    assert c['sync'] != DEFAULT['sync']
    assert c['sync']['timeout'] == 60
    assert c['sync']['strip_tz'] == DEFAULT['sync']['strip_tz']
    assert c['sync']['url'] != DEFAULT['sync']['url']
示例#2
0
def test_load_config(config0_dir):
    with pytest.raises(IOError):
        config.load_config("nonexistent")

    c = config.load_config(config0_dir)
    DEFAULT = config.default_config()
    assert c["sync"] != DEFAULT["sync"]
    assert c["sync"]["timeout"] == 60
    assert c["sync"]["strip_tz"] == DEFAULT["sync"]["strip_tz"]
    assert c["sync"]["url"] != DEFAULT["sync"]["url"]
示例#3
0
def check_load_config(config_dir):
    convert = False
    loaded = config.read_config(config_dir) or {}

    if config.detect_old(loaded):
        print(
            "Found config file with pre-0.7 schema; backing up and converting to new format"
        )
        convert = True
        cfg = config.convert_old(loaded)
    else:
        cfg = config.default_config()
        config.recursive_update(cfg, loaded)

    if convert:
        config.write_config(cfg, config_dir, backup_existing=True)
    return cfg
示例#4
0
import os
from peeringdb import config
import pytest

test_dir = os.path.relpath(os.path.dirname(__file__))
default_config = config.default_config()


def test_default_config():
    cfg = config.get_config(None)
    assert default_config == cfg
    assert '__config_dir__' not in cfg


def test_config_dir():
    with pytest.raises(IOError):
        config.get_config('nonexistant')


def test_config0():
    cfg_dir = os.path.join(test_dir, 'data', 'config0')
    cfg = config.get_config(cfg_dir)

    assert cfg_dir == cfg['__config_dir__']

    assert default_config['database'] == cfg['database']
    assert default_config['peeringdb'] != cfg['peeringdb']
    assert 60 == cfg['peeringdb']['timeout']


def test_write_conf():
示例#5
0
import os
from peeringdb import config
import pytest


test_dir = os.path.relpath(os.path.dirname(__file__))
default_config = config.default_config()


def test_default_config():
    cfg = config.get_config(None)
    assert default_config == cfg
    assert '__config_dir__' not in cfg


def test_config_dir():
    with pytest.raises(IOError):
        config.get_config('nonexistant')


def test_config0():
    cfg_dir = os.path.join(test_dir, 'data', 'config0')
    cfg = config.get_config(cfg_dir)

    assert cfg_dir == cfg['__config_dir__']

    assert default_config['database'] == cfg['database']
    assert default_config['peeringdb'] != cfg['peeringdb']
    assert 60 == cfg['peeringdb']['timeout']
示例#6
0
def test_write():
    with TemporaryDirectory() as td:
        DEFAULT = config.default_config()
        config.write_config(DEFAULT, td)
示例#7
0
def test_default_config():
    DEFAULT = config.default_config()
    with TemporaryDirectory() as path:
        cfg = config.load_config(path)
    assert DEFAULT == cfg