Browse Source

[to #44031139]fix: fix hub ci case delete test project failure

Link: https://code.alibaba-inc.com/Ali-MaaS/MaaS-lib/codereview/9736416

    * [to #44031139]fix: fix hub ci case delete test project failure
master
mulin.lyh 3 years ago
parent
commit
c57c91c359
2 changed files with 11 additions and 4 deletions
  1. +2
    -1
      modelscope/hub/api.py
  2. +9
    -3
      tests/hub/test_hub_operation.py

+ 2
- 1
modelscope/hub/api.py View File

@@ -190,7 +190,8 @@ class HubApi:
r = requests.put(
path,
data='{"Path":"%s", "PageNumber":%s, "PageSize": %s}' %
(owner_or_group, page_number, page_size))
(owner_or_group, page_number, page_size),
cookies=cookies)
handle_http_response(r, logger, cookies, 'list_model')
if r.status_code == HTTPStatus.OK:
if is_ok(r.json()):


+ 9
- 3
tests/hub/test_hub_operation.py View File

@@ -35,6 +35,11 @@ class HubOperationTest(unittest.TestCase):
license=Licenses.APACHE_V2,
chinese_name=TEST_MODEL_CHINESE_NAME,
)

def tearDown(self):
self.api.delete_model(model_id=self.model_id)

def prepare_case(self):
temporary_dir = tempfile.mkdtemp()
self.model_dir = os.path.join(temporary_dir, self.model_name)
repo = Repository(self.model_dir, clone_from=self.model_id)
@@ -42,9 +47,6 @@ class HubOperationTest(unittest.TestCase):
% os.path.join(self.model_dir, download_model_file_name))
repo.push('add model')

def tearDown(self):
self.api.delete_model(model_id=self.model_id)

def test_model_repo_creation(self):
# change to proper model names before use
try:
@@ -57,6 +59,7 @@ class HubOperationTest(unittest.TestCase):
raise

def test_download_single_file(self):
self.prepare_case()
downloaded_file = model_file_download(
model_id=self.model_id, file_path=download_model_file_name)
assert os.path.exists(downloaded_file)
@@ -68,6 +71,7 @@ class HubOperationTest(unittest.TestCase):
assert mdtime1 == mdtime2

def test_snapshot_download(self):
self.prepare_case()
snapshot_path = snapshot_download(model_id=self.model_id)
downloaded_file_path = os.path.join(snapshot_path,
download_model_file_name)
@@ -82,6 +86,7 @@ class HubOperationTest(unittest.TestCase):
file_path=download_model_file_name) # not add counter

def test_download_public_without_login(self):
self.prepare_case()
rmtree(ModelScopeConfig.path_credential)
snapshot_path = snapshot_download(model_id=self.model_id)
downloaded_file_path = os.path.join(snapshot_path,
@@ -96,6 +101,7 @@ class HubOperationTest(unittest.TestCase):
self.api.login(TEST_ACCESS_TOKEN1)

def test_snapshot_delete_download_cache_file(self):
self.prepare_case()
snapshot_path = snapshot_download(model_id=self.model_id)
downloaded_file_path = os.path.join(snapshot_path,
download_model_file_name)


Loading…
Cancel
Save