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_all_learnware.py 1.9 kB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. import os
  2. import unittest
  3. import tempfile
  4. from learnware.client import LearnwareClient
  5. from learnware.specification import Specification
  6. class TestAllLearnware(unittest.TestCase):
  7. def setUp(self):
  8. unittest.TestCase.setUpClass()
  9. email = "liujd@lamda.nju.edu.cn"
  10. token = "f7e647146a314c6e8b4e2e1079c4bca4"
  11. self.client = LearnwareClient()
  12. self.client.login(email, token)
  13. def test_all_learnware(self):
  14. max_learnware_num = 1000
  15. semantic_spec = dict()
  16. semantic_spec["Data"] = {"Type": "Class", "Values": []}
  17. semantic_spec["Task"] = {"Type": "Class", "Values": []}
  18. semantic_spec["Library"] = {"Type": "Class", "Values": []}
  19. semantic_spec["Scenario"] = {"Type": "Tag", "Values": []}
  20. semantic_spec["Name"] = {"Type": "String", "Values": ""}
  21. semantic_spec["Description"] = {"Type": "String", "Values": ""}
  22. specification = Specification(semantic_spec=semantic_spec)
  23. result = self.client.search_learnware(specification, page_size=max_learnware_num)
  24. print(f"result size: {len(result)}")
  25. print(f"key in result: {[key for key in result[0]]}")
  26. failed_ids = []
  27. learnware_ids = [res["learnware_id"] for res in result]
  28. with tempfile.TemporaryDirectory(prefix="learnware_") as tempdir:
  29. for idx in learnware_ids:
  30. zip_path = os.path.join(tempdir, f"test_{idx}.zip")
  31. self.client.download_learnware(idx, zip_path)
  32. try:
  33. LearnwareClient.check_learnware(zip_path)
  34. print(f"check learnware {idx} succeed")
  35. except:
  36. failed_ids.append(idx)
  37. print(f"check learnware {idx} failed!!!")
  38. print(f"failed learnware ids: {failed_ids}")
  39. if __name__ == "__main__":
  40. unittest.main()