def test_download_fails(mocker, for_py_version, session_app_data):
    p_open = mocker.MagicMock()
    mocker.patch('virtualenv.seed.wheels.acquire.Popen', return_value=p_open)
    p_open.communicate.return_value = ('out', 'err')
    p_open.returncode = 1
    as_path = mocker.MagicMock()
    with pytest.raises(CalledProcessError) as context:
        (download_wheel('pip', '==1', for_py_version, [], session_app_data, as_path),)
    exc = context.value
    if PY2:
        assert (exc.output == 'outerr')
    else:
        assert (exc.output == 'out')
        assert (exc.stderr == 'err')
    assert (exc.returncode == 1)
    assert ([sys.executable, '-m', 'pip', 'download', '--progress-bar', 'off', '--disable-pip-version-check', '--only-binary=:all:', '--no-deps', '--python-version', for_py_version, '-d', str(as_path), 'pip==1'] == exc.cmd)
def test_download_fails(mocker, for_py_version, session_app_data):
    p_open = mocker.MagicMock()
    mocker.patch('virtualenv.seed.wheels.acquire.Popen', return_value=p_open)
    p_open.communicate.return_value = ('out', 'err')
    p_open.returncode = 1
    as_path = mocker.MagicMock()
    with pytest.raises(CalledProcessError) as context:
        (download_wheel('pip', '==1', for_py_version, [], session_app_data, as_path),)
    exc = context.value
    if PY2:
        assert (exc.output == 'outerr')
    else:
        assert (exc.output == 'out')
        assert (exc.stderr == 'err')
    assert (exc.returncode == 1)
    assert ([sys.executable, '-m', 'pip', 'download', '--progress-bar', 'off', '--disable-pip-version-check', '--only-binary=:all:', '--no-deps', '--python-version', for_py_version, '-d', str(as_path), 'pip==1'] == exc.cmd)