MCPcopy Create free account
hub / github.com/DeepL/deepl-python / test_translate_document_low_level

Function test_translate_document_low_level

tests/test_translate_document.py:228–261  ·  view source on GitHub ↗
(
    translator,
    example_document_path,
    example_document_translation,
    output_document_path,
    server,
)

Source from the content-addressed store, hash-verified

226
227@needs_mock_server
228def test_translate_document_low_level(
229 translator,
230 example_document_path,
231 example_document_translation,
232 output_document_path,
233 server,
234):
235 # Set a small document queue time to attempt downloading a queued document
236 server.set_doc_queue_time(100)
237
238 with open(example_document_path, "rb") as infile:
239 handle = translator.translate_document_upload(
240 infile, **default_lang_args
241 )
242 status = translator.translate_document_get_status(handle)
243 assert status.ok and not status.done
244
245 # Test recreating a document handle from id & key
246 doc_id, doc_key = handle.document_id, handle.document_key
247 del handle
248
249 handle = deepl.DocumentHandle(doc_id, doc_key)
250 status = translator.translate_document_get_status(handle)
251 assert status.ok
252
253 while status.ok and not status.done:
254 status = translator.translate_document_get_status(handle)
255 time.sleep(0.2)
256
257 assert status.ok and status.done
258 with open(output_document_path, "wb") as outfile:
259 translator.translate_document_download(handle, outfile)
260
261 assert output_document_path.read_text() == example_document_translation
262
263
264def test_translate_document_string(translator, server):

Callers

nothing calls this directly

Tested by

no test coverage detected