You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

test_hub_operation.py 1.7 kB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. # Copyright (c) Alibaba, Inc. and its affiliates.
  2. import os.path as osp
  3. import unittest
  4. from maas_hub.maas_api import MaasApi
  5. from maas_hub.repository import Repository
  6. USER_NAME = 'maasadmin'
  7. PASSWORD = '12345678'
  8. class HubOperationTest(unittest.TestCase):
  9. def setUp(self):
  10. self.api = MaasApi()
  11. # note this is temporary before official account management is ready
  12. self.api.login(USER_NAME, PASSWORD)
  13. @unittest.skip('to be used for local test only')
  14. def test_model_repo_creation(self):
  15. # change to proper model names before use
  16. model_name = 'cv_unet_person-image-cartoon_compound-models'
  17. model_chinese_name = '达摩卡通化模型'
  18. model_org = 'damo'
  19. try:
  20. self.api.create_model(
  21. owner=model_org,
  22. name=model_name,
  23. chinese_name=model_chinese_name,
  24. visibility=5, # 1-private, 5-public
  25. license='apache-2.0')
  26. # TODO: support proper name duplication checking
  27. except KeyError as ke:
  28. if ke.args[0] == 'name':
  29. print(f'model {self.model_name} already exists, ignore')
  30. else:
  31. raise
  32. # Note that this can be done via git operation once model repo
  33. # has been created. Git-Op is the RECOMMENDED model upload approach
  34. @unittest.skip('to be used for local test only')
  35. def test_model_upload(self):
  36. local_path = '/path/to/local/model/directory'
  37. assert osp.exists(local_path), 'Local model directory not exist.'
  38. repo = Repository(local_dir=local_path)
  39. repo.push_to_hub(commit_message='Upload model files')
  40. if __name__ == '__main__':
  41. unittest.main()