Skip to content

Commit 5bcbf56

Browse files
jwesleyeclaude
andcommitted
style: apply ruff formatting for v0.1.0 release
Auto-formatted 10 files with ruff format Minor formatting adjustments for consistency 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 82dd8c3 commit 5bcbf56

11 files changed

Lines changed: 83 additions & 37 deletions

src/basic_agent_chat_loop/components/template_manager.py

Lines changed: 30 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,9 @@ def _initialize_templates(self):
3333
self.prompts_dir.mkdir(parents=True, exist_ok=True)
3434

3535
# Create sample templates
36-
self._create_sample_template("explain", """# Explain this code
36+
self._create_sample_template(
37+
"explain",
38+
"""# Explain this code
3739
3840
Please explain the following code in detail:
3941
@@ -44,9 +46,12 @@ def _initialize_templates(self):
4446
- How it works
4547
- Any potential issues or improvements
4648
- Best practices being followed or violated
47-
""")
49+
""",
50+
)
4851

49-
self._create_sample_template("review", """# Code Review
52+
self._create_sample_template(
53+
"review",
54+
"""# Code Review
5055
5156
Please review the following code:
5257
@@ -58,9 +63,12 @@ def _initialize_templates(self):
5863
- Performance considerations
5964
- Security concerns
6065
- Suggestions for improvement
61-
""")
66+
""",
67+
)
6268

63-
self._create_sample_template("debug", """# Debug Help
69+
self._create_sample_template(
70+
"debug",
71+
"""# Debug Help
6472
6573
I'm having trouble with this code:
6674
@@ -71,9 +79,12 @@ def _initialize_templates(self):
7179
2. Explain why it's happening
7280
3. Suggest a fix
7381
4. Provide the corrected code
74-
""")
82+
""",
83+
)
7584

76-
self._create_sample_template("optimize", """# Optimize This Code
85+
self._create_sample_template(
86+
"optimize",
87+
"""# Optimize This Code
7788
7889
Please optimize the following code:
7990
@@ -84,9 +95,12 @@ def _initialize_templates(self):
8495
- Memory efficiency
8596
- Code simplicity
8697
- Best practices
87-
""")
98+
""",
99+
)
88100

89-
self._create_sample_template("test", """# Write Tests
101+
self._create_sample_template(
102+
"test",
103+
"""# Write Tests
90104
91105
Please write comprehensive tests for the following code:
92106
@@ -96,9 +110,12 @@ def _initialize_templates(self):
96110
- Unit tests for all functions
97111
- Edge cases and error handling
98112
- Test descriptions explaining what each test validates
99-
""")
113+
""",
114+
)
100115

101-
self._create_sample_template("document", """# Add Documentation
116+
self._create_sample_template(
117+
"document",
118+
"""# Add Documentation
102119
103120
Please add comprehensive documentation to this code:
104121
@@ -109,7 +126,8 @@ def _initialize_templates(self):
109126
- Inline comments for complex logic
110127
- Usage examples
111128
- Type hints if missing
112-
""")
129+
""",
130+
)
113131

114132
except Exception as e:
115133
logger.debug(f"Could not initialize templates: {e}")

src/basic_agent_chat_loop/components/ui_components.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,9 +124,13 @@ def render(self) -> str:
124124
# Add tokens if enabled and available
125125
if self.show_tokens and self.total_tokens > 0:
126126
if self.total_tokens >= self.TOKEN_MILLIONS_THRESHOLD:
127-
token_str = f"{self.total_tokens / self.TOKEN_MILLIONS_THRESHOLD:.1f}M tokens"
127+
token_str = (
128+
f"{self.total_tokens / self.TOKEN_MILLIONS_THRESHOLD:.1f}M tokens"
129+
)
128130
elif self.total_tokens >= self.TOKEN_THOUSANDS_THRESHOLD:
129-
token_str = f"{self.total_tokens / self.TOKEN_THOUSANDS_THRESHOLD:.1f}K tokens"
131+
token_str = (
132+
f"{self.total_tokens / self.TOKEN_THOUSANDS_THRESHOLD:.1f}K tokens"
133+
)
130134
else:
131135
token_str = f"{self.total_tokens} tokens"
132136
parts.append(token_str)

tests/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
"""Tests for basic_agent_chat_loop."""
1+
"""Tests for basic_agent_chat_loop."""

tests/conftest.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
if str(src_path) not in sys.path:
1111
sys.path.insert(0, str(src_path))
1212

