diff --git a/.config/pydoclint-baseline.txt b/.config/pydoclint-baseline.txt index d82447a7..e69de29b 100644 --- a/.config/pydoclint-baseline.txt +++ b/.config/pydoclint-baseline.txt @@ -1,4 +0,0 @@ -tests/integration/test_server_creator_v2.py - DOC502: Function `test_error_devfile_v2` has a "Raises" section in the docstring, but there are not "raise" statements in the body - DOC502: Function `test_devfile_v2` has a "Raises" section in the docstring, but there are not "raise" statements in the body --------------------- diff --git a/pyproject.toml b/pyproject.toml index 87ba5db7..402391cc 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -77,6 +77,7 @@ arg-type-hints-in-docstring = false baseline = ".config/pydoclint-baseline.txt" check-return-types = false exclude = '\.git|\.tox|build|collections|out|venv' +should-declare-assert-error-if-assert-statement-exists = true should-document-private-class-attributes = true show-filenames-in-every-violation-message = true skip-checking-short-docstrings = false diff --git a/tests/integration/test_cli.py b/tests/integration/test_cli.py index 3495cfae..303142fb 100644 --- a/tests/integration/test_cli.py +++ b/tests/integration/test_cli.py @@ -19,6 +19,9 @@ def test_version( Args: monkeypatch: Pytest monkeypatch fixture. capsys: Pytest capsys fixture. + + Raises: + AssertionError: If package versions are not found in output. """ monkeypatch.setattr("sys.argv", ["adt", "--version"]) with pytest.raises(SystemExit): @@ -37,6 +40,9 @@ def test_server_fail_no_deps( Args: monkeypatch: Pytest monkeypatch fixture. capsys: Pytest capsys fixture. + + Raises: + AssertionError: If expected error message is not found in output. """ monkeypatch.setattr("sys.argv", ["adt", "server"]) diff --git a/tests/integration/test_container.py b/tests/integration/test_container.py index fbb9c573..b5d1a359 100644 --- a/tests/integration/test_container.py +++ b/tests/integration/test_container.py @@ -34,6 +34,9 @@ def test_versions(exec_container: Callable[[str], subprocess.CompletedProcess[st Args: exec_container: The container executor. + + Raises: + AssertionError: If package versions are not found in output. """ versions = exec_container("adt --version") for pkg in PKGS: @@ -46,6 +49,9 @@ def test_podman(exec_container: Callable[[str], subprocess.CompletedProcess[str] Args: exec_container: The container executor. + + Raises: + AssertionError: If podman command fails. """ result = exec_container("podman run hello") assert result.returncode == 0, "podman command failed" @@ -61,6 +67,9 @@ def test_cinc( Args: infrastructure: The testing infrastructure. exec_container: The container executor. + + Raises: + AssertionError: If container operations or path access fails. """ # We do not want to accidentally pull here because we expected to load # the tar image into the container. Our scope is to test the image we did @@ -113,6 +122,9 @@ def test_app( exec_container: The container executor. app: The app to test. command: Command used to test tool version and or presence. + + Raises: + AssertionError: If app command fails or returns non-zero exit code. """ result = exec_container(command if command else f"{app} --version") assert result.returncode == 0, f"{app} command failed" @@ -124,6 +136,9 @@ def test_user_shell(exec_container: Callable[[str], subprocess.CompletedProcess[ Args: exec_container: The container executor. + + Raises: + AssertionError: If zsh is not found in /etc/passwd. """ result = exec_container("cat /etc/passwd | grep root | grep zsh") assert result.returncode == 0, "zsh not found in /etc/passwd" @@ -143,6 +158,9 @@ def test_navigator_2_c_in_c( test_fixture_dir_container: The test fixture directory. tmp_path: The temporary directory. infrastructure: The testing infrastructure. + + Raises: + AssertionError: If playbook execution does not show expected success output. """ playbook = test_fixture_dir_container / "site.yml" result = exec_container( @@ -171,6 +189,9 @@ def test_navigator_1( infrastructure: The testing infrastructure test_fixture_dir: The test fixture directory. tmp_path: The temporary directory. + + Raises: + AssertionError: If command execution fails or does not show expected success output. """ playbook = test_fixture_dir / "site.yml" cmd = ( @@ -242,6 +263,9 @@ def test_nav_collections( container_tmux: A tmux session attached to the container. tmp_path: The temporary directory infrastructure: The testing infrastructure + + Raises: + AssertionError: If expected collections are not found in output. """ cmd = ( f"ansible-navigator collections --lf {tmp_path}/navigator.log" @@ -267,6 +291,9 @@ def test_nav_images( container_tmux: A tmux session attached to the container. tmp_path: The temporary directory infrastructure: The testing infrastructure + + Raises: + AssertionError: If expected images are not found in output. """ cmd = ( f"ansible-navigator images --lf {tmp_path}/nav.log" @@ -289,6 +316,9 @@ def test_nav_playbook( container_tmux: A tmux session attached to the container. tmp_path: The temporary directory infrastructure: The testing infrastructure + + Raises: + AssertionError: If playbook creation or execution does not show expected output. """ cmd = f"ansible-creator init playbook test_ns.test_name {tmp_path}" stdout = container_tmux.send_and_wait(cmd=cmd, wait_for="created", timeout=15) @@ -310,6 +340,9 @@ def test_nav_collection(container_tmux: ContainerTmux, tmp_path: Path) -> None: Args: container_tmux: A tmux session attached to the container. tmp_path: The temporary directory + + Raises: + AssertionError: If collection creation or navigation does not show expected output. """ namespace = "test_ns" name = "test_name" @@ -337,6 +370,9 @@ def test_builder( exec_container: The container executor. test_fixture_dir_container: The test fixture directory. tmp_path: The temporary directory. + + Raises: + AssertionError: If ansible-builder does not complete successfully. """ ee_file = test_fixture_dir_container / "execution-environment.yml" result = exec_container(f"ANSIBLE_NOCOLOR=1 ansible-builder build -f {ee_file} -c {tmp_path}") diff --git a/tests/integration/test_server_creator_v1.py b/tests/integration/test_server_creator_v1.py index 37f1d58e..8113124c 100644 --- a/tests/integration/test_server_creator_v1.py +++ b/tests/integration/test_server_creator_v1.py @@ -21,6 +21,9 @@ def test_error_v1(server_url: str, resource: str) -> None: Args: server_url: The server URL. resource: The resource to test. + + Raises: + AssertionError: If response status or text does not match expected values. """ response = requests.post(f"{server_url}/v1/creator/{resource}", timeout=10) assert response.status_code == requests.codes.get("bad_request") @@ -33,6 +36,9 @@ def test_playbook_v1(server_url: str, tmp_path: Path) -> None: Args: server_url: The server URL. tmp_path: Pytest tmp_path fixture. + + Raises: + AssertionError: If response status, headers, or content does not match expected values. """ response = requests.post( f"{server_url}/v1/creator/playbook", @@ -62,6 +68,9 @@ def test_collection_v1(server_url: str, tmp_path: Path) -> None: Args: server_url: The server URL. tmp_path: Pytest tmp_path fixture. + + Raises: + AssertionError: If response status, headers, or content does not match expected values. """ response = requests.post( f"{server_url}/v1/creator/collection", diff --git a/tests/integration/test_server_creator_v2.py b/tests/integration/test_server_creator_v2.py index 805e315f..dd54ad30 100644 --- a/tests/integration/test_server_creator_v2.py +++ b/tests/integration/test_server_creator_v2.py @@ -21,6 +21,9 @@ def test_error_v2(server_url: str, resource: str) -> None: Args: server_url: The server URL. resource: The resource to test. + + Raises: + AssertionError: If response status or text does not match expected values. """ response = requests.post(f"{server_url}/v2/creator/{resource}", timeout=10) assert response.status_code == requests.codes.get("bad_request") @@ -50,6 +53,9 @@ def test_playbook_v2(server_url: str, tmp_path: Path) -> None: Args: server_url: The server URL. tmp_path: Pytest tmp_path fixture. + + Raises: + AssertionError: If response status, headers, or content does not match expected values. """ response = requests.post( f"{server_url}/v2/creator/playbook", @@ -79,6 +85,9 @@ def test_collection_v2(server_url: str, tmp_path: Path) -> None: Args: server_url: The server URL. tmp_path: Pytest tmp_path fixture. + + Raises: + AssertionError: If response status, headers, or content does not match expected values. """ response = requests.post( f"{server_url}/v2/creator/collection", @@ -129,6 +138,9 @@ def test_pattern_v2(server_url: str, tmp_path: Path) -> None: Args: server_url: The server URL. tmp_path: Pytest tmp_path fixture. + + Raises: + AssertionError: If the test assertions fail (e.g., response status code or tar content). """ pattern_name = "foo" response = requests.post( diff --git a/tests/integration/test_server_info.py b/tests/integration/test_server_info.py index 022a8b26..8bebc4eb 100644 --- a/tests/integration/test_server_info.py +++ b/tests/integration/test_server_info.py @@ -10,6 +10,9 @@ def test_metadata(server_url: str) -> None: Args: server_url: The server URL. + + Raises: + AssertionError: If response status, headers, or content does not match expected values. """ endpoint = f"{server_url}/metadata" diff --git a/tests/unit/test_basic.py b/tests/unit/test_basic.py index c3c0e470..2a5bbe60 100644 --- a/tests/unit/test_basic.py +++ b/tests/unit/test_basic.py @@ -11,6 +11,9 @@ def test_main() -> None: """Test the main entry point. Gives an error message due to missing subcommand. + + Raises: + AssertionError: If the expected error code is not returned. """ with pytest.raises(SystemExit) as exc: runpy.run_module("ansible_dev_tools.__main__", run_name="__main__") @@ -22,6 +25,9 @@ def test_cli_main() -> None: """Test the main entry point. Gives an error message due to missing subcommand. + + Raises: + AssertionError: If the expected error code is not returned. """ with pytest.raises(SystemExit) as exc: runpy.run_module("ansible_dev_tools.cli", run_name="__main__") diff --git a/tests/unit/test_server.py b/tests/unit/test_server.py index bdda6e13..deb8f949 100644 --- a/tests/unit/test_server.py +++ b/tests/unit/test_server.py @@ -17,6 +17,9 @@ def test_server_debug_options(monkeypatch: pytest.MonkeyPatch, adt_server: Serve Args: monkeypatch: pytest fixture for patching. adt_server: The server instance. + + Raises: + AssertionError: If server options or call status do not match expected values. """ called = False options = {} diff --git a/tests/unit/test_server_utils.py b/tests/unit/test_server_utils.py index 8cc987b3..2748987d 100644 --- a/tests/unit/test_server_utils.py +++ b/tests/unit/test_server_utils.py @@ -43,6 +43,9 @@ def test_validate_request_pass(collection_request: HttpRequest) -> None: Args: collection_request: A Django request object + + Raises: + AssertionError: If validation fails or returns unexpected results. """ result = validate_request(collection_request) assert isinstance(result, RequestUnmarshalResult) @@ -51,7 +54,11 @@ def test_validate_request_pass(collection_request: HttpRequest) -> None: def test_validate_request_fail() -> None: - """Test the validate_request function for failure.""" + """Test the validate_request function for failure. + + Raises: + AssertionError: If validation passes when it should fail. + """ rf = RequestFactory() request = rf.get("/hello/") result = validate_request(request) @@ -64,6 +71,9 @@ def test_validate_response_pass(collection_request: HttpRequest) -> None: Args: collection_request: A Django request object + + Raises: + AssertionError: If validation fails or returns unexpected status code. """ response = HttpResponse() response["Content-Type"] = "application/tar" @@ -80,6 +90,9 @@ def test_validate_response_fail(collection_request: HttpRequest) -> None: Args: collection_request: A Django request object + + Raises: + AssertionError: If validation passes when it should fail. """ response = HttpResponse() response["Content-Type"] = "application/tar"