Ejemplo n.º 1
0
def test_version(capsys):
    with pytest.raises(SystemExit) as exc:
        main(["--version"])

    assert exc.value.code == 0

    out, err = capsys.readouterr()
    assert not err
    assert conda_pack.__version__ in out
Ejemplo n.º 2
0
def test_help(capsys):
    with pytest.raises(SystemExit) as exc:
        main(["-h"])

    assert exc.value.code == 0

    out, err = capsys.readouterr()
    assert not err
    assert 'usage: conda-pack' in out
Ejemplo n.º 3
0
def test_quiet(capsys, tmpdir):
    out_path = os.path.join(str(tmpdir), 'py36.tar')

    with pytest.raises(SystemExit) as exc:
        main(["-p", py36_path, "-o", out_path, "-q"])

    assert exc.value.code == 0

    assert os.path.exists(out_path)
    assert tarfile.is_tarfile(out_path)

    out, err = capsys.readouterr()
    assert not err
    assert not out
Ejemplo n.º 4
0
def test_cli_warnings(capsys, broken_package_cache, tmpdir):
    out_path = os.path.join(str(tmpdir), 'py27.tar')

    with pytest.raises(SystemExit) as exc:
        main(["-p", py27_path, "-o", out_path])

    assert exc.value.code == 0

    assert os.path.exists(out_path)
    assert tarfile.is_tarfile(out_path)

    out, err = capsys.readouterr()
    assert "Conda-managed packages were found" in err
    assert "UserWarning" not in err  # printed, not from python warning
Ejemplo n.º 5
0
def test_cli_exceptions(capsys):
    with pytest.raises(SystemExit) as exc:
        main(["-p", "not_a_real_path"])

    assert exc.value.code == 1

    out, err = capsys.readouterr()
    assert "CondaPackError: Environment path" in err

    with pytest.raises(SystemExit) as exc:
        main(["-foo", "-bar"])

    assert exc.value.code != 0

    out, err = capsys.readouterr()
    assert not out
    assert "usage: conda-pack" in err
Ejemplo n.º 6
0
def test_cli_roundtrip(capsys, tmpdir):
    out_path = os.path.join(str(tmpdir), 'py36.tar')

    with pytest.raises(SystemExit) as exc:
        main(["-p", py36_path, "-o", out_path])

    assert exc.value.code == 0

    assert os.path.exists(out_path)
    assert tarfile.is_tarfile(out_path)

    out, err = capsys.readouterr()
    assert not err

    bar, percent, time = [i.strip() for i in out.split('\r')[-1].split('|')]
    assert bar == '[' + '#' * 40 + ']'
    assert percent == '100% Completed'
    assert time
Ejemplo n.º 7
0
def test_parse_include_exclude():
    out = {}

    def capture(**kwargs):
        out.update(kwargs)

    with pytest.raises(SystemExit) as exc:
        main([
            "--exclude", "foo/*", "--include", "*.py", "--include", "*.pyx",
            "--exclude", "foo/bar/*.pyx"
        ],
             pack=capture)

    assert exc.value.code == 0

    assert out['filters'] == [("exclude", "foo/*"), ("include", "*.py"),
                              ("include", "*.pyx"),
                              ("exclude", "foo/bar/*.pyx")]
Ejemplo n.º 8
0
def test_keyboard_interrupt(capsys, tmpdir):
    def interrupt():
        time.sleep(0.2)
        os.kill(os.getpid(), signal.SIGINT)

    interrupter = Thread(target=interrupt)

    out_path = os.path.join(str(tmpdir), 'py36.tar')
    try:
        with pytest.raises(SystemExit) as exc:
            interrupter.start()
            main(["-p", py36_path, "-o", out_path])
    except KeyboardInterrupt:
        assert False, "Should have been caught by the CLI"

    assert exc.value.code == 1
    out, err = capsys.readouterr()
    assert err == 'Interrupted\n'
    assert not os.path.exists(out_path)