5
5
import os
6
6
from pathlib import Path
7
7
import shutil
8
- import subprocess
9
- from subprocess import CompletedProcess
10
8
from typing import Any , Callable , IO , NamedTuple , Optional , Union
11
9
12
10
from _pytest .monkeypatch import MonkeyPatch
@@ -173,7 +171,7 @@ def do_setup(
173
171
- relay.get_disk_utilization_str()
174
172
175
173
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
177
175
implementations instead of "pure Python" (or, maybe I just don't
178
176
know what I'm doing).
179
177
@@ -490,28 +488,13 @@ def test_command_with_server_error(monkeypatch: MonkeyPatch):
490
488
TestRelay .check_result (result , exit_code = 2 , stderr = "Error running the server" )
491
489
492
490
@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 ):
500
492
"""Test GET /<server_id> method operation"""
501
493
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
-
509
494
def validate_relay (response : HTTPResponse ):
510
495
"""Validate the response from the HTTP method call"""
511
496
assert response .status_code == HTTPStatus .OK
512
497
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 ]
515
498
516
499
with monkeypatch .context () as m :
517
500
mock = mock_app_method_call (
@@ -520,7 +503,6 @@ def validate_relay(response: HTTPResponse):
520
503
method_args = {"server_id" : TestRelay .SERVER_ID_TEXT },
521
504
)
522
505
TestRelay .do_setup (m , func = mock )
523
- m .setattr (subprocess , "run" , mock_run )
524
506
result = TestRelay .invoke_main ()
525
507
TestRelay .check_result (result )
526
508
0 commit comments