forked from pycaret/pycaret
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_persistence.py
47 lines (35 loc) · 1.18 KB
/
test_persistence.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import os
import boto3
import pytest
from moto import mock_s3
from pycaret.internal.persistence import deploy_model, load_model
@pytest.fixture(scope="function")
def aws_credentials():
"""Mocked AWS Credentials for moto."""
os.environ["AWS_ACCESS_KEY_ID"] = "testing"
os.environ["AWS_SECRET_ACCESS_KEY"] = "testing"
os.environ["AWS_SECURITY_TOKEN"] = "testing"
os.environ["AWS_SESSION_TOKEN"] = "testing"
@pytest.fixture(scope="function")
def s3(aws_credentials):
"""Create a mock s3 for testing."""
with mock_s3():
yield boto3.client("s3", region_name="us-east-1")
def test_deploy_model(s3):
authentication = {"bucket": "pycaret-test", "path": "test"}
s3.create_bucket(Bucket=authentication.get("bucket"))
model = "test_model"
model_name = "test"
deploy_model(
model, model_name=model_name, platform="aws", authentication=authentication
)
s3.head_object(
Bucket=authentication.get("bucket"),
Key=os.path.join(authentication.get("path"), f"{model_name}.pkl"),
)
_ = load_model(
model_name=model_name,
platform="aws",
authentication=authentication,
verbose=True,
)