test_config_files.py 文件源码

python
阅读 22 收藏 0 点赞 0 评论 0

项目:artemis 作者: QUVA-Lab 项目源码 文件源码
def test_get_config_value():

    config_path = get_config_path('.testconfigrc')

    if os.path.exists(config_path):
        os.remove(config_path)

    value = get_config_value(config_filename='.testconfigrc', section='opts', option='setting1', default_generator=lambda: 'somevalue', write_default=True)
    assert value == 'somevalue'

    value = get_config_value(config_filename='.testconfigrc', section='opts', option='setting1', default_generator=lambda: 'someothervalue', write_default=True)
    assert value == 'somevalue'

    value = get_config_value(config_filename='.testconfigrc', section='opts', option='setting2', default_generator=lambda: 'blah', write_default=True)
    assert value == 'blah'

    value = get_config_value(config_filename='.testconfigrc', section='opts', option='setting1')
    assert value == 'somevalue'

    value = get_config_value(config_filename='.testconfigrc', section='opts', option='setting2')
    assert value == 'blah'

    with raises(NoSectionError):
        _ = get_config_value(config_filename='.testconfigrc', section='schmopts', option='setting3')

    with raises(NoOptionError):
        _ = get_config_value(config_filename='.testconfigrc', section='opts', option='setting3')

    with raises(AssertionError):
        _ = get_config_value(config_filename='.testconfigXXXrc', section='opts', option='setting3')

    set_non_persistent_config_value(config_filename='.testconfigrc', section='opts', option='setting2',value="bob")
    value = get_config_value(config_filename='.testconfigrc', section='opts', option='setting2')
    assert value == 'bob'

    value = get_config_value(config_filename='.testconfigrc', section='opts', option='setting2', use_cashed_config=False)
    assert value == 'blah'

    value = get_config_value(config_filename='.testconfigrc', section='opts', option='setting2')
    assert value == 'bob'

    set_non_persistent_config_value(config_filename='.testconfigrc', section='schmapts', option='setting2', value="bob")
    with raises(NoOptionError):
        _ = get_config_value(config_filename='.testconfigrc', section='schmapts', option='setting3')

    with raises(NoSectionError):
        _ = get_config_value(config_filename='.testconfigrc', section='schmapts', option='setting2', use_cashed_config=False)

    value = get_config_value(config_filename='.testconfigrc', section='schmapts', option='setting2')
    assert value == 'bob'

    os.remove(config_path)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号