Skip to content

Commit 5a2784c

Browse files
[STYLE] Apply suggestions from code review (- WIP PR #178 -)
- Fixed some typos - Added some docstrings Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
1 parent 12de4bd commit 5a2784c

File tree

1 file changed

+23
-7
lines changed

1 file changed

+23
-7
lines changed

tests/test_hear_server.py

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -44,34 +44,50 @@ class McastHearTestSuite(context.BasicUsageTestSuite):
4444

4545
@staticmethod
4646
def get_default_ip():
47+
"""Get the default IP address of the machine.
48+
49+
Returns:
50+
str: The IP address of the default network interface.
51+
52+
Note:
53+
Uses 203.0.113.1 (TEST-NET-3) for RFC 5737 compliance.
54+
Port 59095 is chosen as an arbitrary high port number.
55+
"""
4756
try:
4857
# Create a socket connection to an external address
4958
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
5059
# Connect to a public non-routable IP
5160
s.connect(("203.0.113.1", 59095))
5261
# Get the IP address of the default interface
5362
ip = s.getsockname()[0]
63+
except socket.error as e:
64+
raise RuntimeError("Failed to determine default IP") from e
5465
finally:
5566
s.close()
5667
return ip
5768

58-
5969
class McastServerTestSuite(McastHearTestSuite):
6070

6171
__module__ = """tests.test_hear_server"""
6272

6373
__name__ = """tests.test_hear_server.McastServerTestSuite"""
6474

6575
def test_handle_error_without_stop_in_request(self):
76+
"""
77+
Test McastServer.handle_error with a non-STOP request.
78+
79+
Verifies that the server properly handles requests without
80+
the STOP command and cleans up resources.
81+
"""
6682
theResult = False
67-
fail_fixture = str("""Mock(BLAH) --> Handller-HEAR == error""")
83+
fail_fixture = str("""Mock(BLAH) --> Handler-HEAR == error""")
6884
_fixture_port_num = self._the_test_port
6985
try:
7086
self.assertIsNotNone(_fixture_port_num)
7187
self.assertIsInstance(_fixture_port_num, int)
7288
# Create an instance of McastServer
73-
server_adddress = ('224.0.0.1', _fixture_port_num)
74-
server = multicast.hear.McastServer(server_adddress, multicast.hear.HearUDPHandler)
89+
server_address = ('224.0.0.1', _fixture_port_num)
90+
server = multicast.hear.McastServer(server_address, multicast.hear.HearUDPHandler)
7591
client_address = (self.get_default_ip(), _fixture_port_num)
7692
# Mock a request not containing "STOP"
7793
request = (str("Regular message"), multicast.genSocket())
@@ -89,14 +105,14 @@ def test_handle_error_without_stop_in_request(self):
89105

90106
def test_handle_error_with_none_request(self):
91107
theResult = False
92-
fail_fixture = str("""Mock(EMPTY) --X Handller-HEAR != Safe""")
108+
fail_fixture = str("""Mock(EMPTY) --X Handler-HEAR != Safe""")
93109
_fixture_port_num = self._the_test_port
94110
try:
95111
self.assertIsNotNone(_fixture_port_num)
96112
self.assertIsInstance(_fixture_port_num, int)
97113
# Create an instance of McastServer
98-
server_adddress = ('224.0.0.1', _fixture_port_num)
99-
server = multicast.hear.McastServer(server_adddress, multicast.hear.HearUDPHandler)
114+
server_address = ('224.0.0.1', _fixture_port_num)
115+
server = multicast.hear.McastServer(server_address, multicast.hear.HearUDPHandler)
100116
client_address = (self.get_default_ip(), _fixture_port_num)
101117
# Mock None as a request
102118
request = None

0 commit comments

Comments
 (0)