Skip to content

Commit

Permalink
fix unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
goldenxinxing committed Sep 16, 2022
1 parent 74a0939 commit 5e32fd1
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 10 deletions.
3 changes: 2 additions & 1 deletion client/starwhale/api/_impl/data_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -901,7 +901,7 @@ def dump(self) -> None:


class RemoteDataStore:
def __init__(self, instance_uri: str, token: str) -> None:
def __init__(self, instance_uri: str, token: str = "") -> None:
self.instance_uri = instance_uri
self.token = token or os.getenv(SWEnv.instance_token)
if self.token is None:
Expand Down Expand Up @@ -1039,6 +1039,7 @@ def get_data_store(instance_uri: str = "") -> DataStore:
if _instance_uri is None or _instance_uri == "local":
return LocalDataStore.get_instance()
else:
print(f"instance:{instance_uri}")
return RemoteDataStore(
instance_uri=_instance_uri,
token=SWCliConfigMixed().get_sw_token(instance=instance_uri),
Expand Down
26 changes: 17 additions & 9 deletions client/tests/core/test_eval.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import os
import unittest
from pathlib import Path
from unittest.mock import patch, MagicMock

Expand All @@ -10,16 +9,19 @@
from starwhale.consts import HTTPMethod, RECOVER_DIRNAME, DEFAULT_MANIFEST_NAME
from starwhale.base.uri import URI
from starwhale.base.type import URIType
from starwhale.utils.config import load_swcli_config
from starwhale.utils.config import load_swcli_config, get_swcli_config_path
from starwhale.core.eval.view import JobTermView, JobTermViewRich
from starwhale.core.eval.model import CloudEvaluationJob, StandaloneEvaluationJob
from starwhale.core.eval.store import EvaluationStorage

from .. import ROOT_DIR
from .. import ROOT_DIR, get_predefined_config_yaml

_job_data_dir = f"{ROOT_DIR}/data/job"
_job_manifest = open(f"{_job_data_dir}/job_manifest.yaml").read()
_cmp_report = open(f"{_job_data_dir}/cmp_report.jsonl").read()
_job_list = open(f"{_job_data_dir}/job_list_resp.json").read()
_task_list = open(f"{_job_data_dir}/task_list.json").read()
_existed_config_contents = get_predefined_config_yaml()


class StandaloneEvaluationJobTestCase(TestCase):
Expand Down Expand Up @@ -137,9 +139,14 @@ def test_stanalone_actions(self, m_call: MagicMock, m_call_output: MagicMock):
assert m_call.call_count == 3


class CloudJobTestCase(unittest.TestCase):
class CloudJobTestCase(TestCase):
def setUp(self):
self.instance_uri = "http://1.1.1.1:8888"
self.setUpPyfakefs()
sw_config._config = {}
path = get_swcli_config_path()
self.fs.create_file(path, contents=_existed_config_contents)

self.instance_uri = "http://1.1.1.1:8182"
self.project_uri = f"{self.instance_uri}/project/self"
self.job_name = "15"
self.job_uri = f"{self.project_uri}/{URIType.EVALUATION}/{self.job_name}"
Expand Down Expand Up @@ -172,15 +179,15 @@ def test_cloud_create(self, rm: Mocker, m_console: MagicMock):
resource="gpu:1",
)
assert m_console.call_count == 2
assert "project/self/job/11" in m_console.call_args[0][0]
assert "project/self/evaluation/11" in m_console.call_args[0][0]

@Mocker()
@patch("starwhale.core.eval.view.console.print")
def test_cloud_list(self, rm: Mocker, m_console: MagicMock):
rm.request(
HTTPMethod.GET,
f"{self.instance_uri}/api/v1/project/self/job",
text=open(f"{_job_data_dir}/job_list_resp.json").read(),
text=_job_list,
)

jobs, pager = CloudEvaluationJob.list(
Expand Down Expand Up @@ -223,15 +230,16 @@ def test_cloud_info(
rm.request(
HTTPMethod.GET,
f"{self.instance_uri}/api/v1/project/self/job/{self.job_name}",
text=open(f"{_job_data_dir}/job_manifest.yaml").read(),
text=_job_manifest,
)
rm.request(
HTTPMethod.GET,
f"{self.instance_uri}/api/v1/project/self/job/{self.job_name}/task",
text=open(f"{_job_data_dir}/task_list.json").read(),
text=_task_list,
)

info = CloudEvaluationJob(URI(self.job_uri)).info()
print(f"info oo :{info}")
assert len(info["tasks"][0]) == 3
assert info["tasks"][0][0]["taskStatus"] == "SUCCESS"
assert info["tasks"][0][0]["id"] == "40"
Expand Down

0 comments on commit 5e32fd1

Please sign in to comment.