Skip to content

Commit 38e919a

Browse files
Copilotmykaul
andcommitted
Fix code quality issues in test_cluster.py
- Fix spelling: 'tring' → 'string' in docstring - Remove extra 't' at end of comment - Refactor complex list comprehension for clarity - Use 'is None' instead of '== None' for None comparison Co-authored-by: mykaul <[email protected]>
1 parent 183f20a commit 38e919a

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

tests/unit/test_cluster.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,10 @@ class ClusterTest(unittest.TestCase):
9090

9191
def test_tuple_for_contact_points(self):
9292
cluster = Cluster(contact_points=[('localhost', 9045), ('127.0.0.2', 9046), '127.0.0.3'], port=9999)
93-
localhost_addr = set([addr[0] for addr in [t for (_,_,_,_,t) in socket.getaddrinfo("localhost",80)]])
93+
# Refactored for clarity
94+
addr_info = socket.getaddrinfo("localhost", 80)
95+
sockaddr_tuples = [info[4] for info in addr_info] # info[4] is sockaddr
96+
localhost_addr = set([sockaddr[0] for sockaddr in sockaddr_tuples])
9497
for cp in cluster.endpoints_resolved:
9598
if cp.address in localhost_addr:
9699
assert cp.port == 9045
@@ -107,7 +110,7 @@ def test_invalid_contact_point_types(self):
107110
Cluster(contact_points="not a sequence", protocol_version=4, connect_timeout=1)
108111

109112
def test_port_str(self):
110-
"""Check port passed as tring is converted and checked properly"""
113+
"""Check port passed as string is converted and checked properly"""
111114
cluster = Cluster(contact_points=['127.0.0.1'], port='1111')
112115
for cp in cluster.endpoints_resolved:
113116
if cp.address in ('::1', '127.0.0.1'):
@@ -181,7 +184,7 @@ def test_event_delay_timing(self, *_):
181184
"""
182185
sched = _Scheduler(None)
183186
sched.schedule(0, lambda: None)
184-
sched.schedule(0, lambda: None) # pre-473: "TypeError: unorderable types: function() < function()"t
187+
sched.schedule(0, lambda: None) # pre-473: "TypeError: unorderable types: function() < function()"
185188

186189

187190
class SessionTest(unittest.TestCase):
@@ -291,7 +294,7 @@ def test_default_exec_parameters(self):
291294
assert cluster.profile_manager.default.request_timeout == 10.0
292295
assert session.default_consistency_level == ConsistencyLevel.LOCAL_ONE
293296
assert cluster.profile_manager.default.consistency_level == ConsistencyLevel.LOCAL_ONE
294-
assert session.default_serial_consistency_level == None
297+
assert session.default_serial_consistency_level is None
295298
assert cluster.profile_manager.default.serial_consistency_level == None
296299
assert session.row_factory == named_tuple_factory
297300
assert cluster.profile_manager.default.row_factory == named_tuple_factory

0 commit comments

Comments
 (0)