Skip to content

Commit 57096ae

Browse files
committed
feat(exceptions): update expections.py
1 parent 598fe95 commit 57096ae

File tree

2 files changed

+57
-1
lines changed

2 files changed

+57
-1
lines changed

src/ansys/tools/common/exceptions.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,36 @@ def __init__(self, message: str) -> None:
3434
self.message = message
3535

3636

37+
class AnsysHostnameValueError(AnsysError):
38+
"""Error raised when hostname value is not valid."""
39+
40+
def __init__(self, msg):
41+
"""Initialize the exception.
42+
43+
Parameters
44+
----------
45+
msg : str
46+
The message to be raised for the exception.
47+
48+
"""
49+
super().__init__(msg)
50+
51+
52+
class AnsysPortValueError(AnsysError):
53+
"""Error raised when port value is not valid."""
54+
55+
def __init__(self, msg):
56+
"""Initialize the exception.
57+
58+
Parameters
59+
----------
60+
msg : str
61+
The message to be raised for the exception.
62+
63+
"""
64+
super().__init__(msg)
65+
66+
3767
class AnsysTypeError(AnsysError):
3868
"""Error raised when an argument is of the wrong type.
3969

tests/test_exceptions.py

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,15 @@
2222

2323
"""Module for exception testing."""
2424

25-
from ansys.tools.common.exceptions import AnsysError, AnsysLogicError, AnsysTypeError, VersionError, VersionSyntaxError
25+
from ansys.tools.common.exceptions import (
26+
AnsysError,
27+
AnsysHostnameValueError,
28+
AnsysLogicError,
29+
AnsysPortValueError,
30+
AnsysTypeError,
31+
VersionError,
32+
VersionSyntaxError,
33+
)
2634

2735

2836
def test_ansys_error():
@@ -34,6 +42,24 @@ def test_ansys_error():
3442
assert e.message == "This is a test error."
3543

3644

45+
def test_ansys_hostname_value_error():
46+
"""Test the AnsysHostnameValueError exception."""
47+
try:
48+
raise AnsysHostnameValueError("Only localhost is supported.")
49+
except AnsysHostnameValueError as e:
50+
assert str(e) == "Only localhost is supported."
51+
assert e.message == "Only localhost is supported."
52+
53+
54+
def test_ansys_port_value_error():
55+
"""Test the AnsysPortValueError exception."""
56+
try:
57+
raise AnsysPortValueError("Port number must be in range from 0 to 65535")
58+
except AnsysPortValueError as e:
59+
assert str(e) == "Port number must be in range from 0 to 65535"
60+
assert e.message == "Port number must be in range from 0 to 65535"
61+
62+
3763
def test_ansys_type_error():
3864
"""Test the AnsysTypeError exception."""
3965
try:

0 commit comments

Comments
 (0)