예제 #1
0
 def test_get_translation_from_model(self):
     model_id = (translation_models.MachineTranslationModel.create(
         'en', 'es', 'hello world', 'hola mundo'))
     model_instance = translation_models.MachineTranslationModel.get(
         model_id)
     self.assertEqual(
         translation_fetchers.get_translation_from_model(
             model_instance).to_dict(),
         translation_domain.MachineTranslation('en', 'es', 'hello world',
                                               'hola mundo').to_dict())
예제 #2
0
def get_translation_from_model(translation_model):
    """Returns a MachineTranslation object given a
    MachineTranslationModel loaded from the datastore.

    Args:
        translation_model: MachineTranslationModel. The
            MachineTranslationModel loaded from the datastore.

    Returns:
        MachineTranslation. A MachineTranslation object corresponding to
        the given MachineTranslationModel.
    """
    return translation_domain.MachineTranslation(
        translation_model.source_language_code,
        translation_model.target_language_code, translation_model.source_text,
        translation_model.translated_text)
예제 #3
0
 def test_get_translation_from_model(self) -> None:
     model_id = (
         translation_models.MachineTranslationModel.create(
             'en', 'es', 'hello world', 'hola mundo')
     )
     # Ruling out the possibility of None for mypy type checking.
     assert model_id is not None
     model_instance = translation_models.MachineTranslationModel.get(
         model_id)
     # Ruling out the possibility of None for mypy type checking.
     assert model_instance is not None
     self.assertEqual(
         translation_fetchers.get_translation_from_model(
             model_instance).to_dict(),
         translation_domain.MachineTranslation(
             'en', 'es', 'hello world', 'hola mundo').to_dict()
     )
예제 #4
0
 def _init_translation(self) -> None:
     """Initialize self.translation with valid default values."""
     self.translation = translation_domain.MachineTranslation(
         'en', 'es', 'hello world', 'hola mundo')
     self.translation.validate()