13+
1314
@pytest.fixture
1415
def temp_config_file(tmp_path):
1516
"""Create a temporary config file."""
@@ -25,20 +26,23 @@ def temp_config_file(tmp_path):
2526
""")
2627
return config_file
2728

29+
2830
@pytest.fixture
2931
def temp_aliases_file(tmp_path):
3032
"""Create a temporary aliases file."""
3133
aliases_file = tmp_path / ".chat_aliases"
3234
return aliases_file
3335

36+
3437
@pytest.fixture
3538
def mock_agent():
3639
"""Create a mock agent for testing."""
40+
3741
class MockAgent:
3842
def __init__(self):
3943
self.name = "Test Agent"
4044
self.description = "A test agent"
41-
self.model = type('obj', (object,), {'model_id': 'test-model'})()
45+
self.model = type("obj", (object,), {"model_id": "test-model"})()
4246

4347
def __call__(self, query):
4448
return {"message": "Test response"}

tests/unit/test_agent_loader.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,9 @@ def test_load_agent_without_root_agent(self, tmp_path):
123123
agent_file = tmp_path / "no_root.py"
124124
agent_file.write_text("# No root_agent here")
125125

126-
with pytest.raises(AttributeError, match="must expose a 'root_agent' attribute"):
126+
with pytest.raises(
127+
AttributeError, match="must expose a 'root_agent' attribute"
128+
):
127129
load_agent_module(str(agent_file))
128130

129131
def test_agent_directory_added_to_sys_path(self, mock_agent_file):

tests/unit/test_alias_manager.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,9 @@ def test_add_alias_nonexistent_path(self, alias_manager):
8686
assert success is False
8787
assert "not found" in message
8888

89-
def test_add_alias_duplicate_without_overwrite(self, populated_alias_manager, tmp_path):
89+
def test_add_alias_duplicate_without_overwrite(
90+
self, populated_alias_manager, tmp_path
91+
):
9092
"""Test adding duplicate alias without overwrite flag."""
9193
agent_path = tmp_path / "new_agent.py"
9294
agent_path.write_text("# new agent")
@@ -98,7 +100,9 @@ def test_add_alias_duplicate_without_overwrite(self, populated_alias_manager, tm
98100
assert "already exists" in message
99101
assert "--overwrite" in message
100102

101-
def test_add_alias_duplicate_with_overwrite(self, populated_alias_manager, tmp_path):
103+
def test_add_alias_duplicate_with_overwrite(
104+
self, populated_alias_manager, tmp_path
105+
):
102106
"""Test adding duplicate alias with overwrite flag."""
103107
agent_path = tmp_path / "new_agent.py"
104108
agent_path.write_text("# new agent")

tests/unit/test_chat_config.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,9 @@ def test_get_config_reload(self, temp_config_file, tmp_path, monkeypatch):
318318
config2 = get_config(temp_config_file, reload=True)
319319

320320
# Should be different configuration
321-
assert config1.get("features.show_tokens") != config2.get("features.show_tokens")
321+
assert config1.get("features.show_tokens") != config2.get(
322+
"features.show_tokens"
323+
)
322324

323325

324326
class TestEdgeCases:

tests/unit/test_chat_loop_utils.py

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,9 @@ def test_extract_none_response(self):
187187
def test_extract_usage_from_dict_result_bedrock(self):
188188
"""Test extraction from AWS Bedrock style response."""
189189
agent = Mock()
190-
with patch("basic_agent_chat_loop.chat_loop.extract_agent_metadata") as mock_extract:
190+
with patch(
191+
"basic_agent_chat_loop.chat_loop.extract_agent_metadata"
192+
) as mock_extract:
191193
mock_extract.return_value = {"model_id": "test", "tool_count": 0}
192194
chat_loop = ChatLoop(agent, "Test", "Desc")
193195

@@ -208,7 +210,9 @@ def test_extract_usage_from_dict_result_bedrock(self):
208210
def test_extract_usage_from_object_anthropic(self):
209211
"""Test extraction from Anthropic style response."""
210212
agent = Mock()
211-
with patch("basic_agent_chat_loop.chat_loop.extract_agent_metadata") as mock_extract:
213+
with patch(
214+
"basic_agent_chat_loop.chat_loop.extract_agent_metadata"
215+
) as mock_extract:
212216
mock_extract.return_value = {"model_id": "test", "tool_count": 0}
213217
chat_loop = ChatLoop(agent, "Test", "Desc")
214218

@@ -224,7 +228,9 @@ def test_extract_usage_from_object_anthropic(self):
224228
def test_extract_usage_from_dict_usage(self):
225229
"""Test extraction from dict with usage key."""
226230
agent = Mock()
227-
with patch("basic_agent_chat_loop.chat_loop.extract_agent_metadata") as mock_extract:
231+
with patch(
232+
"basic_agent_chat_loop.chat_loop.extract_agent_metadata"
233+
) as mock_extract:
228234
mock_extract.return_value = {"model_id": "test", "tool_count": 0}
229235
chat_loop = ChatLoop(agent, "Test", "Desc")
230236

@@ -239,7 +245,9 @@ def test_extract_usage_from_dict_usage(self):
239245
def test_extract_usage_prompt_completion_tokens(self):
240246
"""Test extraction with prompt_tokens/completion_tokens names."""
241247
agent = Mock()
242-
with patch("basic_agent_chat_loop.chat_loop.extract_agent_metadata") as mock_extract:
248+
with patch(
249+
"basic_agent_chat_loop.chat_loop.extract_agent_metadata"
250+
) as mock_extract:
243251
mock_extract.return_value = {"model_id": "test", "tool_count": 0}
244252
chat_loop = ChatLoop(agent, "Test", "Desc")
245253

@@ -257,7 +265,9 @@ def test_extract_usage_prompt_completion_tokens(self):
257265
def test_extract_usage_zero_tokens(self):
258266
"""Test with zero token usage."""
259267
agent = Mock()
260-
with patch("basic_agent_chat_loop.chat_loop.extract_agent_metadata") as mock_extract:
268+
with patch(
269+
"basic_agent_chat_loop.chat_loop.extract_agent_metadata"
270+
) as mock_extract:
261271
mock_extract.return_value = {"model_id": "test", "tool_count": 0}
262272
chat_loop = ChatLoop(agent, "Test", "Desc")
263273

@@ -271,7 +281,9 @@ def test_extract_usage_zero_tokens(self):
271281
def test_extract_usage_partial_tokens(self):
272282
"""Test with only input tokens."""
273283
agent = Mock()
274-
with patch("basic_agent_chat_loop.chat_loop.extract_agent_metadata") as mock_extract:
284+
with patch(
285+
"basic_agent_chat_loop.chat_loop.extract_agent_metadata"
286+
) as mock_extract:
275287
mock_extract.return_value = {"model_id": "test", "tool_count": 0}
276288
chat_loop = ChatLoop(agent, "Test", "Desc")
277289

tests/unit/test_template_manager.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
"""Tests for TemplateManager component."""
22

3-
from pathlib import Path
43

54
import pytest
65

@@ -34,10 +33,7 @@ def populated_prompts_dir(prompts_dir):
3433

3534
# Template with different heading
3635
(prompts_dir / "complex.md").write_text(
37-
"# Complex Template\n"
38-
"\n"
39-
"Content: {input}\n"
40-
"Additional: {extra}"
36+
"# Complex Template\n\nContent: {input}\nAdditional: {extra}"
4137
)
4238

4339
return prompts_dir
@@ -104,7 +100,9 @@ def test_list_with_descriptions_no_heading(self, prompts_dir):
104100
assert len(templates) == 1
105101
assert templates[0] == ("simple", "simple") # Uses name as description
106102

107-
def test_list_with_descriptions_with_heading(self, prompts_dir, populated_prompts_dir):
103+
def test_list_with_descriptions_with_heading(
104+
self, prompts_dir, populated_prompts_dir
105+
):
108106
"""Test listing templates with markdown headings."""
109107
manager = TemplateManager(prompts_dir)
110108
templates = manager.list_templates_with_descriptions()
@@ -143,7 +141,9 @@ def test_load_simple_template(self, prompts_dir, populated_prompts_dir):
143141

144142
assert content == "This is a simple template."
145143

146-
def test_load_template_with_variable_substitution(self, prompts_dir, populated_prompts_dir):
144+
def test_load_template_with_variable_substitution(
145+
self, prompts_dir, populated_prompts_dir
146+
):
147147
"""Test loading template and substituting variables."""
148148
manager = TemplateManager(prompts_dir)
149149
content = manager.load_template("review", "my_code.py")
@@ -198,7 +198,9 @@ def test_empty_template_file(self, prompts_dir):
198198

199199
def test_template_without_input_placeholder(self, prompts_dir):
200200
"""Test loading template without {input} placeholder."""
201-
(prompts_dir / "no_placeholder.md").write_text("# Title\n\nContent without placeholder")
201+
(prompts_dir / "no_placeholder.md").write_text(
202+
"# Title\n\nContent without placeholder"
203+
)
202204

203205
manager = TemplateManager(prompts_dir)
204206
content = manager.load_template("no_placeholder", "extra text")

tests/unit/test_token_tracker.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
"""Tests for TokenTracker component."""
2-
import pytest
2+
33
from basic_agent_chat_loop.components.token_tracker import TokenTracker
44

55

0 commit comments

Comments
 (0)