Skip to content

Commit e8fc031

Browse files
authored
Refractoring: Fix Coroutine attribute error. (#57)
* __ * Add Uniit tests workflows * Add Uniit tests workflows * Fix Coroutine attribute error in cli download command.
1 parent 8a2dd68 commit e8fc031

File tree

8 files changed

+23
-15
lines changed

8 files changed

+23
-15
lines changed

forklet/__main__.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -117,15 +117,22 @@ async def run_download():
117117
def info(ctx, repository: str, ref: str):
118118
"""Show information about a repository."""
119119

120-
try:
120+
async def get_repo_info():
121+
"""Fetch repository information asynchronously."""
122+
121123
app = ForkletCLI()
122124
app.initialize_services(ctx.obj.get('token'))
123125

124126
owner, repo_name = app.parse_repository_string(repository)
125127

126128
# Get repository info
127-
repo_info = app.github_service.get_repository_info(owner, repo_name)
128-
git_ref = app.github_service.resolve_reference(owner, repo_name, ref)
129+
repo_info = await app.github_service.get_repository_info(owner, repo_name)
130+
git_ref = await app.github_service.resolve_reference(owner, repo_name, ref)
131+
132+
return repo_info, git_ref
133+
134+
try:
135+
repo_info, git_ref = asyncio.run(get_repo_info())
129136

130137
# Display information
131138
click.echo(f"📊 Repository: {repo_info.full_name}")

forklet/infrastructure/logger.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,4 +57,4 @@ def setup_logger(
5757

5858

5959
#### GLOBAL LOGGER INSTANCE
60-
logger = setup_logger("Forklet")
60+
logger = setup_logger("Forklet")

forklet/models/config.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,5 +35,3 @@ class DownloadConfig:
3535
__all__ = [
3636
"DownloadConfig",
3737
]
38-
39-

forklet/models/constants.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@
33
VERSION = "0.1.1"
44

55
#### USER AGENT
6-
USER_AGENT = f"Forklet-GitHub-Downloader/{VERSION}"
6+
USER_AGENT = f"Forklet-GitHub-Downloader/{VERSION}"

forklet/models/download.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -255,5 +255,3 @@ def touch(self) -> None:
255255
"DownloadResult",
256256
"CacheEntry",
257257
]
258-
259-

forklet/models/github.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,5 +88,3 @@ class GitHubFile:
8888
"RepositoryInfo",
8989
"GitHubFile",
9090
]
91-
92-

forklet/models/logging.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,3 @@ class StructuredLogRecord:
2525
__all__ = [
2626
"StructuredLogRecord",
2727
]
28-
29-

tests/infrastructure/test_rate_limiter.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
# Adjust this import path to match your project's structure
1010
from forklet.infrastructure.rate_limiter import RateLimiter, RateLimitInfo
1111

12+
# Mark all tests in this file as asyncio
13+
# pytestmark = pytest.mark.asyncio
1214

1315

1416
## 1. RateLimitInfo Helper Class Tests
@@ -125,7 +127,7 @@ async def test_acquire_uses_adaptive_delay(mock_sleep):
125127
rl = RateLimiter(default_delay=1.0)
126128

127129
# Mock time.time() to simulate time passing
128-
with patch('time.time', side_effect=[1000.0, 1000.1, 1000.2, 1000.3]) as mock_time:
130+
with patch('time.time', side_effect=[1000.0, 1000.1, 1000.2, 1000.3]):
129131
# Ensure rate limit is not exhausted
130132
rl.rate_limit_info.remaining = 2000
131133

@@ -137,6 +139,12 @@ async def test_acquire_uses_adaptive_delay(mock_sleep):
137139
# SECOND call: This call is close to the first one, triggering the delay.
138140
await rl.acquire()
139141

142+
# Check that sleep was called. The exact value has jitter, so we check if it was called.
143+
# mock_sleep.assert_called()
144+
# The first call to time.time() is at the start of acquire(),
145+
# the second is for _last_request. The delay calculation uses the first one.
146+
# Expected delay is around 1.0 seconds.
147+
# assert mock_sleep.call_args[0][0] > 0.5
140148
# Assert that sleep was finally called on the second run
141149
mock_sleep.assert_called()
142150
# 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():
147155
"""Test that acquire() correctly updates the _last_request timestamp."""
148156
rl = RateLimiter()
149157

150-
with patch('time.time', return_value=12345.0) as mock_time:
158+
with patch('time.time', return_value=12345.0):
159+
# Patch sleep to make the test run instantly
151160
with patch('asyncio.sleep'):
152161
await rl.acquire()
153162
assert rl._last_request == 12345.0

0 commit comments

Comments
 (0)