Skip to content

Commit 223b83f

Browse files
committed
refactor: rename run_loop to run_multiple for clarity and consistency
1 parent 1724556 commit 223b83f

File tree

6 files changed

+23
-28
lines changed

6 files changed

+23
-28
lines changed

docs/local-development.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ def test_allocations():
184184
run_allocation_test,
185185
reporter=test_reporter,
186186
)
187-
results = test_runner.run_loop(tries)
187+
results = test_runner.run_multiple(tries)
188188
assert False not in results
189189

190190

@@ -337,7 +337,7 @@ def test_allocations():
337337
),
338338
reporter=test_reporter,
339339
)
340-
results = test_runner.run_loop(tries)
340+
results = test_runner.run_multiple(tries)
341341
assert False not in results
342342

343343

examples/team_recommender/tests/example_2_loop/test_allocations_loop.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ def test_allocations():
4343
run_allocation_test,
4444
reporter=test_reporter,
4545
)
46-
results = test_runner.run_loop(tries)
46+
results = test_runner.run_multiple(tries)
4747
assert False not in results
4848

4949

examples/team_recommender/tests/example_3_loop_no_hallucinating/test_allocations_hallucinating.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ def test_allocations():
5151
lambda reporter: run_allocation_test(reporter=reporter, skills_data=skills_data),
5252
reporter=test_reporter,
5353
)
54-
results = test_runner.run_loop(tries)
54+
results = test_runner.run_multiple(tries)
5555
assert False not in results
5656

5757

examples/team_recommender/tests/example_4_gate_on_success_threshold/test_allocations_threshold.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
import json
22
import os
3+
4+
from openai import OpenAI
5+
from tests.settings import ROOT_DIR
6+
37
from cat_ai.reporter import Reporter
48
from cat_ai.runner import Runner
5-
from tests.settings import ROOT_DIR
6-
from openai import OpenAI
79

810

911
def get_all_developer_names(skills_data) -> set[str]:
@@ -26,7 +28,7 @@ def has_expected_success_rate(results: list[bool], expected_success_rate: float)
2628

2729

2830
def test_allocations():
29-
tries = Runner.sample_size(3)
31+
tries = Runner.get_sample_size(3)
3032
skills_json_path = os.path.join(ROOT_DIR, "fixtures", "skills.json")
3133
with open(skills_json_path, "r") as file:
3234
skills_data = json.load(file)
@@ -62,7 +64,7 @@ def test_allocations():
6264
lambda reporter: run_allocation_test(reporter=reporter, skills_data=skills_data),
6365
reporter=test_reporter,
6466
)
65-
results = test_runner.run_loop(tries)
67+
results = test_runner.run_multiple(tries)
6668
failure_threshold = 0.8
6769
assert has_expected_success_rate(results, failure_threshold)
6870

src/cat_ai/runner.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
class Runner:
88
"""Executes test functions and collects results using a reporter."""
99

10-
def __init__(self, test_function: Callable[..., bool], reporter: Reporter) -> None:
10+
def __init__(self, test_function: Callable[[Reporter], bool], reporter: Reporter) -> None:
1111
"""
1212
Initialize the Runner with a test function and reporter.
1313
@@ -42,9 +42,9 @@ def run_once(self, run_number: int = 0) -> bool:
4242
Result from the test function
4343
"""
4444
self.reporter.run_number = run_number
45-
return self.test_function(reporter=self.reporter)
45+
return self.test_function(self.reporter)
4646

47-
def run(self, sample_size: Optional[int] = None) -> List[bool]:
47+
def run_multiple(self, sample_size: Optional[int] = None) -> List[bool]:
4848
"""
4949
Execute the test function multiple times based on sample size.
5050
@@ -55,5 +55,5 @@ def run(self, sample_size: Optional[int] = None) -> List[bool]:
5555
Returns:
5656
List of results from all test runs
5757
"""
58-
runs = sample_size or self.get_sample_size()
58+
runs = sample_size if sample_size is not None else self.get_sample_size()
5959
return [self.run_once(i) for i in range(runs)]

tests/cat_ai/test_runner.py

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@
33

44

55
# Dummy test function that will be passed to Runner
6-
def dummy_test_function(reporter: Reporter):
6+
def dummy_test_function(reporter: Reporter) -> bool:
77
# Imagine that this function does something meaningful
8-
return f"Running test with run number {reporter.run_number}"
8+
# Simply returning True instead of trying to log
9+
return True
910

1011

1112
def test_runner_sample_size(monkeypatch):
@@ -27,7 +28,7 @@ def test_run_once():
2728

2829
# Test run_once
2930
result = runner.run_once(run_number=1)
30-
assert result == "Running test with run number 1"
31+
assert result is True
3132
assert reporter.run_number == 1
3233

3334

@@ -39,14 +40,10 @@ def test_run():
3940
runner = Runner(test_function=dummy_test_function, reporter=reporter)
4041

4142
# Test with explicit sample size parameter
42-
results = runner.run(sample_size=3)
43+
results = runner.run_multiple(sample_size=3)
4344
assert len(results) == 3
44-
assert all(res.startswith("Running test with run number ") for res in results)
45-
expected_results = [
46-
"Running test with run number 0",
47-
"Running test with run number 1",
48-
"Running test with run number 2",
49-
]
45+
assert all(results)
46+
expected_results = [True, True, True]
5047
assert results == expected_results
5148

5249

@@ -61,11 +58,7 @@ def test_run_with_env_variable(monkeypatch):
6158
runner = Runner(test_function=dummy_test_function, reporter=reporter)
6259

6360
# Test without explicit sample size (should use environment variable)
64-
results = runner.run()
61+
results = runner.run_multiple()
6562
assert len(results) == 3
66-
expected_results = [
67-
"Running test with run number 0",
68-
"Running test with run number 1",
69-
"Running test with run number 2",
70-
]
63+
expected_results = [True, True, True]
7164
assert results == expected_results

0 commit comments

Comments
 (0)