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'
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
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
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
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'
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')
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'
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'
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'
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'
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)