2018-07-11 08:50:42 -04:00
|
|
|
"""Syntax checks"""
|
|
|
|
|
|
|
|
import os
|
2023-07-10 10:14:33 -04:00
|
|
|
|
2018-07-11 08:50:42 -04:00
|
|
|
import pytest
|
|
|
|
|
|
|
|
|
|
|
|
def test_yadm_syntax(runner, yadm):
|
|
|
|
"""Is syntactically valid"""
|
2023-07-10 15:43:17 -04:00
|
|
|
run = runner(command=["bash", "-n", yadm])
|
2018-07-11 08:50:42 -04:00
|
|
|
assert run.success
|
|
|
|
|
|
|
|
|
2019-12-03 08:54:59 -05:00
|
|
|
def test_shellcheck(pytestconfig, runner, yadm, shellcheck_version):
|
2018-07-11 08:50:42 -04:00
|
|
|
"""Passes shellcheck"""
|
2019-12-03 08:54:59 -05:00
|
|
|
if not pytestconfig.getoption("--force-linters"):
|
2023-07-10 15:43:17 -04:00
|
|
|
run = runner(command=["shellcheck", "-V"], report=False)
|
|
|
|
if f"version: {shellcheck_version}" not in run.out:
|
|
|
|
pytest.skip("Unsupported shellcheck version")
|
|
|
|
run = runner(command=["shellcheck", "-s", "bash", yadm])
|
2018-07-11 08:50:42 -04:00
|
|
|
assert run.success
|
|
|
|
|
|
|
|
|
2019-12-03 08:54:59 -05:00
|
|
|
def test_pylint(pytestconfig, runner, pylint_version):
|
2018-07-11 08:50:42 -04:00
|
|
|
"""Passes pylint"""
|
2019-12-03 08:54:59 -05:00
|
|
|
if not pytestconfig.getoption("--force-linters"):
|
2023-07-10 15:43:17 -04:00
|
|
|
run = runner(command=["pylint", "--version"], report=False)
|
|
|
|
if f"pylint {pylint_version}" not in run.out:
|
|
|
|
pytest.skip("Unsupported pylint version")
|
2023-07-09 12:13:13 -04:00
|
|
|
pyfiles = []
|
2023-07-10 15:43:17 -04:00
|
|
|
for tfile in os.listdir("test"):
|
|
|
|
if tfile.endswith(".py"):
|
|
|
|
pyfiles.append(f"test/{tfile}")
|
|
|
|
run = runner(command=["pylint"] + pyfiles)
|
2018-07-11 08:50:42 -04:00
|
|
|
assert run.success
|
|
|
|
|
|
|
|
|
2023-07-10 10:14:33 -04:00
|
|
|
def test_isort(pytestconfig, runner, isort_version):
|
|
|
|
"""Passes isort"""
|
|
|
|
if not pytestconfig.getoption("--force-linters"):
|
2023-07-10 15:43:17 -04:00
|
|
|
run = runner(command=["isort", "--version"], report=False)
|
2023-07-10 10:14:33 -04:00
|
|
|
if isort_version not in run.out:
|
2023-07-10 15:43:17 -04:00
|
|
|
pytest.skip("Unsupported isort version")
|
|
|
|
run = runner(command=["isort", "-c", "test"])
|
2023-07-10 10:14:33 -04:00
|
|
|
assert run.success
|
|
|
|
|
|
|
|
|
2019-12-03 08:54:59 -05:00
|
|
|
def test_flake8(pytestconfig, runner, flake8_version):
|
2018-07-11 08:50:42 -04:00
|
|
|
"""Passes flake8"""
|
2019-12-03 08:54:59 -05:00
|
|
|
if not pytestconfig.getoption("--force-linters"):
|
2023-07-10 15:43:17 -04:00
|
|
|
run = runner(command=["flake8", "--version"], report=False)
|
2019-12-03 08:54:59 -05:00
|
|
|
if not run.out.startswith(flake8_version):
|
2023-07-10 15:43:17 -04:00
|
|
|
pytest.skip("Unsupported flake8 version")
|
|
|
|
run = runner(command=["flake8", "test"])
|
2018-07-11 08:50:42 -04:00
|
|
|
assert run.success
|
2019-03-21 08:38:38 -04:00
|
|
|
|
|
|
|
|
2023-07-10 10:18:36 -04:00
|
|
|
def test_black(pytestconfig, runner, black_version):
|
|
|
|
"""Passes black"""
|
|
|
|
if not pytestconfig.getoption("--force-linters"):
|
2023-07-10 15:43:17 -04:00
|
|
|
run = runner(command=["black", "--version"], report=False)
|
2023-07-10 10:18:36 -04:00
|
|
|
if black_version not in run.out:
|
2023-07-10 15:43:17 -04:00
|
|
|
pytest.skip("Unsupported black version")
|
|
|
|
run = runner(command=["black", "--check", "test"])
|
2023-07-10 10:18:36 -04:00
|
|
|
assert run.success
|
|
|
|
|
|
|
|
|
2019-12-03 08:54:59 -05:00
|
|
|
def test_yamllint(pytestconfig, runner, yamllint_version):
|
2019-03-21 08:38:38 -04:00
|
|
|
"""Passes yamllint"""
|
2019-12-03 08:54:59 -05:00
|
|
|
if not pytestconfig.getoption("--force-linters"):
|
2023-07-10 15:43:17 -04:00
|
|
|
run = runner(command=["yamllint", "--version"], report=False)
|
2019-12-03 08:54:59 -05:00
|
|
|
if not run.out.strip().endswith(yamllint_version):
|
2023-07-10 15:43:17 -04:00
|
|
|
pytest.skip("Unsupported yamllint version")
|
|
|
|
run = runner(command=["yamllint", "-s", "$(find . -name \\*.yml)"], shell=True)
|
2019-03-21 08:38:38 -04:00
|
|
|
assert run.success
|
2020-01-20 09:22:17 -05:00
|
|
|
|
|
|
|
|
|
|
|
def test_man(runner):
|
|
|
|
"""Check for warnings from man"""
|
2023-07-10 15:43:17 -04:00
|
|
|
run = runner(command=["man.REAL", "--warnings", "./yadm.1"])
|
2020-01-20 09:22:17 -05:00
|
|
|
assert run.success
|
2023-07-10 15:43:17 -04:00
|
|
|
assert run.err == ""
|
|
|
|
assert "yadm - Yet Another Dotfiles Manager" in run.out
|