-
Notifications
You must be signed in to change notification settings - Fork 867
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
G
committed
Oct 30, 2023
1 parent
d45b3b1
commit 182621d
Showing
2 changed files
with
78 additions
and
1 deletion.
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
77 changes: 77 additions & 0 deletions
77
model-archiver/model_archiver/tests/unit_tests/test_model_archiver.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,77 @@ | ||
from collections import namedtuple | ||
|
||
import pytest | ||
from model_archiver import ModelArchiver, ModelArchiverConfig | ||
from model_archiver.manifest_components.manifest import RuntimeType | ||
|
||
|
||
# noinspection PyClassHasNoInit | ||
class TestModelArchiver: | ||
model_name = "my-model" | ||
model_file = "my-model/" | ||
serialized_file = "my-model/" | ||
handler = "a.py::my-awesome-func" | ||
export_path = "/Users/dummyUser/" | ||
version = "1.0" | ||
requirements_file = "requirements.txt" | ||
config_file = None | ||
source_vocab = None | ||
|
||
config = ModelArchiverConfig( | ||
model_name=model_name, | ||
handler=handler, | ||
runtime=RuntimeType.PYTHON.value, | ||
model_file=model_file, | ||
serialized_file=serialized_file, | ||
extra_files=None, | ||
export_path=export_path, | ||
force=False, | ||
archive_format="default", | ||
version=version, | ||
requirements_file=requirements_file, | ||
config_file=None, | ||
) | ||
|
||
@pytest.fixture() | ||
def patches(self, mocker): | ||
Patches = namedtuple("Patches", ["arg_parse", "export_utils", "export_method"]) | ||
patches = Patches( | ||
mocker.patch("model_archiver.arg_parser.ArgParser"), | ||
mocker.patch("model_archiver.model_packaging.ModelExportUtils"), | ||
mocker.patch("model_archiver.model_packaging.package_model"), | ||
) | ||
mocker.patch("shutil.rmtree") | ||
|
||
return patches | ||
|
||
def test_gen_model_archive(self, patches): | ||
ModelArchiver.generate_model_archive(self.config) | ||
patches.export_method.assert_called() | ||
|
||
def test_model_archiver_config_from_args(self, patches): | ||
class Namespace: | ||
def __init__(self, **kwargs): | ||
self.__dict__.update(kwargs) | ||
|
||
def update(self, **kwargs): | ||
self.__dict__.update(kwargs) | ||
|
||
patches.arg_parse.export_model_args_parser.parse_args.return_value = Namespace( | ||
model_name=self.model_name, | ||
handler=self.handler, | ||
runtime=RuntimeType.PYTHON.value, | ||
model_file=self.model_file, | ||
serialized_file=self.serialized_file, | ||
extra_files=None, | ||
export_path=self.export_path, | ||
force=False, | ||
archive_format="default", | ||
convert=False, | ||
version=self.version, | ||
source_vocab=self.source_vocab, | ||
requirements_file=self.requirements_file, | ||
config_file=None, | ||
) | ||
config = ModelArchiverConfig.from_args(None) | ||
|
||
config == self.config |