(as_file_object)
| 777 | |
| 778 | @pytest.mark.parametrize("as_file_object", [True, False]) |
| 779 | def 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 |
nothing calls this directly
no test coverage detected