-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
92536d0
commit f302414
Showing
4 changed files
with
107 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
65 changes: 65 additions & 0 deletions
65
tests/integration_tests/without_db/utils/test_huggingface_hub_bucketfs_model_transfer_sp.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import pytest | ||
import tempfile | ||
from pathlib import Path | ||
from typing import Union | ||
from unittest.mock import create_autospec, MagicMock | ||
|
||
from transformers import AutoModel | ||
|
||
from exasol_transformers_extension.utils.bucketfs_model_uploader import BucketFSModelUploader, \ | ||
BucketFSModelUploaderFactory | ||
from exasol_transformers_extension.utils.huggingface_hub_bucketfs_model_transfer_sp import ModelFactoryProtocol, \ | ||
HuggingFaceHubBucketFSModelTransferSP | ||
from exasol_transformers_extension.utils.temporary_directory_factory import TemporaryDirectoryFactory | ||
from tests.utils.mock_cast import mock_cast | ||
|
||
from tests.utils.parameters import model_params | ||
|
||
|
||
class TestSetup: | ||
def __init__(self, bucketfs_location): | ||
self.bucketfs_location = bucketfs_location | ||
self.model_factory_mock: Union[ModelFactoryProtocol, MagicMock] = create_autospec(ModelFactoryProtocol) | ||
self.temporary_directory_factory = TemporaryDirectoryFactory() | ||
self.bucketfs_model_uploader_factory_mock: Union[BucketFSModelUploaderFactory, MagicMock] = \ | ||
create_autospec(BucketFSModelUploaderFactory) | ||
self.bucketfs_model_uploader_mock: Union[BucketFSModelUploader, MagicMock] = \ | ||
create_autospec(BucketFSModelUploader) | ||
mock_cast(self.bucketfs_model_uploader_factory_mock.create).side_effect = [self.bucketfs_model_uploader_mock] | ||
|
||
self.token = "token" | ||
model_params_ = model_params.tiny_model | ||
print(model_params_) | ||
self.model_name = model_params_ | ||
self.model_path = Path("test_model_path") | ||
self.downloader = HuggingFaceHubBucketFSModelTransferSP( | ||
bucketfs_location=self.bucketfs_location, | ||
model_path=self.model_path, | ||
model_name=self.model_name, | ||
token=self.token, | ||
temporary_directory_factory=self.temporary_directory_factory, | ||
bucketfs_model_uploader_factory=self.bucketfs_model_uploader_factory_mock | ||
) | ||
|
||
def reset_mocks(self): | ||
self.model_factory_mock.reset_mock() | ||
self.bucketfs_model_uploader_mock.reset_mock() | ||
|
||
|
||
def test_download_with_model(bucketfs_location): | ||
with tempfile.TemporaryDirectory() as folder: | ||
test_setup = TestSetup(bucketfs_location) | ||
base_model_factory: ModelFactoryProtocol = AutoModel | ||
test_setup.downloader.download_from_huggingface_hub(model_factory=base_model_factory) | ||
assert AutoModel.from_pretrained(test_setup.downloader._tmpdir_name/"pretrained"/test_setup.model_name) | ||
test_setup.downloader.__del__() | ||
|
||
|
||
def test_download_with_duplicate_model(bucketfs_location): | ||
with tempfile.TemporaryDirectory() as folder: | ||
test_setup = TestSetup(bucketfs_location) | ||
base_model_factory: ModelFactoryProtocol = AutoModel | ||
test_setup.downloader.download_from_huggingface_hub(model_factory=base_model_factory) | ||
test_setup.downloader.download_from_huggingface_hub(model_factory=base_model_factory) | ||
assert AutoModel.from_pretrained(test_setup.downloader._tmpdir_name/"pretrained"/test_setup.model_name) | ||
test_setup.downloader.__del__() |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters