def test_iterate(): c = OmegaConf.from_string(''' a : 1 b : 2 ''') m2 = {} for k in c: m2[k] = c[k] assert m2 == c
def test_merge_from_2(): a = OmegaConf.empty() a.inner = {} b = OmegaConf.from_string(''' a : 1 b : 2 ''') a.inner.merge_from(b) assert a.inner == b
def test_pickle(): with tempfile.TemporaryFile() as fp: s = 'a: b' import pickle c = OmegaConf.from_string(s) pickle.dump(c, fp) fp.flush() fp.seek(0) c1 = pickle.load(fp) assert c == c1
def test_items(): c = OmegaConf.from_string(''' a: v: 1 b: v: 1 ''') for k, v in c.items(): v.v = 2 assert c.a.v == 2 assert c.b.v == 2
def test_pretty(): c = OmegaConf.from_string(''' hello: world list: [ 1, 2 ] ''') expected = '''hello: world list: - 1 - 2 ''' assert expected == c.pretty()
def test_items(): c = OmegaConf.from_string('{a: 2, b: 10}') assert {'a': 2, 'b': 10}.items() == c.items()
def test_getattr(): c = OmegaConf.from_string('a: b') assert 'b' == c.a
def test_scientific_number(): c = OmegaConf.from_string('a: 10e-3') assert 10e-3 == c.a
def test_with_default(): s = '{hello: {a : 2}}' c = OmegaConf.from_string(s) assert c.get('missing', 4) == 4 assert c.hello.get('missing', 5) == 5 assert {'hello': {'a': 2}} == c
def test_repr(): c = OmegaConf.from_string('a: b') assert "{'a': 'b'}" == repr(c)
def test_merge4(): # replaces a map with an element c1 = OmegaConf.from_string('{b: {c: 1}}') c2 = OmegaConf.from_string('{b: 1}') c3 = OmegaConf.merge(c1, c2) assert {'b': 1} == c3
def test_update_value_to_map(): s = 'hello' c = OmegaConf.from_string(s) c.update('hi', 'there') assert {'hello': None, 'hi': 'there'} == c
def test_update_same_value(): """""" s = 'hello' c = OmegaConf.from_string(s) c.update('hello') assert {'hello': None} == c
def test_list_value_update(): # List update is always a replace because a list can be merged in too many ways c = OmegaConf.from_string('a: [1,2]') c.update('a', [2, 3, 4]) assert {'a': [2, 3, 4]} == c
def test_mandatory_value(): c = OmegaConf.from_string('{a: "???"}') with raises(MissingMandatoryValue): c.get('a')
def test_list_value(): c = OmegaConf.from_string('a: [1,2]') assert {'a': [1, 2]} == c
def test_key_map(): """Test a key to map""" s = '{hello: {a : 2}}' c = OmegaConf.from_string(s) assert {'hello': {'a': 2}} == c
def test_is_empty(): c = OmegaConf.from_string('a: b') assert not c.is_empty() c = OmegaConf.empty() assert c.is_empty()
def test_dir(): c = OmegaConf.from_string('a: b') assert ['a'] == dir(c)
def test_update__map_value(): # Replacing an existing key in a map s = 'hello: world' c = OmegaConf.from_string(s) c.update('hello', 'there') assert {'hello': 'there'} == c
def test_3way_merge(): c1 = OmegaConf.from_string('{a: 1, b: 2}') c2 = OmegaConf.from_string('{b: 3}') c3 = OmegaConf.from_string('{a: 2, c: 3}') c4 = OmegaConf.merge(c1, c2, c3) assert {'a': 2, 'b': 3, 'c': 3} == c4
def test_update_map_to_value(): # changing map to single node s = 'hello: world' c = OmegaConf.from_string(s) c.update('value') assert {'hello': 'world', 'value': None} == c
def test_empty_input(): """Test empty input""" s = '' c = OmegaConf.from_string(s) assert c == {}
def test_getattr_dict(): c = OmegaConf.from_string('a: {b: 1}') assert {'b': 1} == c.a
def test_update_map_empty_to_map(): s = '' c = OmegaConf.from_string(s) c.update('hello', 'there') assert {'hello': 'there'} == c
def test_override_mandatory_value(): c = OmegaConf.from_string('{a: "???"}') with raises(MissingMandatoryValue): c.get('a') c.update('a', 123) assert {'a': 123} == c
def test_update_map_new_keyvalue(): # Adding another key to a map s = 'hello: world' c = OmegaConf.from_string(s) c.update('who', 'goes there') assert {'hello': 'world', 'who': 'goes there'} == c
def test_subscript_get(): c = OmegaConf.from_string('a: b') assert 'b' == c['a']
def test_create_from_string__deprecated(): s = 'hello: world' c = OmegaConf.from_string(s) assert {'hello': 'world'} == c
def test_merge3(): # replaces an element with a map c1 = OmegaConf.from_string('{a: 1, b: 2}') c2 = OmegaConf.from_string('{b: {c: 3}}') c3 = OmegaConf.merge(c1, c2) assert {'a': 1, 'b': {'c': 3}} == c3