Skip to content

Commit 57f4618

Browse files
committed
Fix linting errors in tests
1 parent 12bad7a commit 57f4618

5 files changed

Lines changed: 87 additions & 31 deletions

File tree

tests/balance_studio/test_cli.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import sys
2-
from pathlib import Path
31
from unittest.mock import MagicMock, patch
42

53
import pytest
@@ -39,10 +37,16 @@ def test_main_success(mock_script_path):
3937
# specifically when resolving the script path
4038
with patch("gengine.balance_studio.cli.Path") as mock_path_cls:
4139
# Configure the mock path to point to our temp script
42-
# The logic in cli.py is: Path(__file__).resolve().parents[3] / "scripts"
40+
# The logic in cli.py is:
41+
# Path(__file__).resolve().parents[3] / "scripts"
4342
# We'll just mock the final result of that chain
4443
mock_resolved_path = MagicMock()
45-
mock_resolved_path.parents = [MagicMock(), MagicMock(), MagicMock(), MagicMock()]
44+
mock_resolved_path.parents = [
45+
MagicMock(),
46+
MagicMock(),
47+
MagicMock(),
48+
MagicMock(),
49+
]
4650
# The 4th parent (index 3) is the root
4751
mock_root = mock_resolved_path.parents[3]
4852
mock_root.__truediv__.return_value = mock_script_path.parent
@@ -72,4 +76,7 @@ def test_main_script_not_found():
7276

7377
assert result == 1
7478
mock_stderr.write.assert_called_once()
75-
assert "Failed to load Balance Studio script" in mock_stderr.write.call_args[0][0]
79+
assert (
80+
"Failed to load Balance Studio script"
81+
in mock_stderr.write.call_args[0][0]
82+
)

tests/balance_studio/test_overlays.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1+
12
import pytest
23
import yaml
3-
from pathlib import Path
4+
45
from gengine.balance_studio.overlays import (
56
ConfigOverlay,
6-
create_tuning_overlay,
77
deep_merge,
88
load_overlay_directory,
99
merge_overlays,

tests/balance_studio/test_report_viewer.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import json
2-
from pathlib import Path
31
from unittest.mock import MagicMock, patch
42

53
import pytest
@@ -40,15 +38,23 @@ def sample_data():
4038
"sweeps": [
4139
{
4240
"sweep_id": "1",
43-
"parameters": {"strategy": "balanced", "difficulty": "normal", "seed": 42},
41+
"parameters": {
42+
"strategy": "balanced",
43+
"difficulty": "normal",
44+
"seed": 42,
45+
},
4446
"results": {"final_stability": 0.8, "actions_taken": 10},
4547
},
4648
{
4749
"sweep_id": "2",
48-
"parameters": {"strategy": "aggressive", "difficulty": "hard", "seed": 123},
50+
"parameters": {
51+
"strategy": "aggressive",
52+
"difficulty": "hard",
53+
"seed": 123,
54+
},
4955
"results": {"final_stability": 0.2, "actions_taken": 20},
50-
"error": "Some error"
51-
}
56+
"error": "Some error",
57+
},
5258
]
5359
}
5460

tests/balance_studio/test_workflows.py

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
from unittest.mock import MagicMock, patch
55

66
import pytest
7-
import yaml
87

