style: Fix linting issues in test_coder.py

This commit is contained in:
Paul Gauthier (aider) 2025-02-07 08:39:39 -08:00
parent 52bc51a197
commit af48c46c30

View file

@ -909,17 +909,17 @@ This command will print 'Hello, World!' to the console."""
# Test that system_prompt_prefix is properly set and used # Test that system_prompt_prefix is properly set and used
io = InputOutput(yes=True) io = InputOutput(yes=True)
test_prefix = "Test prefix. " test_prefix = "Test prefix. "
# Create a model with system_prompt_prefix # Create a model with system_prompt_prefix
model = Model("gpt-3.5-turbo") model = Model("gpt-3.5-turbo")
model.system_prompt_prefix = test_prefix model.system_prompt_prefix = test_prefix
coder = Coder.create(model, None, io=io) coder = Coder.create(model, None, io=io)
# Get the formatted messages # Get the formatted messages
chunks = coder.format_messages() chunks = coder.format_messages()
messages = chunks.all_messages() messages = chunks.all_messages()
# Check if the system message contains our prefix # Check if the system message contains our prefix
system_message = next(msg for msg in messages if msg["role"] == "system") system_message = next(msg for msg in messages if msg["role"] == "system")
self.assertTrue(system_message["content"].startswith(test_prefix)) self.assertTrue(system_message["content"].startswith(test_prefix))
@ -927,42 +927,42 @@ This command will print 'Hello, World!' to the console."""
def test_system_prompt_prefix_none(self): def test_system_prompt_prefix_none(self):
# Test behavior when system_prompt_prefix is None # Test behavior when system_prompt_prefix is None
io = InputOutput(yes=True) io = InputOutput(yes=True)
# Create a model without system_prompt_prefix # Create a model without system_prompt_prefix
model = Model("gpt-3.5-turbo") model = Model("gpt-3.5-turbo")
model.system_prompt_prefix = None model.system_prompt_prefix = None
coder = Coder.create(model, None, io=io) coder = Coder.create(model, None, io=io)
# Get the formatted messages # Get the formatted messages
chunks = coder.format_messages() chunks = coder.format_messages()
messages = chunks.all_messages() messages = chunks.all_messages()
# Get the system message # Get the system message
system_message = next(msg for msg in messages if msg["role"] == "system") system_message = next(msg for msg in messages if msg["role"] == "system")
original_content = coder.fmt_system_prompt(coder.gpt_prompts.main_system) original_content = coder.fmt_system_prompt(coder.gpt_prompts.main_system)
# Check that the content matches the original prompt without prefix # Check that the content matches the original prompt without prefix
self.assertEqual(system_message["content"], original_content) self.assertEqual(system_message["content"], original_content)
def test_system_prompt_prefix_empty(self): def test_system_prompt_prefix_empty(self):
# Test behavior when system_prompt_prefix is empty string # Test behavior when system_prompt_prefix is empty string
io = InputOutput(yes=True) io = InputOutput(yes=True)
# Create a model with empty system_prompt_prefix # Create a model with empty system_prompt_prefix
model = Model("gpt-3.5-turbo") model = Model("gpt-3.5-turbo")
model.system_prompt_prefix = "" model.system_prompt_prefix = ""
coder = Coder.create(model, None, io=io) coder = Coder.create(model, None, io=io)
# Get the formatted messages # Get the formatted messages
chunks = coder.format_messages() chunks = coder.format_messages()
messages = chunks.all_messages() messages = chunks.all_messages()
# Get the system message # Get the system message
system_message = next(msg for msg in messages if msg["role"] == "system") system_message = next(msg for msg in messages if msg["role"] == "system")
original_content = coder.fmt_system_prompt(coder.gpt_prompts.main_system) original_content = coder.fmt_system_prompt(coder.gpt_prompts.main_system)
# Check that the content matches the original prompt without prefix # Check that the content matches the original prompt without prefix
self.assertEqual(system_message["content"], original_content) self.assertEqual(system_message["content"], original_content)