test_plugins.py 文件源码

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

项目:edi 作者: lueschem 项目源码 文件源码
def test_plugins(monkeypatch, config_files, capsys, command, command_args, has_templates,
                 has_profiles, has_playbooks, has_postprocessing_commands):
    def fake_lxc_config_command(*popenargs, **kwargs):
        if 'images.compression_algorithm' in popenargs[0]:
            return subprocess.CompletedProcess("fakerun", 0, '')
        else:
            return subprocess.run(*popenargs, **kwargs)

    monkeypatch.setattr(mockablerun, 'run_mockable', fake_lxc_config_command)

    parser = edi._setup_command_line_interface()
    command_args.append(config_files)
    cli_args = parser.parse_args(command_args)

    command().run_cli(cli_args)
    out, err = capsys.readouterr()

    assert err == ''
    result = yaml.load(out)

    if has_templates:
        assert result.get('lxc_templates')
    else:
        assert not result.get('lxc_templates')

    if has_profiles:
        assert result.get('lxc_profiles')
    else:
        assert not result.get('lxc_profiles')

    if has_playbooks:
        assert len(result.get('playbooks')) == 3
        base_system = result.get('playbooks')[0].get('10_base_system')
        assert 'plugins/playbooks/foo.yml' in base_system.get('path')
        assert base_system.get('dictionary').get('kernel_package') == 'linux-image-amd64-rt'
        assert base_system.get('dictionary').get('edi_config_directory') == os.path.dirname(config_files)
    else:
        assert not result.get('playbooks')

    if has_postprocessing_commands:
        assert result.get('postprocessing_commands')
    else:
        assert not result.get('postprocessing_commands')
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号