style: Fix flake8 errors in onboarding tests

This commit is contained in:
Paul Gauthier (aider) 2025-03-31 08:41:35 +13:00
parent 24c074eeaa
commit 650c4cf948

View file

@ -34,19 +34,6 @@ class DummyIO:
pass pass
# Import the functions to be tested
from aider.onboarding import (
check_openrouter_tier,
exchange_code_for_key,
find_available_port,
generate_pkce_codes,
offer_openrouter_oauth,
select_default_model,
start_openrouter_oauth_flow,
try_to_select_default_model,
)
class TestOnboarding(unittest.TestCase): class TestOnboarding(unittest.TestCase):
@patch("requests.get") @patch("requests.get")
def test_check_openrouter_tier_free(self, mock_get): def test_check_openrouter_tier_free(self, mock_get):
@ -372,11 +359,10 @@ class TestOnboarding(unittest.TestCase):
io_mock.tool_warning.assert_any_call( io_mock.tool_warning.assert_any_call(
"No LLM model was specified and no API keys were provided." "No LLM model was specified and no API keys were provided."
) )
# The second call to try_select finds the model, so the *outer* function logs the usage # The second call to try_select finds the model, so the *outer* function logs the usage.
# Note: The actual warning comes from the second call within select_default_model, not try_select itself # Note: The warning comes from the second call within select_default_model,
# Let's refine this check - the warning should happen *after* the second try_select call # not try_select itself.
# We can't easily check call order between mocks like this without more complex setup. # We verify the final state and model returned.
# Instead, let's verify the final state and model returned.
# --- Tests for offer_openrouter_oauth --- # --- Tests for offer_openrouter_oauth ---
@patch("aider.onboarding.start_openrouter_oauth_flow", return_value="new_or_key") @patch("aider.onboarding.start_openrouter_oauth_flow", return_value="new_or_key")
@ -473,15 +459,14 @@ class TestOnboarding(unittest.TestCase):
mock_shutdown_event.is_set.side_effect = [False, True] # Loop once, then shutdown mock_shutdown_event.is_set.side_effect = [False, True] # Loop once, then shutdown
mock_shutdown_event.wait.return_value = True # Callback received before timeout mock_shutdown_event.wait.return_value = True # Callback received before timeout
# Need to simulate the callback setting the auth_code *within* the flow # Need to simulate the callback setting the auth_code *within* the flow.
# This is tricky because it happens in a separate thread in reality. # This is tricky because it happens in a separate thread in reality.
# We'll simulate it by having `shutdown_server.wait` return, and then check `auth_code`. # We'll simulate it by having `shutdown_server.wait` return.
# The actual setting of `auth_code` happens inside the mocked handler, which we don't run here. # The actual setting of `auth_code` happens inside the mocked handler (not run here).
# Instead, we'll patch `exchange_code_for_key` which is called *after* the wait if successful. # Instead, we patch `exchange_code_for_key` called after the wait if successful.
# Let's refine the approach: We can't easily mock the internal state (`auth_code`) set by the # Refined approach: Assume the wait completes successfully (simulating the callback)
# server thread. Instead, we'll assume the wait completes successfully (simulating the callback) # and verify subsequent steps (exchange_code_for_key, saving key) are called.
# and verify that the subsequent steps (exchange_code_for_key, saving key) are called.
mock_event_cls.side_effect = [mock_server_started_event, mock_shutdown_event] mock_event_cls.side_effect = [mock_server_started_event, mock_shutdown_event]