diff --git a/forklet/__main__.py b/forklet/__main__.py index 04c7d57..bc86f73 100644 --- a/forklet/__main__.py +++ b/forklet/__main__.py @@ -117,15 +117,22 @@ async def run_download(): def info(ctx, repository: str, ref: str): """Show information about a repository.""" - try: + async def get_repo_info(): + """Fetch repository information asynchronously.""" + app = ForkletCLI() app.initialize_services(ctx.obj.get('token')) owner, repo_name = app.parse_repository_string(repository) # Get repository info - repo_info = app.github_service.get_repository_info(owner, repo_name) - git_ref = app.github_service.resolve_reference(owner, repo_name, ref) + repo_info = await app.github_service.get_repository_info(owner, repo_name) + git_ref = await app.github_service.resolve_reference(owner, repo_name, ref) + + return repo_info, git_ref + + try: + repo_info, git_ref = asyncio.run(get_repo_info()) # Display information click.echo(f"📊 Repository: {repo_info.full_name}") diff --git a/forklet/infrastructure/logger.py b/forklet/infrastructure/logger.py index 0d2efba..a1a35f6 100644 --- a/forklet/infrastructure/logger.py +++ b/forklet/infrastructure/logger.py @@ -57,4 +57,4 @@ def setup_logger( #### GLOBAL LOGGER INSTANCE -logger = setup_logger("Forklet") \ No newline at end of file +logger = setup_logger("Forklet") diff --git a/forklet/models/config.py b/forklet/models/config.py index 7abe5c6..42836d2 100644 --- a/forklet/models/config.py +++ b/forklet/models/config.py @@ -35,5 +35,3 @@ class DownloadConfig: __all__ = [ "DownloadConfig", ] - - diff --git a/forklet/models/constants.py b/forklet/models/constants.py index 02984a1..81cb1a5 100644 --- a/forklet/models/constants.py +++ b/forklet/models/constants.py @@ -3,4 +3,4 @@ VERSION = "0.1.1" #### USER AGENT -USER_AGENT = f"Forklet-GitHub-Downloader/{VERSION}" \ No newline at end of file +USER_AGENT = f"Forklet-GitHub-Downloader/{VERSION}" diff --git a/forklet/models/download.py b/forklet/models/download.py index 5216153..e628d7f 100644 --- a/forklet/models/download.py +++ b/forklet/models/download.py @@ -255,5 +255,3 @@ def touch(self) -> None: "DownloadResult", "CacheEntry", ] - - diff --git a/forklet/models/github.py b/forklet/models/github.py index 0440cd4..5923af4 100644 --- a/forklet/models/github.py +++ b/forklet/models/github.py @@ -88,5 +88,3 @@ class GitHubFile: "RepositoryInfo", "GitHubFile", ] - - diff --git a/forklet/models/logging.py b/forklet/models/logging.py index 2464b89..4108e7b 100644 --- a/forklet/models/logging.py +++ b/forklet/models/logging.py @@ -25,5 +25,3 @@ class StructuredLogRecord: __all__ = [ "StructuredLogRecord", ] - - diff --git a/tests/infrastructure/test_rate_limiter.py b/tests/infrastructure/test_rate_limiter.py index 723f95a..16edd40 100644 --- a/tests/infrastructure/test_rate_limiter.py +++ b/tests/infrastructure/test_rate_limiter.py @@ -9,6 +9,8 @@ # Adjust this import path to match your project's structure from forklet.infrastructure.rate_limiter import RateLimiter, RateLimitInfo +# Mark all tests in this file as asyncio +# pytestmark = pytest.mark.asyncio ## 1. RateLimitInfo Helper Class Tests @@ -125,7 +127,7 @@ async def test_acquire_uses_adaptive_delay(mock_sleep): rl = RateLimiter(default_delay=1.0) # Mock time.time() to simulate time passing - with patch('time.time', side_effect=[1000.0, 1000.1, 1000.2, 1000.3]) as mock_time: + with patch('time.time', side_effect=[1000.0, 1000.1, 1000.2, 1000.3]): # Ensure rate limit is not exhausted rl.rate_limit_info.remaining = 2000 @@ -137,6 +139,12 @@ async def test_acquire_uses_adaptive_delay(mock_sleep): # SECOND call: This call is close to the first one, triggering the delay. await rl.acquire() + # Check that sleep was called. The exact value has jitter, so we check if it was called. + # mock_sleep.assert_called() + # The first call to time.time() is at the start of acquire(), + # the second is for _last_request. The delay calculation uses the first one. + # Expected delay is around 1.0 seconds. + # assert mock_sleep.call_args[0][0] > 0.5 # Assert that sleep was finally called on the second run mock_sleep.assert_called() # The delay should be > 0 because elapsed time (0.1s) < default_delay (1.0s) @@ -147,7 +155,8 @@ async def test_acquire_updates_last_request_time(): """Test that acquire() correctly updates the _last_request timestamp.""" rl = RateLimiter() - with patch('time.time', return_value=12345.0) as mock_time: + with patch('time.time', return_value=12345.0): + # Patch sleep to make the test run instantly with patch('asyncio.sleep'): await rl.acquire() assert rl._last_request == 12345.0