test_config.py 文件源码

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

项目:two1-python 作者: 21dotco 项目源码 文件源码
def test_save_config():
    """Test Config object can save to update a file."""
    mock_config = mock.mock_open(read_data=CONFIG_DATA)
    with mock.patch('two1.commands.util.config.open', mock_config, create=True):
        c = config.Config('config_file')

    num_config_keys = len(c.state.keys())

    # Update an existing key and add a new one
    with mock.patch('two1.commands.util.config.open', mock_config, create=True):
        c.set('username', 'TEST_USERNAME', should_save=True)
        c.set('some_list_key', [123, 456, 789], should_save=True)

    # Import the newly saved configuration file
    new_config = json.loads(mock_config.return_value.write.call_args[0][0])

    mock_config.assert_called_with('config_file', mode='w')
    assert c.username == 'TEST_USERNAME'
    assert c.some_list_key == [123, 456, 789]
    assert new_config['username'] == 'TEST_USERNAME'
    assert new_config['some_list_key'] == [123, 456, 789]
    assert len(new_config.keys()) == num_config_keys + 1
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号