MCPcopy Create free account
hub / github.com/OpenNMT/CTranslate2 / test_load_model_from_memory

Function test_load_model_from_memory

python/tests/test_translator.py:779–805  ·  view source on GitHub ↗
(as_file_object)

Source from the content-addressed store, hash-verified

777
778@pytest.mark.parametrize("as_file_object", [True, False])
779def test_load_model_from_memory(as_file_object):
780 model_path = _get_model_path()
781 files = {}
782
783 for filename in os.listdir(model_path):
784 with open(os.path.join(model_path, filename), "rb") as model_file:
785 content = model_file.read()
786 if as_file_object:
787 content = io.BytesIO(content)
788 files[filename] = content
789
790 translator = ctranslate2.Translator("aren-transliteration", files=files)
791
792 def _translate():
793 output = translator.translate_batch([["آ", "ت", "ز", "م", "و", "ن"]])
794 assert output[0].hypotheses[0] == ["a", "t", "z", "m", "o", "n"]
795
796 if as_file_object:
797 for handle in files.values():
798 handle.close()
799
800 _translate()
801
802 translator.unload_model()
803 translator.load_model()
804
805 _translate()
806
807
808@test_utils.only_on_linux

Callers

nothing calls this directly

Calls 6

_get_model_pathFunction · 0.85
_translateFunction · 0.85
joinMethod · 0.80
closeMethod · 0.80
unload_modelMethod · 0.80
load_modelMethod · 0.45

Tested by

no test coverage detected