Skip to content

Commit ea2ec8f

Browse files
committed
fix
1 parent 51716e5 commit ea2ec8f

File tree

2 files changed

+90
-5
lines changed

2 files changed

+90
-5
lines changed

src/ansys/tools/common/cyberchannel.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -190,19 +190,16 @@ def create_insecure_channel(
190190

191191

192192
def create_uds_channel(
193-
uds_fullpath: str | Path | None = None,
194193
uds_service: str | None = None,
195194
uds_dir: str | Path | None = None,
196195
uds_id: str | None = None,
197196
grpc_options: list[tuple[str, object]] | None = None,
197+
uds_fullpath: str | Path | None = None,
198198
) -> grpc.Channel:
199199
"""Create a gRPC channel using Unix Domain Sockets (UDS).
200200
201201
Parameters
202202
----------
203-
uds_fullpath : str | Path | None
204-
Full path to the UDS socket file.
205-
By default `None` and thus it will use the `uds_service`, `uds_dir` and `uds_id` parameters.
206203
uds_service : str
207204
Service name for the UDS socket.
208205
uds_dir : str | Path | None
@@ -216,6 +213,9 @@ def create_uds_channel(
216213
gRPC channel options to pass when creating the channel.
217214
Each option is a tuple of the form ("option_name", value).
218215
By default `None` and thus only the default authority option is added.
216+
uds_fullpath : str | Path | None
217+
Full path to the UDS socket file.
218+
By default `None` and thus it will use the `uds_service`, `uds_dir` and `uds_id` parameters.
219219
220220
Returns
221221
-------
@@ -489,10 +489,10 @@ def verify_transport_mode(transport_mode: str, mode: str | None = None) -> None:
489489

490490

491491
def verify_uds_socket(
492-
uds_fullpath: str | Path | None = None,
493492
uds_service: str | None = None,
494493
uds_dir: Path | None = None,
495494
uds_id: str | None = None,
495+
uds_fullpath: str | Path | None = None,
496496
) -> bool:
497497
"""Verify that the UDS socket file has been created.
498498
@@ -507,6 +507,9 @@ def verify_uds_socket(
507507
Unique identifier for the UDS socket (optional).
508508
By default `None` and thus it will use "<uds_service>.sock".
509509
Otherwise, the socket filename will be "<uds_service>-<uds_id>.sock".
510+
uds_fullpath : str | Path | None
511+
Full path to the UDS socket file.
512+
By default `None` and thus it will use the `uds_service`, `uds_dir` and `uds_id` parameters.
510513
511514
Returns
512515
-------

tests/test_cyberchannel.py

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
# Copyright (C) 2025 ANSYS, Inc. and/or its affiliates.
2+
# SPDX-License-Identifier: MIT
3+
#
4+
#
5+
# Permission is hereby granted, free of charge, to any person obtaining a copy
6+
# of this software and associated documentation files (the "Software"), to deal
7+
# in the Software without restriction, including without limitation the rights
8+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
# copies of the Software, and to permit persons to whom the Software is
10+
# furnished to do so, subject to the following conditions:
11+
#
12+
# The above copyright notice and this permission notice shall be included in all
13+
# copies or substantial portions of the Software.
14+
#
15+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
# SOFTWARE.
22+
"""Tests for cyberchannel."""
23+
24+
from pathlib import Path
25+
import tempfile
26+
27+
import pytest
28+
29+
from ansys.tools.common import cyberchannel
30+
31+
32+
def test_version_tuple():
33+
"""Test version tuple."""
34+
assert cyberchannel.version_tuple("1.2.3") == (1, 2, 3)
35+
assert cyberchannel.version_tuple("1.2.3.4") == (1, 2, 3, 4)
36+
assert cyberchannel.version_tuple("1.0.0") == (1, 0, 0)
37+
38+
39+
def test_cyberchannel_functions():
40+
"""Test cyberchannel functions."""
41+
assert cyberchannel.check_grpc_version()
42+
assert cyberchannel.is_uds_supported()
43+
uds_path = cyberchannel.determine_uds_folder()
44+
uds_path.mkdir(parents=True, exist_ok=True)
45+
assert uds_path.is_dir()
46+
assert uds_path.exists()
47+
uds_path.rmdir()
48+
cyberchannel.verify_transport_mode(transport_mode="insecure", mode="local")
49+
with pytest.raises(ValueError):
50+
cyberchannel.verify_transport_mode(transport_mode="invalid_mode", mode="mode1")
51+
52+
53+
def test_cyberchannel_insecure():
54+
"""Test cyberchannel insecure."""
55+
ch = cyberchannel.create_insecure_channel(host="localhost", port=12345)
56+
assert ch is not None
57+
assert ch._channel.target().decode() == "dns:///localhost:12345"
58+
assert not ch.close()
59+
60+
61+
def test_cyberchannel_wnua():
62+
"""Test cyberchannel wnua."""
63+
ch = cyberchannel.create_wnua_channel(host="localhost", port=12345)
64+
assert ch is not None
65+
assert ch._channel.target().decode() == "dns:///localhost:12345"
66+
assert not ch.close()
67+
68+
69+
def test_cyberchannel_uds():
70+
"""Test cyberchannel uds."""
71+
uds_file = Path(tempfile.gettempdir()) / "test_uds.sock"
72+
with uds_file.open("w"):
73+
pass
74+
ch = cyberchannel.create_uds_channel(uds_fullpath=uds_file)
75+
assert ch is not None
76+
assert ch._channel.target().decode() == f"unix:{uds_file}"
77+
assert not ch.close()
78+
79+
ch = cyberchannel.create_uds_channel("service_name")
80+
assert ch is not None
81+
assert ch._channel.target().decode() == f"unix:{cyberchannel.determine_uds_folder() / 'service_name.sock'}"
82+
assert not ch.close()

0 commit comments

Comments
 (0)