Skip to content

Commit 2befe31

Browse files
committed
refactor(utils): enforce keyword-only args for functions
Update all function definitions in utils/ to require keyword-only arguments by adding '*' to their signatures. This improves clarity, prevents accidental positional argument usage, and aligns with modern Python best practices for function interfaces.
1 parent 8b36196 commit 2befe31

34 files changed

+394
-359
lines changed

cardano_node_tests/cluster_management/cluster_getter.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ def instance_dir(self) -> pl.Path:
116116
def ports(self) -> cardonnay_local.InstancePorts:
117117
"""Return port mappings for current cluster instance."""
118118
return cluster_nodes.get_cluster_type().cluster_scripts.get_instance_ports(
119-
self.cluster_instance_num
119+
instance_num=self.cluster_instance_num
120120
)
121121

122122
def _create_startup_files_dir(self, instance_num: int) -> pl.Path:
@@ -935,7 +935,7 @@ def get_cluster_instance( # noqa: C901
935935
self.log(f"c{instance_num}: can run test '{cget_status.current_test}'")
936936
# Set environment variables that are needed when respinning the cluster
937937
# and running tests
938-
cluster_nodes.set_cluster_env(instance_num)
938+
cluster_nodes.set_cluster_env(instance_num=instance_num)
939939

940940
# Remove "prio" status file
941941
if prio:

cardano_node_tests/cluster_management/netstat_tools.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,9 @@ def _get_proc_cmdline(pid: int) -> str:
6262

6363
return cmdline
6464

65-
port_nums = cluster_nodes.get_cluster_type().cluster_scripts.get_instance_ports(instance_num)
65+
port_nums = cluster_nodes.get_cluster_type().cluster_scripts.get_instance_ports(
66+
instance_num=instance_num
67+
)
6668
port_strs = [
6769
# Add whitestpace to the end of each port number to avoid matching a port number that is a
6870
# prefix of another port number.

cardano_node_tests/tests/delegation.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ def cluster_and_pool(
9797
if pool_id in stake_pools:
9898
return cluster_obj, pool_id
9999

100-
blocks_before = clusterlib_utils.get_blocks_before(cluster_obj)
100+
blocks_before = clusterlib_utils.get_blocks_before(cluster_obj=cluster_obj)
101101
# Sort pools by how many blocks they produce
102102
pool_ids_s = sorted(blocks_before, key=blocks_before.get, reverse=True) # type: ignore
103103
# Select a pool with reasonable margin

cardano_node_tests/tests/kes.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ def check_kes_period_info_result( # noqa: C901
8282
KesScenarios.INVALID_COUNTERS,
8383
):
8484
instance_ports = cluster_nodes.get_cluster_type().cluster_scripts.get_instance_ports(
85-
cluster_nodes.get_instance_num()
85+
instance_num=cluster_nodes.get_instance_num()
8686
)
8787
prometheus_port = instance_ports.node_ports[pool_num].prometheus
8888
response = http_client.get_session().get(

cardano_node_tests/tests/test_dbsync_config.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -73,26 +73,28 @@ def check_dbsync_state(
7373
f"Invalid column condition format: {condition}"
7474
)
7575
column_condition = condition.value.split(":", 1)[1]
76-
dbsync_utils.check_column_condition(table, column, column_condition)
76+
dbsync_utils.check_column_condition(
77+
table=table, column=column, condition=column_condition
78+
)
7779
else: # Table-level check
7880
assert isinstance(condition, TableCondition), (
7981
f"Invalid table condition format: {condition}"
8082
)
8183
match condition:
8284
case TableCondition.EMPTY:
83-
assert dbsync_utils.table_empty(key), (
85+
assert dbsync_utils.table_empty(table=key), (
8486
f"Expected {key} to be empty, but it is not."
8587
)
8688
case TableCondition.NOT_EMPTY:
87-
assert not dbsync_utils.table_empty(key), (
89+
assert not dbsync_utils.table_empty(table=key), (
8890
f"Expected {key} to have data, but it is empty."
8991
)
9092
case TableCondition.EXISTS:
91-
assert dbsync_utils.table_exists(key), (
93+
assert dbsync_utils.table_exists(table=key), (
9294
f"Expected {key} to exist, but it does not."
9395
)
9496
case TableCondition.NOT_EXISTS:
95-
assert not dbsync_utils.table_exists(key), (
97+
assert not dbsync_utils.table_exists(table=key), (
9698
f"Expected {key} to NOT exist, but it does."
9799
)
98100
case _:

cardano_node_tests/tests/test_kes.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ def cluster_kes(
8282

8383
def _save_metrics(pool_num: int, temp_template: str) -> None:
8484
instance_ports = cluster_nodes.get_cluster_type().cluster_scripts.get_instance_ports(
85-
cluster_nodes.get_instance_num()
85+
instance_num=cluster_nodes.get_instance_num()
8686
)
8787
port = instance_ports.node_ports[pool_num].prometheus
8888

cardano_node_tests/tests/test_metrics.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ def test_available_metrics(
110110
"""Test that list of available metrics == list of expected metrics."""
111111
prometheus_port = (
112112
cluster_nodes.get_cluster_type()
113-
.cluster_scripts.get_instance_ports(cluster_nodes.get_instance_num())
113+
.cluster_scripts.get_instance_ports(instance_num=cluster_nodes.get_instance_num())
114114
.prometheus_pool1
115115
)
116116

@@ -133,9 +133,9 @@ def test_available_metrics(
133133
"""Test that available EKG metrics matches the expected schema."""
134134
ekg_port = (
135135
cluster_nodes.get_cluster_type()
136-
.cluster_scripts.get_instance_ports(cluster_nodes.get_instance_num())
136+
.cluster_scripts.get_instance_ports(instance_num=cluster_nodes.get_instance_num())
137137
.ekg_pool1
138138
)
139139

140140
response = get_ekg_metrics(ekg_port)
141-
model_ekg.Model.validate(response.json())
141+
model_ekg.Model.model_validate(response.json())

cardano_node_tests/tests/test_reconnect.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ def test_metrics_reconnect(
242242

243243
prometheus_port = (
244244
cluster_nodes.get_cluster_type()
245-
.cluster_scripts.get_instance_ports(cluster_nodes.get_instance_num())
245+
.cluster_scripts.get_instance_ports(instance_num=cluster_nodes.get_instance_num())
246246
.prometheus_pool2
247247
)
248248

cardano_node_tests/tests/test_smash.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,9 @@ def locked_pool(
6363
pools_ids = cluster_obj.g_query.get_stake_pools()
6464
locked_pool_number = pool_name.replace("node-pool", "")
6565
pattern = re.compile(r"pool" + re.escape(locked_pool_number) + r"(\D|$)")
66-
pools = [next(dbsync_queries.query_pool_data(p)) for p in pools_ids]
66+
pools = [next(dbsync_queries.query_pool_data(pool_id_bech32=p)) for p in pools_ids]
6767
locked_pool = next(p for p in pools if p.metadata_url and pattern.search(p.metadata_url))
68-
locked_pool_data = dbsync_utils.get_pool_data(locked_pool.view)
68+
locked_pool_data = dbsync_utils.get_pool_data(pool_id_bech32=locked_pool.view)
6969
assert locked_pool_data is not None, "Locked pool data not found!"
7070
return locked_pool_data
7171

@@ -90,7 +90,8 @@ def test_fetch_pool_metadata(
9090
# Offchain metadata is inserted into database few minutes after start of a cluster
9191
def _query_func():
9292
pool_metadata = next(
93-
iter(dbsync_queries.query_off_chain_pool_data(locked_pool.view)), None
93+
iter(dbsync_queries.query_off_chain_pool_data(pool_id_bech32=locked_pool.view)),
94+
None,
9495
)
9596
if pool_metadata is None:
9697
msg = f"no off-chain pool data record found for pool {pool_id}"
@@ -154,7 +155,7 @@ def pool_cleanup():
154155
)
155156
# Ensure re-delisting an already delisted pool returns an error
156157
try:
157-
smash.delist_pool(pool_id)
158+
smash.delist_pool(pool_id=pool_id)
158159
except requests.exceptions.RequestException as err:
159160
check_request_error(
160161
err=err,

cardano_node_tests/tests/tests_conway/test_committee.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -940,7 +940,10 @@ def _get_res_cert(idx: int, cc_auth: governance_utils.CCMemberAuth) -> pl.Path:
940940
_get_res_cert(idx=i, cc_auth=r)
941941
for i, r in enumerate((cc_auth_record1, cc_auth_record2, cc_auth_record3))
942942
if governance_utils.is_cc_active(
943-
auth_committee_state["committee"].get(f"keyHash-{r.key_hash}") or {}
943+
cc_member_state=auth_committee_state["committee"].get(
944+
f"keyHash-{r.key_hash}"
945+
)
946+
or {}
944947
)
945948
]
946949

@@ -1830,7 +1833,7 @@ def _check_rat_enact_state(
18301833
constitution_url = web.publish(file_path=constitution_file)
18311834
constitution_hash = cluster.g_governance.get_anchor_data_hash(file_text=constitution_file)
18321835
(
1833-
const_action,
1836+
_const_action,
18341837
const_action_txid,
18351838
const_action_ix,
18361839
) = conway_common.propose_change_constitution(

0 commit comments

Comments
 (0)