コード例 #1
0
def test_xml_content(fs):
    '''Test XML content read.'''
    fs.add_real_file(xml_filepath)
    cfg = ConfigFile(name='tests')
    cfg.load(filepath=xml_filepath)
    assert cfg.retrieve('/root/stooges/stooge1') == 'Larry'
    assert cfg.retrieve('/root/stooges/stooge2') == 'Curly'
    assert cfg.retrieve('/root/stooges/stooge3') == 'Moe'
    assert cfg.retrieve('/root/fruit') != 'banana'
    assert cfg.retrieve('/root/number') == '2'
コード例 #2
0
ファイル: test_json.py プロジェクト: kuwv/python-compendium
def test_cfg(fs):
    '''Test loading JSON configuration.'''
    fs.add_real_file(json_filepath)
    cfg = ConfigFile(name='tests')
    cfg.load(filepath=json_filepath)
    assert cfg.retrieve('/stooges/stooge1') == 'Larry'
    assert cfg.retrieve('/stooges/stooge2') == 'Curly'
    assert cfg.retrieve('/stooges/stooge3') == 'Moe'
    assert cfg.retrieve('/fruit') != 'banana'
    assert cfg.retrieve('/number') == 2
コード例 #3
0
ファイル: test_ini.py プロジェクト: kuwv/python-compendium
def test_ini_content(fs):
    '''Test TOML content load.'''
    fs.add_real_file(ini_filepath)
    cfg = ConfigFile(name='tests')
    cfg.load(filepath=ini_filepath)
    assert cfg.retrieve('/stooges/stooge1') == 'Larry'
    assert cfg.retrieve('/stooges/stooge2') == 'Curly'
    assert cfg.retrieve('/stooges/stooge3') == 'Moe'
    assert cfg.retrieve('/fruit') == 'apple'
    assert int(cfg.retrieve('/number')) == 2
コード例 #4
0
ファイル: test_yaml.py プロジェクト: kuwv/python-compendium
def test_yaml_content(fs):
    '''Test read YAML content.'''
    fs.add_real_file(yaml_filepath)
    cfg = ConfigFile(name='tests')
    cfg.load(filepath=yaml_filepath)
    assert cfg.retrieve('/stooges/stooge1') == 'Larry'
    assert cfg.retrieve('/stooges/stooge2') == 'Curly'
    assert cfg.retrieve('/stooges/stooge3') == 'Moe'
    assert cfg.retrieve('/fruit') != 'banana'
    assert cfg.retrieve('/number') == 2
コード例 #5
0
def test_toml_content_update(fs):
    '''Test content update.'''
    fs.add_real_file(settings_filepath, False)
    cfg = ConfigFile(name='tests', writable=True)
    cfg.load(filepath=settings_filepath)
    cfg.set('/owner/name', 'Tom Waits')
    assert cfg.retrieve('/owner/name') == 'Tom Waits'
コード例 #6
0
def test_toml_content_append(fs):
    '''Test appending settings to list.'''
    fs.add_real_file(settings_filepath, False)
    cfg = ConfigFile(name='tests')
    cfg.load(filepath=settings_filepath)
    cfg.append('/database/ports', 2345)
    assert 2345 in cfg.retrieve('/database/ports')
コード例 #7
0
def test_toml_content_create(fs):
    '''Test content creation settings.'''
    fs.add_real_file(settings_filepath, False)
    cfg = ConfigFile(name='tests')
    cfg.load(filepath=settings_filepath)
    cfg.create('/test', 'test')
    assert cfg.retrieve('test') == 'test'
コード例 #8
0
ファイル: test_json.py プロジェクト: kuwv/python-compendium
def test_cfg_dump(fs):
    '''Test saving JSON content.'''
    fs.add_real_file(json_filepath, False)
    cfg = ConfigFile(name='tests', writable=True)
    cfg.load(filepath=json_filepath)
    cfg.create('/test', 'test')
    assert cfg.retrieve('test') == 'test'
コード例 #9
0
def test_xml_content_dump(fs):
    '''Test XML content save.'''
    fs.add_real_file(xml_filepath, False)
    cfg = ConfigFile(name='tests', writable=True)
    cfg.load(filepath=xml_filepath)
    cfg.create('/root/test', 'test')
    assert cfg.retrieve('/root/test') == 'test'
コード例 #10
0
ファイル: test_toml.py プロジェクト: kuwv/python-compendium
def test_toml_content_dump(fs):
    '''Test TOML content save.'''
    fs.add_real_file(toml_filepath, False)
    cfg = ConfigFile(name='tests', writable=True)
    cfg.load(filepath=toml_filepath)
    cfg.create('/test', 'test')
    # TODO where is save happening :/
    assert cfg.retrieve('test') == 'test'
コード例 #11
0
import os
from compendium.loader import ConfigFile
from compendium.filetypes.ini import IniConfig
from pprint import pprint

basepath = os.path.dirname(os.path.realpath(__file__))
filepath = os.path.join(basepath, '.example')

assert os.path.exists(filepath) is True
assert os.path.isfile(filepath) is True

cfg = ConfigFile(filepath=filepath, filetype='yaml')
cfg.load()
print('settings', cfg)

assert 'sre' in cfg.retrieve('/allowed_roles')
assert 'devops' in cfg.retrieve('/allowed_roles')
assert 'cloudops' in cfg.retrieve('/allowed_roles')

pypirc_filepath = os.path.join(os.path.expanduser('~'), '.pypirc')

assert os.path.exists(pypirc_filepath) is True
assert os.path.isfile(pypirc_filepath) is True

# pypirc = ConfigFile(pypirc_filepath, filetype='ini')
# pypirc.load()
# print('pypi', type(pypirc))

pypirc = IniConfig()
p = pypirc.load_config(pypirc_filepath)
pprint(p)