Skip to content

Commit

Permalink
TST: Added testcase for user metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
ganesh-k13 committed Jan 13, 2023
1 parent fde94d4 commit 3dd7690
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions vetiver/tests/test_build_vetiver_model.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import sklearn
import sys

import vetiver as vt
from vetiver.meta import VetiverMeta
Expand Down Expand Up @@ -113,6 +114,7 @@ def test_vetiver_model_use_ptype():
version=None,
url=None,
required_pkgs=["scikit-learn"],
python_version=sys.version,
)


Expand All @@ -137,5 +139,41 @@ def test_vetiver_model_from_pin():
assert v2.metadata.user == {"test": 123}
assert v2.metadata.version is not None
assert v2.metadata.required_pkgs == ["scikit-learn"]
assert v2.metadata.python_version == sys.version

board.pin_delete("model")


def test_vetiver_model_from_pin_user_metadata():
"""
Test if standard keys as part of :dataclass:`VetiverMeta` are picked
"""
custom_meta = {
"test": 123,
"required_pkgs": ["foo", "bar"],
"python_version": "baz",
}
loaded_pkgs = custom_meta["required_pkgs"] + ["scikit-learn"]

v = vt.VetiverModel(
model=model,
prototype_data=X_df,
model_name="model",
versioned=None,
description=None,
metadata=custom_meta,
)

board = pins.board_temp(allow_pickle_read=True)
vt.vetiver_pin_write(board=board, model=v)
v2 = vt.VetiverModel.from_pin(board, "model")

assert isinstance(v2, vt.VetiverModel)
assert isinstance(v2.model, sklearn.base.BaseEstimator)
assert isinstance(v2.prototype.construct(), pydantic.BaseModel)
assert v2.metadata.user == custom_meta
assert v2.metadata.version is not None
assert v2.metadata.required_pkgs == loaded_pkgs
assert v2.metadata.python_version == custom_meta["python_version"]

board.pin_delete("model")

0 comments on commit 3dd7690

Please sign in to comment.