def test_json(): config_file = tempfile.NamedTemporaryFile(suffix='.json') sonata_cfg = { 'manifest': { '$BASE': '${configdir}', '$TMP_ATTR': 'mytest' }, 'myvar': '$TMP_ATTR/myvar', 'cwd': '${workingdir}', 'cdir': '${configdir}', 'cfname': '${configfname}' } json.dump(sonata_cfg, open(config_file.name, 'w')) config_dict = SonataConfig.from_json(config_file.name) assert (isinstance(config_dict, SonataConfig)) assert (isinstance(config_dict, dict)) assert (config_dict['myvar'] == 'mytest/myvar') assert (config_dict['cwd'] == os.getcwd()) assert (config_dict['cdir'] == os.path.dirname(config_file.name)) assert (config_dict['cfname'] == config_file.name) config_dict = SonataConfig.load(config_file.name) assert (isinstance(config_dict, SonataConfig)) assert (isinstance(config_dict, dict)) assert (config_dict['myvar'] == 'mytest/myvar') assert (config_dict['cwd'] == os.getcwd()) assert (config_dict['cdir'] == os.path.dirname(config_file.name)) assert (config_dict['cfname'] == config_file.name) with pytest.warns(DeprecationWarning): config_dict = from_json(config_file.name) assert (isinstance(config_dict, SonataConfig)) assert (isinstance(config_dict, dict)) assert (config_dict['myvar'] == 'mytest/myvar') assert (config_dict['cwd'] == os.getcwd()) assert (config_dict['cdir'] == os.path.dirname(config_file.name)) assert (config_dict['cfname'] == config_file.name)
def test_dict(): sonata_dict = { 'manifest': { '$BASE': '${configdir}', '$TMP_ATTR': 'mytest' }, 'myvar': '$TMP_ATTR/myvar' } config_dict = SonataConfig.from_dict(sonata_dict) assert (isinstance(config_dict, SonataConfig)) assert (isinstance(config_dict, dict)) assert (config_dict['myvar'] == 'mytest/myvar') config_dict = SonataConfig.load(sonata_dict) assert (isinstance(config_dict, SonataConfig)) assert (isinstance(config_dict, dict)) assert (config_dict['myvar'] == 'mytest/myvar') config_dict = from_dict(sonata_dict) assert (isinstance(config_dict, SonataConfig)) assert (isinstance(config_dict, dict)) assert (config_dict['myvar'] == 'mytest/myvar')