def test_page_without_source(self, cache): translation = { "translatedText": "Привет, мир [cached]", "detectedSourceLanguage": "en", "input": "Hello world" } cache.save_to_cache([translation], "", "ru") with grpc.insecure_channel('localhost:50051') as channel: stub = cached_translation_pb2_grpc.CachedTranslationStub(channel) response = stub.GetTranslations( cached_translation_pb2.TranslationRequest( texts=["Hello world", "Hello world guys"], targetLanguage="ru", sourceLanguage="")) print("translatedText: " + response.translations[0].translatedText) print("detectedSourceLanguage: " + response.translations[0].detectedSourceLanguage) print("input: " + response.translations[0].input) assert response.translations[ 0].translatedText == "Привет, мир [cached]" assert response.translations[0].detectedSourceLanguage == "en" assert response.translations[0].input == "Hello world" assert response.translations[1].translatedText == "Привет, мир, ребята" assert response.translations[1].detectedSourceLanguage == "en" assert response.translations[1].input == "Hello world guys"
def test_empty_translation_request(self, cache): with grpc.insecure_channel('localhost:50051') as channel: stub = cached_translation_pb2_grpc.CachedTranslationStub(channel) response = stub.GetTranslations( cached_translation_pb2.TranslationRequest(texts=[], targetLanguage="ru", sourceLanguage="")) print("translatedText: " + str(response.translations[0].translatedText)) print("detectedSourceLanguage: " + str(response.translations[0].detectedSourceLanguage)) print("input: " + response.translations[0].input) assert response.translations[0].translatedText == "" assert response.translations[0].detectedSourceLanguage == "" assert response.translations[0].input == "BAD ARGUMENT"
def test_from_cloud_with_source(self, cache): with grpc.insecure_channel('localhost:50051') as channel: stub = cached_translation_pb2_grpc.CachedTranslationStub(channel) response = stub.GetTranslations( cached_translation_pb2.TranslationRequest( texts=["Hello world"], targetLanguage="ru", sourceLanguage="en")) print("translatedText: " + response.translations[0].translatedText) print("detectedSourceLanguage: " + response.translations[0].detectedSourceLanguage) print("input: " + response.translations[0].input) assert response.translations[0].translatedText == "Привет, мир" assert response.translations[0].detectedSourceLanguage == "" assert response.translations[0].input == "Hello world"
def run(): with grpc.insecure_channel('localhost:50051') as channel: stub = cached_translation_pb2_grpc.CachedTranslationStub(channel) texts = args.strings source_language = args.source target_language = args.to response = stub.GetTranslations(cached_translation_pb2.TranslationRequest( texts=texts, targetLanguage=target_language, sourceLanguage=source_language)) for translation in response.translations: print(translation.translatedText) print(translation.detectedSourceLanguage) print(translation.input)