Skip to content

Commit 5660964

Browse files
committed
Fix unit tests
1 parent 79b8c13 commit 5660964

File tree

1 file changed

+2
-20
lines changed

1 file changed

+2
-20
lines changed

tests/test_relay.py

Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@
55
import os
66
from pathlib import Path
77
import shutil
8-
import subprocess
9-
from subprocess import CompletedProcess
108
from typing import Any, Callable, IO, NamedTuple, Optional, Union
119

1210
from _pytest.monkeypatch import MonkeyPatch
@@ -173,7 +171,7 @@ def do_setup(
173171
- relay.get_disk_utilization_str()
174172
175173
The mock classes seem to be necessary in order to intercept the
176-
respective member functions, possibly because these native
174+
respective member functions, possibly because these are native
177175
implementations instead of "pure Python" (or, maybe I just don't
178176
know what I'm doing).
179177
@@ -490,28 +488,13 @@ def test_command_with_server_error(monkeypatch: MonkeyPatch):
490488
TestRelay.check_result(result, exit_code=2, stderr="Error running the server")
491489

492490
@staticmethod
493-
@pytest.mark.parametrize(
494-
"files_str,returncode",
495-
(("We've got files!", 0), ("We've got NO files!", 1)),
496-
)
497-
def test_relay_status_operation(
498-
files_str: str, returncode: int, monkeypatch: MonkeyPatch
499-
):
491+
def test_relay_status_operation(monkeypatch: MonkeyPatch):
500492
"""Test GET /<server_id> method operation"""
501493

502-
def mock_run(args: Union[str, list[str]], *, cwd: str, **_kwargs):
503-
"""Mock for subprocess.run()"""
504-
assert str(cwd) == relay.DEFAULT_FILES_DIRECTORY
505-
key = "stdout" if returncode == 0 else "stderr"
506-
kwargs = {"args": args, "returncode": returncode, key: files_str}
507-
return CompletedProcess(**kwargs)
508-
509494
def validate_relay(response: HTTPResponse):
510495
"""Validate the response from the HTTP method call"""
511496
assert response.status_code == HTTPStatus.OK
512497
assert TestRelay.DISK_STR in response.body["disk utilization"]
513-
key = "files" if returncode == 0 else "error"
514-
assert files_str in response.body[key]
515498

516499
with monkeypatch.context() as m:
517500
mock = mock_app_method_call(
@@ -520,7 +503,6 @@ def validate_relay(response: HTTPResponse):
520503
method_args={"server_id": TestRelay.SERVER_ID_TEXT},
521504
)
522505
TestRelay.do_setup(m, func=mock)
523-
m.setattr(subprocess, "run", mock_run)
524506
result = TestRelay.invoke_main()
525507
TestRelay.check_result(result)
526508

0 commit comments

Comments
 (0)