Skip to content

Commit 153289e

Browse files
authored
adding integrations tests for Prod (#40)
* adding integrations tests for Prod * lightning-sdk >=0.1.56
1 parent 96fa47f commit 153289e

File tree

4 files changed

+66
-4
lines changed

4 files changed

+66
-4
lines changed

.github/workflows/ci-testing.yml

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ name: CI testing
33
# see: https://help.github.com/en/actions/reference/events-that-trigger-workflows
44
on: # Trigger the workflow on push or pull request, but only for the main branch
55
push: {}
6-
pull_request:
6+
pull_request_target:
77
branches: [main]
88

99
defaults:
@@ -47,9 +47,17 @@ jobs:
4747
pip install -e '.[test,extra]' -U -q --find-links $TORCH_URL
4848
pip list
4949
50-
- name: Tests
50+
- name: Tests with mocks
5151
run: |
52-
coverage run --source litmodels -m pytest src tests -v
52+
coverage run --source litmodels -m pytest src tests -v -m "not cloud"
53+
54+
- name: Test integrations
55+
env:
56+
LIGHTNING_USER_ID: ${{ secrets.LIGHTNING_USER_ID }}
57+
LIGHTNING_API_KEY: ${{ secrets.LIGHTNING_API_KEY }}
58+
run: |
59+
coverage run --source litmodels -m pytest src tests -v -m cloud
60+
timeout-minutes: 5
5361

5462
- name: Statistics
5563
run: |

pyproject.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ addopts = [
3131
"--color=yes",
3232
"--disable-pytest-warnings",
3333
]
34+
markers = [
35+
"cloud:Run the cloud tests for example",
36+
]
3437
filterwarnings = [
3538
"error::FutureWarning",
3639
]

requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# NOTE: once we add more dependencies, consider update dependabot to check for updates
22

3-
lightning-sdk >=0.1.40
3+
lightning-sdk >=0.1.56
44
lightning-utilities
55
joblib

tests/integrations/test_cloud.py

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
import os
2+
from contextlib import redirect_stdout
3+
from io import StringIO
4+
5+
import pytest
6+
from lightning_sdk.lightning_cloud.rest_client import GridRestClient
7+
from lightning_sdk.utils.resolve import _resolve_teamspace
8+
from litmodels import download_model, upload_model
9+
10+
LIT_ORG = "lightning-ai"
11+
LIT_TEAMSPACE = "LitModels"
12+
13+
14+
@pytest.mark.cloud()
15+
def test_upload_download_model(tmp_path):
16+
"""Verify that the model is uploaded to the teamspace"""
17+
# create a dummy file
18+
file_path = tmp_path / "dummy.txt"
19+
with open(file_path, "w") as f:
20+
f.write("dummy")
21+
22+
# model name with random hash
23+
model_name = f"litmodels_test_integrations+{os.urandom(8).hex()}"
24+
teamspace = _resolve_teamspace(org=LIT_ORG, teamspace=LIT_TEAMSPACE, user=None)
25+
org_team = f"{teamspace.owner.name}/{teamspace.name}"
26+
27+
out = StringIO()
28+
with redirect_stdout(out):
29+
upload_model(name=f"{org_team}/{model_name}", model=file_path)
30+
31+
# validate the output
32+
assert (
33+
f"Model uploaded successfully. Link to the model: 'https://lightning.ai/{org_team}/models/{model_name}'"
34+
) in out.getvalue()
35+
36+
os.remove(file_path)
37+
assert not os.path.isfile(file_path)
38+
39+
model_files = download_model(name=f"{org_team}/{model_name}", download_dir=tmp_path)
40+
assert model_files == ["dummy.txt"]
41+
for file in model_files:
42+
assert os.path.isfile(os.path.join(tmp_path, file))
43+
44+
client = GridRestClient()
45+
# cleaning created models with todo: also consider how to delete just this version of the model
46+
model = client.models_store_get_model_by_name(
47+
project_owner_name=teamspace.owner.name,
48+
project_name=teamspace.name,
49+
model_name=model_name,
50+
)
51+
client.models_store_delete_model(project_id=teamspace.id, model_id=model.id)

0 commit comments

Comments
 (0)