mirror of
https://github.com/Aider-AI/aider.git
synced 2025-05-20 12:24:59 +00:00
style: Reformat code to comply with linter rules
This commit is contained in:
parent
0d75c4d0e3
commit
ddc1556ae0
1 changed files with 10 additions and 9 deletions
|
@ -1,7 +1,8 @@
|
||||||
import unittest
|
|
||||||
import time
|
import time
|
||||||
|
import unittest
|
||||||
from unittest.mock import MagicMock
|
from unittest.mock import MagicMock
|
||||||
from requests.exceptions import ReadTimeout, ConnectionError
|
|
||||||
|
from requests.exceptions import ConnectionError, ReadTimeout
|
||||||
|
|
||||||
import aider
|
import aider
|
||||||
from aider.coders import Coder
|
from aider.coders import Coder
|
||||||
|
@ -16,23 +17,23 @@ class TestHelp(unittest.TestCase):
|
||||||
def retry_with_backoff(func, max_time=60, initial_delay=1, backoff_factor=2):
|
def retry_with_backoff(func, max_time=60, initial_delay=1, backoff_factor=2):
|
||||||
"""
|
"""
|
||||||
Execute a function with exponential backoff retry logic.
|
Execute a function with exponential backoff retry logic.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
func: Function to execute
|
func: Function to execute
|
||||||
max_time: Maximum time in seconds to keep retrying
|
max_time: Maximum time in seconds to keep retrying
|
||||||
initial_delay: Initial delay between retries in seconds
|
initial_delay: Initial delay between retries in seconds
|
||||||
backoff_factor: Multiplier for delay after each retry
|
backoff_factor: Multiplier for delay after each retry
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
The result of the function if successful
|
The result of the function if successful
|
||||||
|
|
||||||
Raises:
|
Raises:
|
||||||
The last exception encountered if all retries fail
|
The last exception encountered if all retries fail
|
||||||
"""
|
"""
|
||||||
start_time = time.time()
|
start_time = time.time()
|
||||||
delay = initial_delay
|
delay = initial_delay
|
||||||
last_exception = None
|
last_exception = None
|
||||||
|
|
||||||
while time.time() - start_time < max_time:
|
while time.time() - start_time < max_time:
|
||||||
try:
|
try:
|
||||||
return func()
|
return func()
|
||||||
|
@ -40,12 +41,12 @@ class TestHelp(unittest.TestCase):
|
||||||
last_exception = e
|
last_exception = e
|
||||||
time.sleep(delay)
|
time.sleep(delay)
|
||||||
delay = min(delay * backoff_factor, 15) # Cap max delay at 15 seconds
|
delay = min(delay * backoff_factor, 15) # Cap max delay at 15 seconds
|
||||||
|
|
||||||
# If we've exhausted our retry time, raise the last exception
|
# If we've exhausted our retry time, raise the last exception
|
||||||
if last_exception:
|
if last_exception:
|
||||||
raise last_exception
|
raise last_exception
|
||||||
raise Exception("Retry timeout exceeded but no exception was caught")
|
raise Exception("Retry timeout exceeded but no exception was caught")
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def setUpClass(cls):
|
def setUpClass(cls):
|
||||||
io = InputOutput(pretty=False, yes=True)
|
io = InputOutput(pretty=False, yes=True)
|
||||||
|
@ -69,7 +70,7 @@ class TestHelp(unittest.TestCase):
|
||||||
|
|
||||||
# Use retry with backoff for the help command that loads models
|
# Use retry with backoff for the help command that loads models
|
||||||
cls.retry_with_backoff(run_help_command)
|
cls.retry_with_backoff(run_help_command)
|
||||||
|
|
||||||
help_coder_run.assert_called_once()
|
help_coder_run.assert_called_once()
|
||||||
|
|
||||||
def test_init(self):
|
def test_init(self):
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue