Esempio n. 1
0
def test_to_dict_with_single_map():
    s = Settings({
        "outer": {
            "inner": "foo",
        },
    })

    assert s.to_dict() == {"outer": {"inner": "foo"}}
Esempio n. 2
0
def test_get_drills_through_dots():
    s = Settings({
        "outer": {
            "inner": "foo",
        },
    })

    assert s.get("outer.inner") == "foo"
Esempio n. 3
0
def test_to_dict_with_single_map():
    s = Settings({
        'outer': {
            'inner': 'foo',
        },
    })

    assert s.to_dict() == {'outer': {'inner': 'foo'}}
Esempio n. 4
0
def test_get_drills_through_dots():
    s = Settings({
        'outer': {
            'inner': 'foo',
        },
    })

    assert s.get('outer.inner') == 'foo'
Esempio n. 5
0
def test_can_load_saved_settings(tmpdir):
    s = Settings({'foo': 'bar'})

    file = tmpdir.join('foo.toml')
    s.save(file)

    loaded = Settings.load(file)

    assert loaded == s
    assert loaded is not s
Esempio n. 6
0
def test_can_load_saved_settings(tmpdir):
    s = Settings({"foo": "bar"})

    file = tmpdir.join("foo.toml")
    s.save(file)

    loaded = Settings.load(file)

    assert loaded == s
    assert loaded is not s
Esempio n. 7
0
def test_replace():
    s = Settings({'foo': 'bar'})

    new = Settings({'zing': 'zang'})

    s.replace(new)

    assert s.maps == new.maps
    with pytest.raises(htmap.exceptions.MissingSetting):
        s['foo']
    assert s['zing'] == 'zang'
Esempio n. 8
0
def test_replace():
    s = Settings({"foo": "bar"})

    new = Settings({"zing": "zang"})

    s.replace(new)

    assert s.maps == new.maps
    with pytest.raises(htmap.exceptions.MissingSetting):
        s["foo"]
    assert s["zing"] == "zang"
Esempio n. 9
0
def test_to_dict_with_override():
    s = Settings({
        'outer': {
            'inner': 'override',
        },
    }, {
        'outer': {
            'inner': 'hidden',
        },
    })

    assert s.to_dict() == {'outer': {'inner': 'override'}}
Esempio n. 10
0
def test_to_dict_with_no_overlap():
    s = Settings({
        "outer": {
            "top": "this",
        },
    }, {
        "outer": {
            "bottom": "that",
        },
    })

    assert s.to_dict() == {"outer": {"top": "this", "bottom": "that"}}
Esempio n. 11
0
def test_to_dict_with_override():
    s = Settings({
        "outer": {
            "inner": "override",
        },
    }, {
        "outer": {
            "inner": "hidden",
        },
    })

    assert s.to_dict() == {"outer": {"inner": "override"}}
Esempio n. 12
0
def test_to_dict_with_no_overlap():
    s = Settings({
        'outer': {
            'top': 'this',
        },
    }, {
        'outer': {
            'bottom': 'that',
        },
    })

    assert s.to_dict() == {'outer': {'top': 'this', 'bottom': 'that'}}
Esempio n. 13
0
def test_setitem_creates_new_nested_path_when_path_doesnt_exist():
    s = Settings()

    s['foo.bar'] = 'zoo'

    assert s['foo.bar'] == 'zoo'
    assert s.maps[0] == {'foo': {'bar': 'zoo'}}
Esempio n. 14
0
def test_setitem_creates_new_nested_path_when_path_doesnt_exist():
    s = Settings()

    s["foo.bar"] = "zoo"

    assert s["foo.bar"] == "zoo"
    assert s.maps[0] == {"foo": {"bar": "zoo"}}
Esempio n. 15
0
def test_getitem_drills_through_dots():
    s = Settings({
        "outer": {
            "inner": "foo",
        },
    })

    assert s["outer.inner"] == "foo"
Esempio n. 16
0
def test_getitem_drills_through_dots():
    s = Settings({
        'outer': {
            'inner': 'foo',
        },
    })

    assert s['outer.inner'] == 'foo'
Esempio n. 17
0
def test_get_with_missing_key_returns_default():
    s = Settings()

    assert s.get('foo', default='bar') == 'bar'
Esempio n. 18
0
def test_getitem_with_missing_key_raises_missing_setting():
    s = Settings()

    with pytest.raises(htmap.exceptions.MissingSetting):
        s['foo']
Esempio n. 19
0
def test_nested_dicts_are_not_hidden_by_set():
    s = Settings({"top": {"hidden": 0}})

    s["top.new"] = 5

    assert s["top"] == {"hidden": 0, "new": 5}
Esempio n. 20
0
def test_nested_settings_not_equal():
    s1 = Settings({'outer': {'inner': 'foo'}})
    s2 = Settings({'outer': {'inner': 'bar'}})

    assert s1 != s2
Esempio n. 21
0
def test_nested_settings_equal():
    s1 = Settings({'outer': {'inner': 'foo'}})
    s2 = Settings({'outer': {'inner': 'foo'}})

    assert s1 == s2
    assert s1 is not s2
Esempio n. 22
0
def test_empty_settings_equal():
    s1 = Settings()
    s2 = Settings()

    assert s1 == s2
    assert s1 is not s2
Esempio n. 23
0
def test_two_maps_in_constructor():
    s = Settings({}, {})

    assert len(s.maps) == 2
Esempio n. 24
0
def test_no_args_makes_emtpy_settings():
    s = Settings()

    assert len(s.maps) == 1
    assert s.maps[0] == {}
Esempio n. 25
0
def test_nested_dicts_are_not_hidden_by_set():
    s = Settings({'top': {'hidden': 0}})

    s['top.new'] = 5

    assert s['top'] == {'hidden': 0, 'new': 5}
Esempio n. 26
0
def test_nested_settings_equal():
    s1 = Settings({"outer": {"inner": "foo"}})
    s2 = Settings({"outer": {"inner": "foo"}})

    assert s1 == s2
    assert s1 is not s2
Esempio n. 27
0
def test_prepend_with_settings():
    s = Settings({'foo': 'hidden'})
    s.prepend(Settings({'foo': 'override'}))

    assert len(s.maps) == 2
    assert s['foo'] == 'override'
Esempio n. 28
0
def test_append_with_dict():
    s = Settings({'foo': 'override'})
    s.append({'foo': 'hidden'})

    assert len(s.maps) == 2
    assert s['foo'] == 'override'
Esempio n. 29
0
def test_nested_settings_not_equal():
    s1 = Settings({"outer": {"inner": "foo"}})
    s2 = Settings({"outer": {"inner": "bar"}})

    assert s1 != s2
Esempio n. 30
0
def test_get_with_missing_key_returns_default():
    s = Settings()

    assert s.get("foo", default="bar") == "bar"