Skip to content

Commit 7039367

Browse files
committed
chore: upd
1 parent a18e06b commit 7039367

File tree

3 files changed

+54
-37
lines changed

3 files changed

+54
-37
lines changed

src/lingodotdev/engine.py

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,9 @@ async def _localize_raw(
134134
)
135135

136136
if progress_callback:
137-
progress_callback(percentage_completed, chunk, processed_payload_chunk)
137+
progress_callback(
138+
percentage_completed, chunk, processed_payload_chunk
139+
)
138140

139141
processed_payload_chunks.append(processed_payload_chunk)
140142

@@ -280,7 +282,9 @@ async def localize_object(
280282
A new object with the same structure but localized string values
281283
"""
282284
localization_params = LocalizationParams(**params)
283-
return await self._localize_raw(obj, localization_params, progress_callback, concurrent)
285+
return await self._localize_raw(
286+
obj, localization_params, progress_callback, concurrent
287+
)
284288

285289
async def localize_text(
286290
self,
@@ -425,7 +429,9 @@ async def recognize_locale(self, text: str) -> str:
425429
f"Server error ({response.status_code}): {response.reason_phrase}. "
426430
"This may be due to temporary service issues."
427431
)
428-
raise RuntimeError(f"Error recognizing locale: {response.reason_phrase}")
432+
raise RuntimeError(
433+
f"Error recognizing locale: {response.reason_phrase}"
434+
)
429435

430436
json_response = response.json()
431437
return json_response.get("locale") or ""
@@ -466,9 +472,7 @@ async def whoami(self) -> Optional[Dict[str, str]]:
466472
return None
467473

468474
async def batch_localize_objects(
469-
self,
470-
objects: List[Dict[str, Any]],
471-
params: Dict[str, Any]
475+
self, objects: List[Dict[str, Any]], params: Dict[str, Any]
472476
) -> List[Dict[str, Any]]:
473477
"""
474478
Localize multiple objects concurrently
@@ -515,15 +519,15 @@ async def quick_translate(
515519
Example:
516520
# Translate text
517521
result = await LingoDotDevEngine.quick_translate(
518-
"Hello world",
519-
"your-api-key",
522+
"Hello world",
523+
"your-api-key",
520524
"es"
521525
)
522-
526+
523527
# Translate object
524528
result = await LingoDotDevEngine.quick_translate(
525529
{"greeting": "Hello", "farewell": "Goodbye"},
526-
"your-api-key",
530+
"your-api-key",
527531
"es"
528532
)
529533
"""
@@ -573,8 +577,8 @@ async def quick_batch_translate(
573577
574578
Example:
575579
results = await LingoDotDevEngine.quick_batch_translate(
576-
"Hello world",
577-
"your-api-key",
580+
"Hello world",
581+
"your-api-key",
578582
["es", "fr", "de"]
579583
)
580584
# Results: ["Hola mundo", "Bonjour le monde", "Hallo Welt"]

tests/test_engine.py

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -345,10 +345,9 @@ async def test_whoami_no_email(self, mock_post):
345345
@patch("lingodotdev.engine.LingoDotDevEngine.localize_object")
346346
async def test_batch_localize_objects(self, mock_localize_object):
347347
"""Test batch object localization"""
348-
mock_localize_object.side_effect = AsyncMock(side_effect=[
349-
{"greeting": "hola"},
350-
{"farewell": "adiós"}
351-
])
348+
mock_localize_object.side_effect = AsyncMock(
349+
side_effect=[{"greeting": "hola"}, {"farewell": "adiós"}]
350+
)
352351

353352
objects = [{"greeting": "hello"}, {"farewell": "goodbye"}]
354353
params = {"source_locale": "en", "target_locale": "es"}
@@ -360,21 +359,29 @@ async def test_batch_localize_objects(self, mock_localize_object):
360359

361360
async def test_concurrent_processing(self):
362361
"""Test concurrent processing functionality"""
363-
with patch("lingodotdev.engine.LingoDotDevEngine._localize_chunk") as mock_chunk:
362+
with patch(
363+
"lingodotdev.engine.LingoDotDevEngine._localize_chunk"
364+
) as mock_chunk:
364365
mock_chunk.return_value = {"key": "value"}
365366

366367
large_payload = {f"key{i}": f"value{i}" for i in range(5)}
367-
368+
368369
# Test concurrent mode
369370
await self.engine._localize_raw(
370371
large_payload,
371-
await asyncio.to_thread(lambda: type('MockParams', (), {
372-
'source_locale': 'en',
373-
'target_locale': 'es',
374-
'fast': False,
375-
'reference': None
376-
})()),
377-
concurrent=True
372+
await asyncio.to_thread(
373+
lambda: type(
374+
"MockParams",
375+
(),
376+
{
377+
"source_locale": "en",
378+
"target_locale": "es",
379+
"fast": False,
380+
"reference": None,
381+
},
382+
)()
383+
),
384+
concurrent=True,
378385
)
379386

380387
# Should have called _localize_chunk multiple times concurrently

tests/test_integration.py

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,11 @@ async def test_batch_localize_text_real_api(self):
7474
async with self.engine:
7575
result = await self.engine.batch_localize_text(
7676
"Welcome to our application",
77-
{"source_locale": "en", "target_locales": ["es", "fr", "de"], "fast": True},
77+
{
78+
"source_locale": "en",
79+
"target_locales": ["es", "fr", "de"],
80+
"fast": True,
81+
},
7882
)
7983

8084
assert isinstance(result, list)
@@ -208,16 +212,19 @@ async def test_fast_mode(self):
208212
async def test_concurrent_processing_performance(self):
209213
"""Test concurrent processing performance improvement"""
210214
import time
211-
212-
large_object = {f"key_{i}": f"Test content number {i} for performance testing" for i in range(10)}
215+
216+
large_object = {
217+
f"key_{i}": f"Test content number {i} for performance testing"
218+
for i in range(10)
219+
}
213220

214221
async with self.engine:
215222
# Test sequential processing
216223
start_time = time.time()
217224
await self.engine.localize_object(
218225
large_object,
219226
{"source_locale": "en", "target_locale": "es"},
220-
concurrent=False
227+
concurrent=False,
221228
)
222229
sequential_time = time.time() - start_time
223230

@@ -226,7 +233,7 @@ async def test_concurrent_processing_performance(self):
226233
await self.engine.localize_object(
227234
large_object,
228235
{"source_locale": "en", "target_locale": "es"},
229-
concurrent=True
236+
concurrent=True,
230237
)
231238
concurrent_time = time.time() - start_time
232239

@@ -238,13 +245,12 @@ async def test_batch_localize_objects(self):
238245
objects = [
239246
{"greeting": "Hello", "question": "How are you?"},
240247
{"farewell": "Goodbye", "thanks": "Thank you"},
241-
{"welcome": "Welcome", "help": "Can I help you?"}
248+
{"welcome": "Welcome", "help": "Can I help you?"},
242249
]
243250

244251
async with self.engine:
245252
results = await self.engine.batch_localize_objects(
246-
objects,
247-
{"source_locale": "en", "target_locale": "es"}
253+
objects, {"source_locale": "en", "target_locale": "es"}
248254
)
249255

250256
assert len(results) == 3
@@ -337,15 +343,15 @@ async def test_workflow_id_consistency(self, mock_post):
337343
async def test_concurrent_chunk_processing(self, mock_post):
338344
"""Test concurrent chunk processing"""
339345
import asyncio
340-
346+
341347
# Mock API response with delay to test concurrency
342348
async def mock_response_with_delay(*args, **kwargs):
343349
await asyncio.sleep(0.1) # Small delay
344-
mock_resp = type('MockResponse', (), {})()
350+
mock_resp = type("MockResponse", (), {})()
345351
mock_resp.is_success = True
346352
mock_resp.json = lambda: {"data": {"key": "value"}}
347353
return mock_resp
348-
354+
349355
mock_post.side_effect = mock_response_with_delay
350356

351357
# Create a payload that will be chunked
@@ -356,7 +362,7 @@ async def mock_response_with_delay(*args, **kwargs):
356362
await self.engine.localize_object(
357363
large_payload,
358364
{"source_locale": "en", "target_locale": "es"},
359-
concurrent=True
365+
concurrent=True,
360366
)
361367
concurrent_time = asyncio.get_event_loop().time() - start_time
362368

0 commit comments

Comments
 (0)