8
8
from langchain .prompts import PromptTemplate
9
9
from tests .unitary .with_extras .langchain .test_guardrails import FakeLLM
10
10
11
+
11
12
class TestLangChainDeploy :
12
-
13
13
def generate_chain_application (self ):
14
14
prompt = PromptTemplate .from_template ("Tell me a joke about {subject}" )
15
15
llm_chain = LLMChain (prompt = prompt , llm = FakeLLM (), verbose = True )
16
16
return llm_chain
17
-
17
+
18
18
@patch ("ads.model.datascience_model.DataScienceModel._to_oci_dsc_model" )
19
19
def test_initialize (self , mock_to_oci_dsc_model ):
20
20
chain_application = self .generate_chain_application ()
@@ -25,39 +25,51 @@ def test_initialize(self, mock_to_oci_dsc_model):
25
25
@patch ("ads.model.runtime.env_info.get_service_packs" )
26
26
@patch ("ads.common.auth.default_signer" )
27
27
@patch ("ads.model.datascience_model.DataScienceModel._to_oci_dsc_model" )
28
- def test_prepare (self , mock_to_oci_dsc_model , mock_default_signer , mock_get_service_packs ):
28
+ def test_prepare (
29
+ self , mock_to_oci_dsc_model , mock_default_signer , mock_get_service_packs
30
+ ):
29
31
mock_default_signer .return_value = MagicMock ()
30
- inference_conda_env = "oci://service-conda-packs@ociodscdev/service_pack/cpu/General_Machine_Learning_for_CPUs/1.0/mlcpuv1"
31
- inference_python_version = "3.7"
32
+ inference_conda_env = "oci://service-conda-packs@ociodscdev/service_pack/cpu/General_Machine_Learning_for_CPUs/1.0/mlcpuv1"
33
+ inference_python_version = "3.7"
32
34
mock_get_service_packs .return_value = (
33
35
{
34
- inference_conda_env : ("mlcpuv1" , inference_python_version ),
36
+ inference_conda_env : ("mlcpuv1" , inference_python_version ),
35
37
},
36
38
{
37
- "mlcpuv1" : (inference_conda_env , inference_python_version ),
38
- }
39
+ "mlcpuv1" : (inference_conda_env , inference_python_version ),
40
+ },
39
41
)
40
42
artifact_dir = tempfile .mkdtemp ()
41
43
chain_application = self .generate_chain_application ()
42
44
chain_deployment = ChainDeployment (
43
- chain_application ,
44
- artifact_dir = artifact_dir ,
45
- auth = MagicMock ()
45
+ chain_application , artifact_dir = artifact_dir , auth = MagicMock ()
46
46
)
47
-
47
+
48
48
mock_to_oci_dsc_model .assert_called ()
49
- mock_default_signer .assert_called ()
50
49
51
50
chain_deployment .prepare (
52
51
inference_conda_env = "oci://service-conda-packs@ociodscdev/service_pack/cpu/General_Machine_Learning_for_CPUs/1.0/mlcpuv1" ,
53
- inference_python_version = "3.7"
52
+ inference_python_version = "3.7" ,
54
53
)
55
54
56
55
mock_get_service_packs .assert_called ()
57
56
58
57
score_py_file_location = os .path .join (chain_deployment .artifact_dir , "score.py" )
59
- chain_yaml_file_location = os .path .join (chain_deployment .artifact_dir , "chain.yaml" )
60
- runtime_yaml_file_location = os .path .join (chain_deployment .artifact_dir , "runtime.yaml" )
61
- assert os .path .isfile (score_py_file_location ) and os .path .getsize (score_py_file_location ) > 0
62
- assert os .path .isfile (chain_yaml_file_location ) and os .path .getsize (chain_yaml_file_location ) > 0
63
- assert os .path .isfile (runtime_yaml_file_location ) and os .path .getsize (runtime_yaml_file_location ) > 0
58
+ chain_yaml_file_location = os .path .join (
59
+ chain_deployment .artifact_dir , "chain.yaml"
60
+ )
61
+ runtime_yaml_file_location = os .path .join (
62
+ chain_deployment .artifact_dir , "runtime.yaml"
63
+ )
64
+ assert (
65
+ os .path .isfile (score_py_file_location )
66
+ and os .path .getsize (score_py_file_location ) > 0
67
+ )
68
+ assert (
69
+ os .path .isfile (chain_yaml_file_location )
70
+ and os .path .getsize (chain_yaml_file_location ) > 0
71
+ )
72
+ assert (
73
+ os .path .isfile (runtime_yaml_file_location )
74
+ and os .path .getsize (runtime_yaml_file_location ) > 0
75
+ )
0 commit comments