Skip to content

Commit 795c824

Browse files
committed
Enable raises for assert
1 parent af5a880 commit 795c824

10 files changed

+87
-5
lines changed

.config/pydoclint-baseline.txt

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +0,0 @@
1-
tests/integration/test_server_creator_v2.py
2-
DOC502: Function `test_error_devfile_v2` has a "Raises" section in the docstring, but there are not "raise" statements in the body
3-
DOC502: Function `test_devfile_v2` has a "Raises" section in the docstring, but there are not "raise" statements in the body
4-
--------------------

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ arg-type-hints-in-docstring = false
7777
baseline = ".config/pydoclint-baseline.txt"
7878
check-return-types = false
7979
exclude = '\.git|\.tox|build|collections|out|venv'
80+
should-declare-assert-error-if-assert-statement-exists = true
8081
should-document-private-class-attributes = true
8182
show-filenames-in-every-violation-message = true
8283
skip-checking-short-docstrings = false

tests/integration/test_cli.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ def test_version(
1919
Args:
2020
monkeypatch: Pytest monkeypatch fixture.
2121
capsys: Pytest capsys fixture.
22+
23+
Raises:
24+
AssertionError: If package versions are not found in output.
2225
"""
2326
monkeypatch.setattr("sys.argv", ["adt", "--version"])
2427
with pytest.raises(SystemExit):
@@ -37,6 +40,9 @@ def test_server_fail_no_deps(
3740
Args:
3841
monkeypatch: Pytest monkeypatch fixture.
3942
capsys: Pytest capsys fixture.
43+
44+
Raises:
45+
AssertionError: If expected error message is not found in output.
4046
"""
4147
monkeypatch.setattr("sys.argv", ["adt", "server"])
4248

tests/integration/test_container.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@ def test_versions(exec_container: Callable[[str], subprocess.CompletedProcess[st
3434
3535
Args:
3636
exec_container: The container executor.
37+
38+
Raises:
39+
AssertionError: If package versions are not found in output.
3740
"""
3841
versions = exec_container("adt --version")
3942
for pkg in PKGS:
@@ -46,6 +49,9 @@ def test_podman(exec_container: Callable[[str], subprocess.CompletedProcess[str]
4649
4750
Args:
4851
exec_container: The container executor.
52+
53+
Raises:
54+
AssertionError: If podman command fails.
4955
"""
5056
result = exec_container("podman run hello")
5157
assert result.returncode == 0, "podman command failed"
@@ -61,6 +67,9 @@ def test_cinc(
6167
Args:
6268
infrastructure: The testing infrastructure.
6369
exec_container: The container executor.
70+
71+
Raises:
72+
AssertionError: If container operations or path access fails.
6473
"""
6574
# We do not want to accidentally pull here because we expected to load
6675
# the tar image into the container. Our scope is to test the image we did
@@ -113,6 +122,9 @@ def test_app(
113122
exec_container: The container executor.
114123
app: The app to test.
115124
command: Command used to test tool version and or presence.
125+
126+
Raises:
127+
AssertionError: If app command fails or returns non-zero exit code.
116128
"""
117129
result = exec_container(command if command else f"{app} --version")
118130
assert result.returncode == 0, f"{app} command failed"
@@ -124,6 +136,9 @@ def test_user_shell(exec_container: Callable[[str], subprocess.CompletedProcess[
124136
125137
Args:
126138
exec_container: The container executor.
139+
140+
Raises:
141+
AssertionError: If zsh is not found in /etc/passwd.
127142
"""
128143
result = exec_container("cat /etc/passwd | grep root | grep zsh")
129144
assert result.returncode == 0, "zsh not found in /etc/passwd"
@@ -143,6 +158,9 @@ def test_navigator_2_c_in_c(
143158
test_fixture_dir_container: The test fixture directory.
144159
tmp_path: The temporary directory.
145160
infrastructure: The testing infrastructure.
161+
162+
Raises:
163+
AssertionError: If playbook execution does not show expected success output.
146164
"""
147165
playbook = test_fixture_dir_container / "site.yml"
148166
result = exec_container(
@@ -171,6 +189,9 @@ def test_navigator_1(
171189
infrastructure: The testing infrastructure
172190
test_fixture_dir: The test fixture directory.
173191
tmp_path: The temporary directory.
192+
193+
Raises:
194+
AssertionError: If command execution fails or does not show expected success output.
174195
"""
175196
playbook = test_fixture_dir / "site.yml"
176197
cmd = (
@@ -242,6 +263,9 @@ def test_nav_collections(
242263
container_tmux: A tmux session attached to the container.
243264
tmp_path: The temporary directory
244265
infrastructure: The testing infrastructure
266+
267+
Raises:
268+
AssertionError: If expected collections are not found in output.
245269
"""
246270
cmd = (
247271
f"ansible-navigator collections --lf {tmp_path}/navigator.log"
@@ -267,6 +291,9 @@ def test_nav_images(
267291
container_tmux: A tmux session attached to the container.
268292
tmp_path: The temporary directory
269293
infrastructure: The testing infrastructure
294+
295+
Raises:
296+
AssertionError: If expected images are not found in output.
270297
"""
271298
cmd = (
272299
f"ansible-navigator images --lf {tmp_path}/nav.log"
@@ -289,6 +316,9 @@ def test_nav_playbook(
289316
container_tmux: A tmux session attached to the container.
290317
tmp_path: The temporary directory
291318
infrastructure: The testing infrastructure
319+
320+
Raises:
321+
AssertionError: If playbook creation or execution does not show expected output.
292322
"""
293323
cmd = f"ansible-creator init playbook test_ns.test_name {tmp_path}"
294324
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:
310340
Args:
311341
container_tmux: A tmux session attached to the container.
312342
tmp_path: The temporary directory
343+
344+
Raises:
345+
AssertionError: If collection creation or navigation does not show expected output.
313346
"""
314347
namespace = "test_ns"
315348
name = "test_name"
@@ -337,6 +370,9 @@ def test_builder(
337370
exec_container: The container executor.
338371
test_fixture_dir_container: The test fixture directory.
339372
tmp_path: The temporary directory.
373+
374+
Raises:
375+
AssertionError: If ansible-builder does not complete successfully.
340376
"""
341377
ee_file = test_fixture_dir_container / "execution-environment.yml"
342378
result = exec_container(f"ANSIBLE_NOCOLOR=1 ansible-builder build -f {ee_file} -c {tmp_path}")

tests/integration/test_server_creator_v1.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ def test_error_v1(server_url: str, resource: str) -> None:
2121
Args:
2222
server_url: The server URL.
2323
resource: The resource to test.
24+
25+
Raises:
26+
AssertionError: If response status or text does not match expected values.
2427
"""
2528
response = requests.post(f"{server_url}/v1/creator/{resource}", timeout=10)
2629
assert response.status_code == requests.codes.get("bad_request")
@@ -33,6 +36,9 @@ def test_playbook_v1(server_url: str, tmp_path: Path) -> None:
3336
Args:
3437
server_url: The server URL.
3538
tmp_path: Pytest tmp_path fixture.
39+
40+
Raises:
41+
AssertionError: If response status, headers, or content does not match expected values.
3642
"""
3743
response = requests.post(
3844
f"{server_url}/v1/creator/playbook",
@@ -62,6 +68,9 @@ def test_collection_v1(server_url: str, tmp_path: Path) -> None:
6268
Args:
6369
server_url: The server URL.
6470
tmp_path: Pytest tmp_path fixture.
71+
72+
Raises:
73+
AssertionError: If response status, headers, or content does not match expected values.
6574
"""
6675
response = requests.post(
6776
f"{server_url}/v1/creator/collection",

tests/integration/test_server_creator_v2.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ def test_error_v2(server_url: str, resource: str) -> None:
2121
Args:
2222
server_url: The server URL.
2323
resource: The resource to test.
24+
25+
Raises:
26+
AssertionError: If response status or text does not match expected values.
2427
"""
2528
response = requests.post(f"{server_url}/v2/creator/{resource}", timeout=10)
2629
assert response.status_code == requests.codes.get("bad_request")
@@ -50,6 +53,9 @@ def test_playbook_v2(server_url: str, tmp_path: Path) -> None:
5053
Args:
5154
server_url: The server URL.
5255
tmp_path: Pytest tmp_path fixture.
56+
57+
Raises:
58+
AssertionError: If response status, headers, or content does not match expected values.
5359
"""
5460
response = requests.post(
5561
f"{server_url}/v2/creator/playbook",
@@ -79,6 +85,9 @@ def test_collection_v2(server_url: str, tmp_path: Path) -> None:
7985
Args:
8086
server_url: The server URL.
8187
tmp_path: Pytest tmp_path fixture.
88+
89+
Raises:
90+
AssertionError: If response status, headers, or content does not match expected values.
8291
"""
8392
response = requests.post(
8493
f"{server_url}/v2/creator/collection",

tests/integration/test_server_info.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ def test_metadata(server_url: str) -> None:
1010
1111
Args:
1212
server_url: The server URL.
13+
14+
Raises:
15+
AssertionError: If response status, headers, or content does not match expected values.
1316
"""
1417
endpoint = f"{server_url}/metadata"
1518

tests/unit/test_basic.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ def test_main() -> None:
1111
"""Test the main entry point.
1212
1313
Gives an error message due to missing subcommand.
14+
15+
Raises:
16+
AssertionError: If the expected error code is not returned.
1417
"""
1518
with pytest.raises(SystemExit) as exc:
1619
runpy.run_module("ansible_dev_tools.__main__", run_name="__main__")
@@ -22,6 +25,9 @@ def test_cli_main() -> None:
2225
"""Test the main entry point.
2326
2427
Gives an error message due to missing subcommand.
28+
29+
Raises:
30+
AssertionError: If the expected error code is not returned.
2531
"""
2632
with pytest.raises(SystemExit) as exc:
2733
runpy.run_module("ansible_dev_tools.cli", run_name="__main__")

tests/unit/test_server.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ def test_server_debug_options(monkeypatch: pytest.MonkeyPatch, adt_server: Serve
1717
Args:
1818
monkeypatch: pytest fixture for patching.
1919
adt_server: The server instance.
20+
21+
Raises:
22+
AssertionError: If server options or call status do not match expected values.
2023
"""
2124
called = False
2225
options = {}

tests/unit/test_server_utils.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,9 @@ def test_validate_request_pass(collection_request: HttpRequest) -> None:
4343
4444
Args:
4545
collection_request: A Django request object
46+
47+
Raises:
48+
AssertionError: If validation fails or returns unexpected results.
4649
"""
4750
result = validate_request(collection_request)
4851
assert isinstance(result, RequestUnmarshalResult)
@@ -51,7 +54,11 @@ def test_validate_request_pass(collection_request: HttpRequest) -> None:
5154

5255

5356
def test_validate_request_fail() -> None:
54-
"""Test the validate_request function for failure."""
57+
"""Test the validate_request function for failure.
58+
59+
Raises:
60+
AssertionError: If validation passes when it should fail.
61+
"""
5562
rf = RequestFactory()
5663
request = rf.get("/hello/")
5764
result = validate_request(request)
@@ -64,6 +71,9 @@ def test_validate_response_pass(collection_request: HttpRequest) -> None:
6471
6572
Args:
6673
collection_request: A Django request object
74+
75+
Raises:
76+
AssertionError: If validation fails or returns unexpected status code.
6777
"""
6878
response = HttpResponse()
6979
response["Content-Type"] = "application/tar"
@@ -80,6 +90,9 @@ def test_validate_response_fail(collection_request: HttpRequest) -> None:
8090
8191
Args:
8292
collection_request: A Django request object
93+
94+
Raises:
95+
AssertionError: If validation passes when it should fail.
8396
"""
8497
response = HttpResponse()
8598
response["Content-Type"] = "application/tar"

0 commit comments

Comments
 (0)