Skip to content

Commit

Permalink
add ModelArchiver unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
G committed Oct 30, 2023
1 parent d45b3b1 commit 182621d
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 1 deletion.
2 changes: 1 addition & 1 deletion model-archiver/model_archiver/model_archiver.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"""
Command line interface to export model files to be used for inference by MXNet Model Server
Helper class to generate a model archive file
"""

from model_archiver.model_archiver_config import ModelArchiverConfig
Expand Down
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

0 comments on commit 182621d

Please sign in to comment.