示例#1
0
def test_local_conf_with_both_slashconf_file_and_dir(tmpdir):
    with tmpdir.join('slashconf.py').open('w') as f:
        f.write("x = 1")
    conf_dir = tmpdir.join("slashconf")
    conf_dir.mkdir()
    with tmpdir.join('slashconf.py').open('w') as f:
        f.write("y = 2")
    local_config = LocalConfig()
    with pytest.raises(AssertionError) as caught:
        local_config.push_path(str(tmpdir))
    assert str(tmpdir) in str(caught.value)
示例#2
0
def test_local_conf_with_slashconf_dir(tmpdir):
    conf_dir = tmpdir.join("slashconf")
    conf_dir.mkdir()
    with conf_dir.join('some_file.py').open('w') as f:
        f.write("x = 42")
    with conf_dir.join("other_file.py").open("w") as f:
        f.write("a = 1\n")
        f.write("b = 2")
    with conf_dir.join("__init__.py").open("w") as f:
        f.write("import slash\n")
        f.write("c = 1")
    local_config = LocalConfig()
    local_config.push_path(str(tmpdir))
    expected = {"a": 1, "b": 2, "c": 1, "x": 42, "slash": slash}
    config_dict = local_config.get_dict()
    got = {key: config_dict.get(key, NOTHING) for key in expected}
    assert expected == got
示例#3
0
def test_local_conf_loading_multiple_times(local_conf_dir, expected_dict):
    items = list(iteritems(expected_dict))
    local_conf = LocalConfig()

    local_conf.push_path(str(local_conf_dir.join('..')))
    var_name, var_value = items[0]
    var = local_conf.get_dict()[var_name]
    assert var == [var_value]

    local_conf.push_path(str(local_conf_dir))

    assert var is local_conf.get_dict()[var_name]
示例#4
0
def test_local_conf_loading_multiple_times(local_conf_dir, expected_dict):
    items = list(iteritems(expected_dict))
    local_conf = LocalConfig()

    local_conf.push_path(str(local_conf_dir.join('..')))
    var_name, var_value = items[0]
    var = local_conf.get_dict()[var_name]
    assert var == [var_value]

    local_conf.push_path(str(local_conf_dir))

    assert var is local_conf.get_dict()[var_name]
示例#5
0
def local_conf(local_conf_dir):
    returned = LocalConfig()
    returned.push_path(str(local_conf_dir))
    return returned
示例#6
0
def test_local_conf_nonexistent_dir():
    with pytest.raises(RuntimeError):
        LocalConfig().push_path('/nonexistent/dir')
示例#7
0
def local_conf(local_conf_dir):
    returned = LocalConfig()
    returned.push_path(str(local_conf_dir))
    return returned