예제 #1
0
def test_to_dict_with_single_map():
    s = Settings({
        "outer": {
            "inner": "foo",
        },
    })

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

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

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

    assert s.get('outer.inner') == 'foo'
예제 #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
예제 #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
예제 #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'
예제 #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"
예제 #9
0
def test_to_dict_with_override():
    s = Settings({
        'outer': {
            'inner': 'override',
        },
    }, {
        'outer': {
            'inner': 'hidden',
        },
    })

    assert s.to_dict() == {'outer': {'inner': 'override'}}
예제 #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"}}
예제 #11
0
def test_to_dict_with_override():
    s = Settings({
        "outer": {
            "inner": "override",
        },
    }, {
        "outer": {
            "inner": "hidden",
        },
    })

    assert s.to_dict() == {"outer": {"inner": "override"}}
예제 #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'}}
예제 #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'}}
예제 #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"}}
예제 #15
0
def test_getitem_drills_through_dots():
    s = Settings({
        "outer": {
            "inner": "foo",
        },
    })

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

    assert s['outer.inner'] == 'foo'
예제 #17
0
def test_get_with_missing_key_returns_default():
    s = Settings()

    assert s.get('foo', default='bar') == 'bar'
예제 #18
0
def test_getitem_with_missing_key_raises_missing_setting():
    s = Settings()

    with pytest.raises(htmap.exceptions.MissingSetting):
        s['foo']
예제 #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}
예제 #20
0
def test_nested_settings_not_equal():
    s1 = Settings({'outer': {'inner': 'foo'}})
    s2 = Settings({'outer': {'inner': 'bar'}})

    assert s1 != s2
예제 #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
예제 #22
0
def test_empty_settings_equal():
    s1 = Settings()
    s2 = Settings()

    assert s1 == s2
    assert s1 is not s2
예제 #23
0
def test_two_maps_in_constructor():
    s = Settings({}, {})

    assert len(s.maps) == 2
예제 #24
0
def test_no_args_makes_emtpy_settings():
    s = Settings()

    assert len(s.maps) == 1
    assert s.maps[0] == {}
예제 #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}
예제 #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
예제 #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'
예제 #28
0
def test_append_with_dict():
    s = Settings({'foo': 'override'})
    s.append({'foo': 'hidden'})

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

    assert s1 != s2
예제 #30
0
def test_get_with_missing_key_returns_default():
    s = Settings()

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