From 95dc28e227fe9bf61288b2be4b034a4c0ba4e671 Mon Sep 17 00:00:00 2001 From: Marc Cataford Date: Fri, 12 Apr 2024 01:16:03 -0400 Subject: [PATCH] ci: lint + format + test on push fix: ensure ci lints all source files chore: formatting --- .forgejo/workflows/main.yml | 10 +++++---- pyproject.toml | 4 ++++ spud/cli.py | 1 + tests/conftest.py | 7 ++++++- tests/test_cli.py | 41 ++++++++++++++++++++++++++++--------- 5 files changed, 48 insertions(+), 15 deletions(-) diff --git a/.forgejo/workflows/main.yml b/.forgejo/workflows/main.yml index dc97b5b..bf96628 100644 --- a/.forgejo/workflows/main.yml +++ b/.forgejo/workflows/main.yml @@ -6,22 +6,24 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - - uses: actions/setup-python@v2 + - uses: https://github.com/actions/setup-python@v5 with: python-version: 3.12 - run: | pip install -r ./requirements.txt pip install -r ./requirements_sast.txt - name: Formatting - run: python -m black . + run: python -m black . --check - name: Linting - run: python -m pylint . + run: python -m pylint **/*.py test: name: Tests runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - - uses: actions/setup-python@v2 + with: + github-server-url: https://forge.karnov.club + - uses: https://github.com/actions/setup-python@v5 with: python-version: 3.12 - run: | diff --git a/pyproject.toml b/pyproject.toml index 7588f27..89da2b4 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -25,3 +25,7 @@ spud = "spud.cli:cli" [tool.setuptools] packages = ["spud"] +[tool.pylint.main] +ignore = ["spud.venv"] +ignore-paths = ["spud.venv"] +jobs = 0 diff --git a/spud/cli.py b/spud/cli.py index 02f5915..c624e47 100644 --- a/spud/cli.py +++ b/spud/cli.py @@ -3,6 +3,7 @@ Command-line application entry-point. Logic for the command-line spud tooling. """ + import pathlib import json diff --git a/tests/conftest.py b/tests/conftest.py index b10c779..72e1036 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -4,9 +4,14 @@ import importlib import spud.cli + @pytest.fixture(autouse=True) def mock_default_config_path(monkeypatch, tmpdir): - monkeypatch.setattr(spud.cli, "DEFAULT_CONFIGURATION_PATH", tmpdir / ".config" / "spud" / "config.json") + monkeypatch.setattr( + spud.cli, + "DEFAULT_CONFIGURATION_PATH", + tmpdir / ".config" / "spud" / "config.json", + ) @pytest.fixture(name="invoke_cli") diff --git a/tests/test_cli.py b/tests/test_cli.py index 4b4044d..37c158c 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -3,16 +3,23 @@ import click import pathlib -def test_init_raises_if_config_file_exists_default_path(invoke_cli, tmpdir, monkeypatch): + +def test_init_raises_if_config_file_exists_default_path( + invoke_cli, tmpdir, monkeypatch +): expected_default_path = tmpdir / ".config" / "spud" / "config.json" pathlib.Path(expected_default_path).parent.mkdir(parents=True) expected_default_path.write("{}") result = invoke_cli(["init"]) - + assert result.exit_code == 1 - assert str(result.exception) == f"File already exists ({str(expected_default_path)}), cannot initialize." + assert ( + str(result.exception) + == f"File already exists ({str(expected_default_path)}), cannot initialize." + ) + def test_init_raises_if_config_file_exists_custom_path(invoke_cli, tmpdir, monkeypatch): expected_default_path = tmpdir / "config.json" @@ -20,21 +27,35 @@ def test_init_raises_if_config_file_exists_custom_path(invoke_cli, tmpdir, monke expected_default_path.write("{}") result = invoke_cli(["--config", str(expected_default_path), "init"]) - - assert result.exit_code == 1 - assert str(result.exception) == f"File already exists ({str(expected_default_path)}), cannot initialize." -def test_print_config_raises_if_no_config_file_default_path(invoke_cli, tmpdir, monkeypatch): + assert result.exit_code == 1 + assert ( + str(result.exception) + == f"File already exists ({str(expected_default_path)}), cannot initialize." + ) + + +def test_print_config_raises_if_no_config_file_default_path( + invoke_cli, tmpdir, monkeypatch +): expected_default_path = tmpdir / ".config" / "spud" / "config.json" result = invoke_cli(["print-config"]) assert result.exit_code == 1 - assert str(result.exception) == f"Configuration file not found at {str(expected_default_path)}." + assert ( + str(result.exception) + == f"Configuration file not found at {str(expected_default_path)}." + ) -def test_print_config_raises_if_no_config_file_custom_path(invoke_cli, tmpdir, monkeypatch): + +def test_print_config_raises_if_no_config_file_custom_path( + invoke_cli, tmpdir, monkeypatch +): config_file = tmpdir / "config.json" result = invoke_cli(["--config", str(config_file), "print-config"]) assert result.exit_code == 1 - assert str(result.exception) == f"Configuration file not found at {str(config_file)}." + assert ( + str(result.exception) == f"Configuration file not found at {str(config_file)}." + )