Skip to content

Chore: Enable raises for assert #583

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions .config/pydoclint-baseline.txt
Original file line number Diff line number Diff line change
@@ -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
--------------------
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions tests/integration/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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"])

Expand Down
36 changes: 36 additions & 0 deletions tests/integration/test_container.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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"
Expand All @@ -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
Expand Down Expand Up @@ -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"
Expand All @@ -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"
Expand All @@ -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(
Expand Down Expand Up @@ -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 = (
Expand Down Expand Up @@ -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"
Expand All @@ -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"
Expand All @@ -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)
Expand All @@ -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"
Expand Down Expand Up @@ -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}")
Expand Down
9 changes: 9 additions & 0 deletions tests/integration/test_server_creator_v1.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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",
Expand Down Expand Up @@ -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",
Expand Down
9 changes: 9 additions & 0 deletions tests/integration/test_server_creator_v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down
3 changes: 3 additions & 0 deletions tests/integration/test_server_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
6 changes: 6 additions & 0 deletions tests/unit/test_basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__")
Expand All @@ -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__")
Expand Down
3 changes: 3 additions & 0 deletions tests/unit/test_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {}
Expand Down
15 changes: 14 additions & 1 deletion tests/unit/test_server_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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"
Expand All @@ -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"
Expand Down
Loading