Skip to content

Commit 446f502

Browse files
Hsaylorapaparazzi0329
authored andcommitted
refactor(lt): minor code cleanup
1 parent 972a1ae commit 446f502

File tree

2 files changed

+65
-21
lines changed

2 files changed

+65
-21
lines changed

ibm_watson/language_translator_v3.py

Lines changed: 61 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
# See the License for the specific language governing permissions and
1515
# limitations under the License.
1616

17-
# IBM OpenAPI SDK Code Generator Version: 3.46.0-a4e29da0-20220224-210428
17+
# IBM OpenAPI SDK Code Generator Version: 3.53.0-9710cac3-20220713-193508
1818
"""
1919
IBM Watson™ Language Translator translates text from one language to another. The
2020
service offers multiple IBM-provided translation models that you can customize based on
@@ -107,6 +107,7 @@ def list_languages(self, **kwargs) -> DetailedResponse:
107107

108108
if 'headers' in kwargs:
109109
headers.update(kwargs.get('headers'))
110+
del kwargs['headers']
110111
headers['Accept'] = 'application/json'
111112

112113
url = '/v3/languages'
@@ -182,6 +183,7 @@ def translate(self,
182183

183184
if 'headers' in kwargs:
184185
headers.update(kwargs.get('headers'))
186+
del kwargs['headers']
185187
headers['Accept'] = 'application/json'
186188

187189
url = '/v3/translate'
@@ -221,6 +223,7 @@ def list_identifiable_languages(self, **kwargs) -> DetailedResponse:
221223

222224
if 'headers' in kwargs:
223225
headers.update(kwargs.get('headers'))
226+
del kwargs['headers']
224227
headers['Accept'] = 'application/json'
225228

226229
url = '/v3/identifiable_languages'
@@ -259,6 +262,7 @@ def identify(self, text: Union[str, TextIO], **kwargs) -> DetailedResponse:
259262

260263
if 'headers' in kwargs:
261264
headers.update(kwargs.get('headers'))
265+
del kwargs['headers']
262266
headers['Accept'] = 'application/json'
263267

264268
url = '/v3/identify'
@@ -315,6 +319,7 @@ def list_models(self,
315319

316320
if 'headers' in kwargs:
317321
headers.update(kwargs.get('headers'))
322+
del kwargs['headers']
318323
headers['Accept'] = 'application/json'
319324

320325
url = '/v3/models'
@@ -330,7 +335,9 @@ def create_model(self,
330335
base_model_id: str,
331336
*,
332337
forced_glossary: BinaryIO = None,
338+
forced_glossary_content_type: str = None,
333339
parallel_corpus: BinaryIO = None,
340+
parallel_corpus_content_type: str = None,
334341
name: str = None,
335342
**kwargs) -> DetailedResponse:
336343
"""
@@ -409,6 +416,8 @@ def create_model(self,
409416
words or short phrases. For more information, see **Supported file
410417
formats** in the method description.
411418
*With `curl`, use `--form forced_glossary=@{filename}`.*.
419+
:param str forced_glossary_content_type: (optional) The content type of
420+
forced_glossary.
412421
:param BinaryIO parallel_corpus: (optional) A file with parallel sentences
413422
for the source and target languages. You can upload multiple parallel
414423
corpus files in one request by repeating the parameter. All uploaded
@@ -420,6 +429,8 @@ def create_model(self,
420429
MB. For more information, see **Supported file formats** in the method
421430
description.
422431
*With `curl`, use `--form parallel_corpus=@{filename}`.*.
432+
:param str parallel_corpus_content_type: (optional) The content type of
433+
parallel_corpus.
423434
:param str name: (optional) An optional model name that you can use to
424435
identify the model. Valid characters are letters, numbers, dashes,
425436
underscores, spaces, and apostrophes. The maximum length of the name is 32
@@ -445,14 +456,19 @@ def create_model(self,
445456

446457
form_data = []
447458
if forced_glossary:
448-
form_data.append(('forced_glossary', (None, forced_glossary,
449-
'application/octet-stream')))
459+
form_data.append(
460+
('forced_glossary',
461+
(None, forced_glossary, forced_glossary_content_type or
462+
'application/octet-stream')))
450463
if parallel_corpus:
451-
form_data.append(('parallel_corpus', (None, parallel_corpus,
452-
'application/octet-stream')))
464+
form_data.append(
465+
('parallel_corpus',
466+
(None, parallel_corpus, parallel_corpus_content_type or
467+
'application/octet-stream')))
453468

454469
if 'headers' in kwargs:
455470
headers.update(kwargs.get('headers'))
471+
del kwargs['headers']
456472
headers['Accept'] = 'application/json'
457473

458474
url = '/v3/models'
@@ -489,6 +505,7 @@ def delete_model(self, model_id: str, **kwargs) -> DetailedResponse:
489505

490506
if 'headers' in kwargs:
491507
headers.update(kwargs.get('headers'))
508+
del kwargs['headers']
492509
headers['Accept'] = 'application/json'
493510

494511
path_param_keys = ['model_id']
@@ -529,6 +546,7 @@ def get_model(self, model_id: str, **kwargs) -> DetailedResponse:
529546

530547
if 'headers' in kwargs:
531548
headers.update(kwargs.get('headers'))
549+
del kwargs['headers']
532550
headers['Accept'] = 'application/json'
533551

534552
path_param_keys = ['model_id']
@@ -568,6 +586,7 @@ def list_documents(self, **kwargs) -> DetailedResponse:
568586

569587
if 'headers' in kwargs:
570588
headers.update(kwargs.get('headers'))
589+
del kwargs['headers']
571590
headers['Accept'] = 'application/json'
572591

573592
url = '/v3/documents'
@@ -596,14 +615,16 @@ def translate_document(self,
596615
`file` parameter, or you can reference a previously submitted document by document
597616
ID. The maximum file size for document translation is
598617
* 20 MB for service instances on the Standard, Advanced, and Premium plans
599-
* 2 MB for service instances on the Lite plan.
618+
* 2 MB for service instances on the Lite plan
619+
**Note:** When translating a previously submitted document, the target language
620+
must be different from the target language of the original request when the
621+
document was initially submitted.
600622
601623
:param BinaryIO file: The contents of the source file to translate. The
602624
maximum file size for document translation is 20 MB for service instances
603625
on the Standard, Advanced, and Premium plans, and 2 MB for service
604626
instances on the Lite plan. For more information, see [Supported file
605-
formats
606-
(Beta)](https://cloud.ibm.com/docs/language-translator?topic=language-translator-document-translator-tutorial#supported-file-formats).
627+
formats](https://cloud.ibm.com/docs/language-translator?topic=language-translator-document-translator-tutorial#supported-file-formats).
607628
:param str filename: (optional) The filename for file.
608629
:param str file_content_type: (optional) The content type of file.
609630
:param str model_id: (optional) The model to use for translation. For
@@ -653,6 +674,7 @@ def translate_document(self,
653674

654675
if 'headers' in kwargs:
655676
headers.update(kwargs.get('headers'))
677+
del kwargs['headers']
656678
headers['Accept'] = 'application/json'
657679

658680
url = '/v3/documents'
@@ -690,6 +712,7 @@ def get_document_status(self, document_id: str,
690712

691713
if 'headers' in kwargs:
692714
headers.update(kwargs.get('headers'))
715+
del kwargs['headers']
693716
headers['Accept'] = 'application/json'
694717

695718
path_param_keys = ['document_id']
@@ -728,6 +751,7 @@ def delete_document(self, document_id: str, **kwargs) -> DetailedResponse:
728751

729752
if 'headers' in kwargs:
730753
headers.update(kwargs.get('headers'))
754+
del kwargs['headers']
731755

732756
path_param_keys = ['document_id']
733757
path_param_values = self.encode_path_vars(document_id)
@@ -784,6 +808,7 @@ def get_translated_document(self,
784808

785809
if 'headers' in kwargs:
786810
headers.update(kwargs.get('headers'))
811+
del kwargs['headers']
787812

788813
path_param_keys = ['document_id']
789814
path_param_values = self.encode_path_vars(document_id)
@@ -799,6 +824,34 @@ def get_translated_document(self,
799824
return response
800825

801826

827+
class CreateModelEnums:
828+
"""
829+
Enums for create_model parameters.
830+
"""
831+
832+
class ForcedGlossaryContentType(str, Enum):
833+
"""
834+
The content type of forced_glossary.
835+
"""
836+
APPLICATION_X_TMX_XML = 'application/x-tmx+xml'
837+
APPLICATION_XLIFF_XML = 'application/xliff+xml'
838+
TEXT_CSV = 'text/csv'
839+
TEXT_TAB_SEPARATED_VALUES = 'text/tab-separated-values'
840+
APPLICATION_JSON = 'application/json'
841+
APPLICATION_VND_OPENXMLFORMATS_OFFICEDOCUMENT_SPREADSHEETML_SHEET = 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'
842+
843+
class ParallelCorpusContentType(str, Enum):
844+
"""
845+
The content type of parallel_corpus.
846+
"""
847+
APPLICATION_X_TMX_XML = 'application/x-tmx+xml'
848+
APPLICATION_XLIFF_XML = 'application/xliff+xml'
849+
TEXT_CSV = 'text/csv'
850+
TEXT_TAB_SEPARATED_VALUES = 'text/tab-separated-values'
851+
APPLICATION_JSON = 'application/json'
852+
APPLICATION_VND_OPENXMLFORMATS_OFFICEDOCUMENT_SPREADSHEETML_SHEET = 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'
853+
854+
802855
class TranslateDocumentEnums:
803856
"""
804857
Enums for translate_document parameters.

test/unit/test_language_translator_v3.py

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,6 @@ def test_list_languages_value_error(self):
131131
with pytest.raises(ValueError):
132132
_service.list_languages(**req_copy)
133133

134-
135134
def test_list_languages_value_error_with_retries(self):
136135
# Enable retries and run test_list_languages_value_error.
137136
_service.enable_retries()
@@ -233,7 +232,6 @@ def test_translate_value_error(self):
233232
with pytest.raises(ValueError):
234233
_service.translate(**req_copy)
235234

236-
237235
def test_translate_value_error_with_retries(self):
238236
# Enable retries and run test_translate_value_error.
239237
_service.enable_retries()
@@ -311,7 +309,6 @@ def test_list_identifiable_languages_value_error(self):
311309
with pytest.raises(ValueError):
312310
_service.list_identifiable_languages(**req_copy)
313311

314-
315312
def test_list_identifiable_languages_value_error_with_retries(self):
316313
# Enable retries and run test_list_identifiable_languages_value_error.
317314
_service.enable_retries()
@@ -390,7 +387,6 @@ def test_identify_value_error(self):
390387
with pytest.raises(ValueError):
391388
_service.identify(**req_copy)
392389

393-
394390
def test_identify_value_error_with_retries(self):
395391
# Enable retries and run test_identify_value_error.
396392
_service.enable_retries()
@@ -514,7 +510,6 @@ def test_list_models_value_error(self):
514510
with pytest.raises(ValueError):
515511
_service.list_models(**req_copy)
516512

517-
518513
def test_list_models_value_error_with_retries(self):
519514
# Enable retries and run test_list_models_value_error.
520515
_service.enable_retries()
@@ -546,14 +541,18 @@ def test_create_model_all_params(self):
546541
# Set up parameter values
547542
base_model_id = 'testString'
548543
forced_glossary = io.BytesIO(b'This is a mock file.').getvalue()
544+
forced_glossary_content_type = 'application/x-tmx+xml'
549545
parallel_corpus = io.BytesIO(b'This is a mock file.').getvalue()
546+
parallel_corpus_content_type = 'application/x-tmx+xml'
550547
name = 'testString'
551548

552549
# Invoke method
553550
response = _service.create_model(
554551
base_model_id,
555552
forced_glossary=forced_glossary,
553+
forced_glossary_content_type=forced_glossary_content_type,
556554
parallel_corpus=parallel_corpus,
555+
parallel_corpus_content_type=parallel_corpus_content_type,
557556
name=name,
558557
headers={}
559558
)
@@ -642,7 +641,6 @@ def test_create_model_value_error(self):
642641
with pytest.raises(ValueError):
643642
_service.create_model(**req_copy)
644643

645-
646644
def test_create_model_value_error_with_retries(self):
647645
# Enable retries and run test_create_model_value_error.
648646
_service.enable_retries()
@@ -719,7 +717,6 @@ def test_delete_model_value_error(self):
719717
with pytest.raises(ValueError):
720718
_service.delete_model(**req_copy)
721719

722-
723720
def test_delete_model_value_error_with_retries(self):
724721
# Enable retries and run test_delete_model_value_error.
725722
_service.enable_retries()
@@ -796,7 +793,6 @@ def test_get_model_value_error(self):
796793
with pytest.raises(ValueError):
797794
_service.get_model(**req_copy)
798795

799-
800796
def test_get_model_value_error_with_retries(self):
801797
# Enable retries and run test_get_model_value_error.
802798
_service.enable_retries()
@@ -874,7 +870,6 @@ def test_list_documents_value_error(self):
874870
with pytest.raises(ValueError):
875871
_service.list_documents(**req_copy)
876872

877-
878873
def test_list_documents_value_error_with_retries(self):
879874
# Enable retries and run test_list_documents_value_error.
880875
_service.enable_retries()
@@ -1002,7 +997,6 @@ def test_translate_document_value_error(self):
1002997
with pytest.raises(ValueError):
1003998
_service.translate_document(**req_copy)
1004999

1005-
10061000
def test_translate_document_value_error_with_retries(self):
10071001
# Enable retries and run test_translate_document_value_error.
10081002
_service.enable_retries()
@@ -1079,7 +1073,6 @@ def test_get_document_status_value_error(self):
10791073
with pytest.raises(ValueError):
10801074
_service.get_document_status(**req_copy)
10811075

1082-
10831076
def test_get_document_status_value_error_with_retries(self):
10841077
# Enable retries and run test_get_document_status_value_error.
10851078
_service.enable_retries()
@@ -1150,7 +1143,6 @@ def test_delete_document_value_error(self):
11501143
with pytest.raises(ValueError):
11511144
_service.delete_document(**req_copy)
11521145

1153-
11541146
def test_delete_document_value_error_with_retries(self):
11551147
# Enable retries and run test_delete_document_value_error.
11561148
_service.enable_retries()
@@ -1265,7 +1257,6 @@ def test_get_translated_document_value_error(self):
12651257
with pytest.raises(ValueError):
12661258
_service.get_translated_document(**req_copy)
12671259

1268-
12691260
def test_get_translated_document_value_error_with_retries(self):
12701261
# Enable retries and run test_get_translated_document_value_error.
12711262
_service.enable_retries()

0 commit comments

Comments
 (0)