-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[doc translator] adding tests (#17511)
* [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
Showing
41 changed files
with
18,413 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 64 additions & 0 deletions
64
sdk/documenttranslation/azure-ai-documenttranslation/tests/asynctestcase.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
14 changes: 14 additions & 0 deletions
14
sdk/documenttranslation/azure-ai-documenttranslation/tests/conftest.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.