Beispiel #1
0
def test_cli_tox_ini_not_file(tmp_path, capsys):
    with pytest.raises(SystemExit) as context:
        cli_args([str(tmp_path)])
    assert context.value.code != 0
    out, err = capsys.readouterr()
    assert not out
    assert "argument tox_ini: path is not a file" in err
Beispiel #2
0
def test_cli_tox_ini_not_exists(tmp_path, capsys):
    with pytest.raises(SystemExit) as context:
        cli_args([str(tmp_path / "tox.ini")])
    assert context.value.code != 0
    out, err = capsys.readouterr()
    assert not out
    assert "argument tox_ini: path does not exists" in err
Beispiel #3
0
def test_cli_tox_ini_permission_fail(tmp_path, capsys, flag, error):
    path = tmp_path / "tox.ini"
    path.write_text("")
    path.chmod(flag)
    try:
        with pytest.raises(SystemExit) as context:
            cli_args([str(path)])
    finally:
        path.chmod(S_IWRITE | S_IREAD)
    assert context.value.code != 0
    out, err = capsys.readouterr()
    assert not out
    assert f"argument tox_ini: cannot {error} path" in err
Beispiel #4
0
def run(args: Optional[Sequence[str]] = None) -> int:
    opts = cli_args(sys.argv[1:] if args is None else args)
    formatted = format_tox_ini(opts.tox_ini)
    before = opts.tox_ini.read_text()
    changed = before != formatted
    if opts.stdout:  # stdout just prints new format to stdout
        print(formatted, end="")
    else:
        opts.tox_ini.write_text(formatted)
        try:
            name = str(opts.tox_ini.relative_to(Path.cwd()))
        except ValueError:
            name = str(opts.tox_ini)
        diff = (difflib.unified_diff(before.splitlines(),
                                     formatted.splitlines(),
                                     fromfile=name,
                                     tofile=name) if changed else [])
        if diff:
            print("\n".join(diff))  # print diff on change
        else:
            print(f"no change for {name}")
    # exit with non success on change
    return 1 if changed else 0
Beispiel #5
0
def test_cli_tox_ini_ok(tmp_path):
    path = tmp_path / "tox.ini"
    path.write_text("")
    result = cli_args([str(path)])
    assert result.tox_ini == path
Beispiel #6
0
def test_tox_ini_resolved(tmp_path, monkeypatch):
    monkeypatch.chdir(tmp_path)
    path = tmp_path / "tox.ini"
    path.write_text("")
    result = cli_args(["tox.ini"])
    assert result.tox_ini == path