Skip to content

Commit

Permalink
[doc translator] adding tests (#17511)
Browse files Browse the repository at this point in the history
* [tests][sync] test supported formats

* [tests][sync] test translation

* [tests] comeplete the supported formats test

* [tests] translation test

* [tests] translation -> single source multiple target

* [test] translation -> multiple sources single targets

* [test] translation -> prefix and suffix

* [test] translation -> list all doc statuses

* [test] updated tests to create their own containers

* [tests] update base test functions to support offline tests

* [test] adding more tests

* [tests] status tests

* [tests] list statuses

* [tests] list submitted jobs

* [tests] doc status

* [tests] update paging in list all statuses

* [tests] some refactoring

* [tests] added meaningful assertions + method refactoring

* [test] cancel job

* [tests] refactor helper functions

* [tests] added async tests

* [tests] skip some tests (functionality is hidden for now)

* [tests][pr reviews] correct silly mistake -> calling function with argument self!

* [test] lazy fix -> sample trsnaltion jobs -> wait until done for status to be succeeded

* [test] some bugs

* [tests] fix gettting first item if async iterator

* [tests] fix cancelled job status propagation

* [tests] fix iterator len issue in sync client

* [tests] fix 'self' keyword used unnecessarily

* [test] fix get length of async iterator

* [tests] update tests after actually running them

* [tests] sync client updates

* [tests] add sync client test recordings

* [tests] fixed async client tests

* [tests] adding async recordings

* [tests] adding conftest.py for py2 async tests

* [tests] update recordings

* [tests] pr reviews

* [tests] created AsyncDocumentTranslationTest for python 3

* [tests] setting polling interval to zero when running recorded tests

* [tests] updated polling interval for wait_until_done method in client

* [tests] updating recorded tests

* [tests] updated records -> downgrade azure core bug

* [tests] fixing linting errors
  • Loading branch information
Mohamed Shaban authored Mar 31, 2021
1 parent 93f9f0b commit b285461
Show file tree
Hide file tree
Showing 41 changed files with 18,413 additions and 55 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ def callback(raw_response):
initial_response=pipeline_response,
deserialization_callback=callback,
polling_method=LROBasePolling(
timeout=30,
timeout=self._client._config.polling_interval, # pylint: disable=protected-access
lro_algorithms=[TranslationPolling()],
**kwargs
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ def callback(raw_response):
initial_response=pipeline_response,
deserialization_callback=callback,
polling_method=AsyncLROBasePolling(
timeout=30,
timeout=self._client._config.polling_interval, # pylint: disable=protected-access
lro_algorithms=[TranslationPolling()],
**kwargs
),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
# coding=utf-8
# ------------------------------------
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.
# ------------------------------------
from testcase import DocumentTranslationTest
from azure.ai.documenttranslation import DocumentTranslationInput, TranslationTarget

class AsyncDocumentTranslationTest(DocumentTranslationTest):

def __init__(self, method_name):
super(AsyncDocumentTranslationTest, self).__init__(method_name)

async def _submit_and_validate_translation_job_async(self, async_client, translation_inputs, total_docs_count):
# submit job
job_details = await async_client.create_translation_job(translation_inputs)
self.assertIsNotNone(job_details.id)
# wait for result
job_details = await async_client.wait_until_done(job_details.id)
# validate
self._validate_translation_job(job_details=job_details, status='Succeeded', total=total_docs_count, succeeded=total_docs_count)

return job_details.id

# client helpers
async def _create_and_submit_sample_translation_jobs_async(self, async_client, jobs_count):
result_job_ids = []
for i in range(jobs_count):
# prepare containers and test data
'''
# WARNING!!
TOTAL_DOC_COUNT_IN_JOB = 1
if you plan to create more docs in the job,
please update this variable TOTAL_DOC_COUNT_IN_JOB in respective test
# note
since we're only testing the client library
we can use sync container calls in here
no need for async container clients!
'''
blob_data = b'This is some text'
source_container_sas_url = self.create_source_container(data=blob_data)
target_container_sas_url = self.create_target_container()

# prepare translation inputs
translation_inputs = [
DocumentTranslationInput(
source_url=source_container_sas_url,
targets=[
TranslationTarget(
target_url=target_container_sas_url,
language_code="es"
)
]
)
]

# submit multiple jobs
job_details = await async_client.create_translation_job(translation_inputs)
self.assertIsNotNone(job_details.id)
await async_client.wait_until_done(job_details.id)
result_job_ids.append(job_details.id)

return result_job_ids
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@

# coding: utf-8
# -------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for
# license information.
# --------------------------------------------------------------------------

import sys

# Ignore async tests for Python < 3.5
collect_ignore_glob = []
if sys.version_info < (3, 5):
collect_ignore_glob.append("*_async.py")
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ def create_resource(self, name, **kwargs):
doctranslation_test_endpoint = kwargs.get("documenttranslation_test_endpoint")
doctranslation_test_api_key = kwargs.get("documenttranslation_test_api_key")

# set polling interval to 0 for recorded tests
if not self.is_live:
self.client_kwargs["polling_interval"] = 0

client = self.client_cls(
doctranslation_test_endpoint,
Expand Down
Loading

0 comments on commit b285461

Please sign in to comment.