feat(python/omp-rpc): added user and group options to RpcClient startup

- Added user, group, and extra_groups parameters to RpcClient initialization.
- Propagated those parameters through to subprocess startup calls.
- Added tests to verify the new kwargs are passed correctly, including None defaults and empty extra groups.
This commit is contained in:
can1357
2026-05-15 02:23:43 +02:00
parent 7754607561
commit 2ea1bd96b8
2 changed files with 54 additions and 0 deletions
+45
View File
@@ -0,0 +1,45 @@
from __future__ import annotations
from unittest.mock import patch
import pytest
from omp_rpc import RpcClient
class _Sentinel(Exception):
pass
def _start_and_capture(**kwargs):
client = RpcClient(**kwargs)
with patch("omp_rpc.client.subprocess.Popen", side_effect=_Sentinel("aborted")) as mock_popen:
with pytest.raises(_Sentinel):
client.start()
assert mock_popen.call_count == 1
return mock_popen.call_args
def test_no_user_group_defaults_to_none():
call = _start_and_capture(executable="omp")
assert call.kwargs["user"] is None
assert call.kwargs["group"] is None
assert call.kwargs["extra_groups"] is None
def test_user_and_group_kwargs_threaded():
call = _start_and_capture(
executable="omp",
user=2001,
group="omp",
extra_groups=[2000, "docker"],
)
assert call.kwargs["user"] == 2001
assert call.kwargs["group"] == "omp"
assert call.kwargs["extra_groups"] == [2000, "docker"]
def test_extra_groups_none_distinct_from_empty():
call = _start_and_capture(executable="omp", extra_groups=[])
# [] means an empty supplementary group list and differs from None.
assert call.kwargs["extra_groups"] == []