Пример #1
0
 def test_should_not_download_if_not_downloaded_but_has_lmdb_cache(
         self, download_manager: MagicMock,
         embedding_manager: EmbeddingManager):
     _create_dummy_lmdb_cache_file(embedding_manager, EMBEDDING_NAME_1)
     assert embedding_manager.ensure_available(
         EXTERNAL_TXT_URL_1) == EMBEDDING_NAME_1
     download_manager.download_if_url.assert_not_called()
     embedding_manager.validate_embedding(EMBEDDING_NAME_1)
Пример #2
0
 def test_should_generate_lmdb_cache(
         self, embedding_manager: EmbeddingManager):
     embedding_manager.add_embedding_config(EMBEDDING_1)
     assert embedding_manager.ensure_available(
         EMBEDDING_NAME_1) == EMBEDDING_NAME_1
     assert not embedding_manager.has_lmdb_cache(EMBEDDING_NAME_1)
     embedding_manager.ensure_lmdb_cache_if_enabled(EMBEDDING_NAME_1)
     assert embedding_manager.has_lmdb_cache(EMBEDDING_NAME_1)
Пример #3
0
        def test_should_download_if_config_exists_but_not_downloaded(
                self, download_manager: MagicMock,
                embedding_manager: EmbeddingManager):
            embedding_manager.download_and_install_embedding(
                EXTERNAL_TXT_URL_1)
            download_manager.reset_mock()

            assert embedding_manager.ensure_available(
                EXTERNAL_TXT_URL_1) == EMBEDDING_NAME_1
            download_manager.download_if_url.assert_called_with(
                EXTERNAL_TXT_URL_1)
Пример #4
0
 def test_should_download_registered_embedding(
         self, download_manager: MagicMock,
         embedding_manager: EmbeddingManager, download_path_1: Path):
     embedding_manager.add_embedding_config({
         'name': EMBEDDING_NAME_1,
         'path': str(download_path_1),
         'url': EXTERNAL_TXT_URL_1
     })
     assert embedding_manager.ensure_available(
         EMBEDDING_NAME_1) == EMBEDDING_NAME_1
     download_manager.download.assert_called_with(
         EXTERNAL_TXT_URL_1, local_file=str(download_path_1))
Пример #5
0
        def test_should_download_and_register_embedding(
                self, download_manager: MagicMock,
                embedding_manager: EmbeddingManager, download_path_1: Path):
            assert embedding_manager.ensure_available(
                EXTERNAL_TXT_URL_1) == EMBEDDING_NAME_1
            download_manager.download_if_url.assert_called_with(
                EXTERNAL_TXT_URL_1)

            embedding_config = embedding_manager.get_embedding_config(
                EMBEDDING_NAME_1)
            assert embedding_config
            assert embedding_config['name'] == EMBEDDING_NAME_1
            assert embedding_config['path'] == str(download_path_1)
Пример #6
0
 def test_should_download_registered_mdb_embedding(
         self, download_manager: MagicMock,
         embedding_manager: EmbeddingManager):
     embedding_manager.add_embedding_config({
         'name': EMBEDDING_NAME_1,
         'url': EXTERNAL_MDB_GZ_URL_1
     })
     assert embedding_manager.ensure_available(
         EMBEDDING_NAME_1) == EMBEDDING_NAME_1
     download_manager.download.assert_called_with(
         EXTERNAL_MDB_GZ_URL_1,
         local_file=str(
             embedding_manager.get_embedding_lmdb_cache_data_path(
                 EMBEDDING_NAME_1)))
Пример #7
0
        def test_should_not_download_if_already_downloaded(
                self, download_manager: MagicMock,
                embedding_manager: EmbeddingManager):
            embedding_manager.download_and_install_embedding(
                EXTERNAL_TXT_URL_1)
            download_manager.reset_mock()
            embedding_config = embedding_manager.get_embedding_config(
                EMBEDDING_NAME_1)
            assert embedding_config
            Path(embedding_config['path']).touch()

            assert embedding_manager.ensure_available(
                EXTERNAL_TXT_URL_1) == EMBEDDING_NAME_1
            download_manager.download_if_url.assert_not_called()