98
from gengine.balance_studio.workflows import (
109
CompareConfigsConfig,
@@ -114,7 +113,6 @@ def test_run_config_comparison_success(mock_subprocess_run, mock_datetime, tmp_p
114113
mock_subprocess_run.return_value.returncode = 0
115114

116115
# Create dummy summary files for both sweeps
117-
timestamp = "20230101_120000"
118116

119117
def side_effect(*args, **kwargs):
120118
# Determine if this is sweep A or B based on args
@@ -165,12 +163,17 @@ def test_run_tuning_test(mock_subprocess_run, mock_datetime, tmp_path):
165163
)
166164

167165
# Mock yaml loading/dumping
168-
with patch("yaml.safe_load") as mock_safe_load, patch("yaml.safe_dump") as mock_safe_dump:
166+
with (
167+
patch("yaml.safe_load") as mock_safe_load,
168+
patch("yaml.safe_dump"),
169+
):
169170

170171
mock_safe_load.return_value = {"simulation": {"tick_limit": 100}}
171172

172173
# Mock run_config_comparison to avoid complex subprocess mocking again
173-
with patch("gengine.balance_studio.workflows.run_config_comparison") as mock_compare:
174+
with patch(
175+
"gengine.balance_studio.workflows.run_config_comparison"
176+
) as mock_compare:
174177
mock_compare.return_value = WorkflowResult(
175178
workflow_name="compare_configs",
176179
success=True,
@@ -180,7 +183,7 @@ def test_run_tuning_test(mock_subprocess_run, mock_datetime, tmp_path):
180183
)
181184

182185
# We also need to mock file operations for base config
183-
with patch("builtins.open", create=True) as mock_open:
186+
with patch("builtins.open", create=True):
184187
# Setup mock for file existence check
185188
with patch("pathlib.Path.exists") as mock_exists:
186189
mock_exists.return_value = True
@@ -244,7 +247,8 @@ def test_list_historical_reports(tmp_path):
244247
reports = list_historical_reports(reports_dir=reports_dir)
245248

246249
assert len(reports) == 2
247-
# Should be sorted reverse by path (which usually correlates with time if named correctly)
250+
# Should be sorted reverse by path
251+
# (which usually correlates with time if named correctly)
248252
# But glob order depends on OS.
249253
# Let's just check content.
250254
timestamps = [r["timestamp"] for r in reports]
@@ -266,7 +270,9 @@ def test_get_workflow_menu():
266270
assert "view_reports" in ids
267271

268272

269-
def test_run_exploratory_sweep_with_overlay(mock_subprocess_run, mock_datetime, tmp_path):
273+
def test_run_exploratory_sweep_with_overlay(
274+
mock_subprocess_run, mock_datetime, tmp_path
275+
):
270276
"""Test exploratory sweep with overlay."""
271277
from gengine.balance_studio.overlays import ConfigOverlay
272278

tests/scripts/test_echoes_balance_studio.py

Lines changed: 48 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -496,14 +496,20 @@ def mock_cli_workflows():
496496
patch(f"{module_name}.write_html_report") as mock_write:
497497

498498
# Setup default success returns
499-
mock_sweep.return_value = MagicMock(success=True, message="Success", output_path="out", errors=[])
499+
mock_sweep.return_value = MagicMock(
500+
success=True, message="Success", output_path="out", errors=[]
501+
)
500502

501503
# Fix for JSON serialization: to_dict should return a real dict
502-
compare_result = MagicMock(success=True, message="Success", output_path="out", data={}, errors=[])
504+
compare_result = MagicMock(
505+
success=True, message="Success", output_path="out", data={}, errors=[]
506+
)
503507
compare_result.to_dict.return_value = {"success": True, "message": "Success"}
504508
mock_compare.return_value = compare_result
505509

506-
mock_tuning.return_value = MagicMock(success=True, message="Success", output_path="out", data={}, errors=[])
510+
mock_tuning.return_value = MagicMock(
511+
success=True, message="Success", output_path="out", data={}, errors=[]
512+
)
507513
mock_list.return_value = []
508514
mock_view.return_value = MagicMock(success=True, message="Success", data={})
509515

@@ -532,7 +538,8 @@ def test_interactive_mode_invalid(self, mock_cli_workflows):
532538

533539
def test_interactive_mode_sweep(self, mock_cli_workflows):
534540
"""Test selecting sweep workflow."""
535-
with patch("builtins.input", side_effect=["1", "", "", "", ""]): # Select 1, then defaults for sweep
541+
# Select 1, then defaults for sweep
542+
with patch("builtins.input", side_effect=["1", "", "", "", ""]):
536543
assert _cli.interactive_mode() == 0
537544
mock_cli_workflows["sweep"].assert_called_once()
538545

@@ -548,7 +555,9 @@ def test_interactive_sweep_defaults(self, mock_cli_workflows):
548555

549556
def test_interactive_sweep_custom(self, mock_cli_workflows):
550557
"""Test interactive sweep with custom inputs."""
551-
with patch("builtins.input", side_effect=["strat1, strat2", "hard", "1, 2", "50"]):
558+
with patch(
559+
"builtins.input", side_effect=["strat1, strat2", "hard", "1, 2", "50"]
560+
):
552561
assert _cli.interactive_sweep() == 0
553562
args = mock_cli_workflows["sweep"].call_args[0][0]
554563
assert args.strategies == ["strat1", "strat2"]
@@ -558,7 +567,9 @@ def test_interactive_sweep_custom(self, mock_cli_workflows):
558567

559568
def test_interactive_compare_success(self, mock_cli_workflows):
560569
"""Test interactive compare workflow."""
561-
with patch("builtins.input", side_effect=["path/a", "Name A", "path/b", "Name B"]):
570+
with patch(
571+
"builtins.input", side_effect=["path/a", "Name A", "path/b", "Name B"]
572+
):
562573
assert _cli.interactive_compare() == 0
563574
args = mock_cli_workflows["compare"].call_args[0][0]
564575
assert str(args.config_a_path) == "path/a"
@@ -573,7 +584,10 @@ def test_interactive_compare_missing_path(self, mock_cli_workflows):
573584

574585
def test_interactive_tuning_success(self, mock_cli_workflows):
575586
"""Test interactive tuning workflow."""
576-
with patch("builtins.input", side_effect=["test_exp", "economy.regen=1.5", "invalid", "flag=true", ""]):
587+
with patch(
588+
"builtins.input",
589+
side_effect=["test_exp", "economy.regen=1.5", "invalid", "flag=true", ""],
590+
):
577591
assert _cli.interactive_tuning() == 0
578592
args = mock_cli_workflows["tuning"].call_args[0][0]
579593
assert args.name == "test_exp"
@@ -592,17 +606,32 @@ def test_interactive_view_reports_empty(self, mock_cli_workflows):
592606
def test_interactive_view_reports_select(self, mock_cli_workflows):
593607
"""Test selecting a report to view."""
594608
mock_cli_workflows["list"].return_value = [
595-
{"timestamp": "2023", "completed_sweeps": 1, "total_sweeps": 1, "strategies": ["s"], "path": "p"}
609+
{
610+
"timestamp": "2023",
611+
"completed_sweeps": 1,
612+
"total_sweeps": 1,
613+
"strategies": ["s"],
614+
"path": "p",
615+
}
596616
]
597-
mock_cli_workflows["view"].return_value.data = {"strategy_stats": {"s": {"avg_stability": 0.5}}}
617+
mock_cli_workflows["view"].return_value.data = {
618+
"strategy_stats": {"s": {"avg_stability": 0.5}}
619+
}
598620

599621
with patch("builtins.input", side_effect=["1"]):
600622
assert _cli.interactive_view_reports() == 0
601623
mock_cli_workflows["view"].assert_called_once()
602624

603625
def test_interactive_view_reports_quit(self, mock_cli_workflows):
604626
"""Test quitting report viewer."""
605-
mock_cli_workflows["list"].return_value = [{"timestamp": "2023", "completed_sweeps": 1, "total_sweeps": 1, "strategies": ["s"]}]
627+
mock_cli_workflows["list"].return_value = [
628+
{
629+
"timestamp": "2023",
630+
"completed_sweeps": 1,
631+
"total_sweeps": 1,
632+
"strategies": ["s"],
633+
}
634+
]
606635
with patch("builtins.input", side_effect=["q"]):
607636
assert _cli.interactive_view_reports() == 0
608637

@@ -666,7 +695,15 @@ def test_cmd_view_reports(self, mock_cli_workflows):
666695
args.limit = 5
667696
args.json = False
668697

669-
mock_cli_workflows["list"].return_value = [{"timestamp": "t", "completed_sweeps": 1, "total_sweeps": 1, "strategies": ["s"], "path": "p"}]
698+
mock_cli_workflows["list"].return_value = [
699+
{
700+
"timestamp": "t",
701+
"completed_sweeps": 1,
702+
"total_sweeps": 1,
703+
"strategies": ["s"],
704+
"path": "p",
705+
}
706+
]
670707

671708
assert _cli.cmd_view_reports(args) == 0
672709
mock_cli_workflows["list"].assert_called_once()

0 commit comments

Comments
 (0)