def test_tree_coerce_dict(): d, s = {}, 'test' assert ConfigTree._coerce(d, s) == (d, s) d, s = {'key': 'val'}, 'test' assert ConfigTree._coerce(d, s) == (d, s) d = { 'key1': { 'sub_key1': ['val', 'val', 'val'], 'sub_key2': 'val' }, 'key2': 'val' } s = 'test' assert ConfigTree._coerce(d, s) == (d, s)
def test_tree_coerce_yaml(tmpdir): d = '''\ key1: sub_key1: - val - val - val sub_key2: [val, val] key2: val''' r = { 'key1': { 'sub_key1': ['val', 'val', 'val'], 'sub_key2': ['val', 'val'] }, 'key2': 'val' } s = 'test' p = tmpdir.join('model_spec.yaml') with p.open('w') as f: f.write(d) assert ConfigTree._coerce(str(p), s) == (r, s) assert ConfigTree._coerce(str(p), None) == (r, str(p))
def test_tree_coerce_str(): d = '''''' s = 'test' assert ConfigTree._coerce(d, s) == (None, s) d = '''\ key: val''' assert ConfigTree._coerce(d, s) == ({'key': 'val'}, s) d = '''\ key1: sub_key1: - val - val - val sub_key2: val key2: val''' r = { 'key1': { 'sub_key1': ['val', 'val', 'val'], 'sub_key2': 'val' }, 'key2': 'val' } assert ConfigTree._coerce(d, s) == (r, s) d = '''\ key1: sub_key1: [val, val, val] sub_key2: val key2: val''' r = { 'key1': { 'sub_key1': ['val', 'val', 'val'], 'sub_key2': 'val' }, 'key2': 'val' } assert ConfigTree._coerce(d, s) == (r, s)