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_check_learnware.py 3.1 kB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. import os
  2. import json
  3. import zipfile
  4. import unittest
  5. import tempfile
  6. from learnware.client import LearnwareClient
  7. class TestCheckLearnware(unittest.TestCase):
  8. def setUp(self):
  9. unittest.TestCase.setUpClass()
  10. self.client = LearnwareClient()
  11. def test_check_learnware_pip(self):
  12. learnware_id = "00000208"
  13. with tempfile.TemporaryDirectory(prefix="learnware_") as tempdir:
  14. self.zip_path = os.path.join(tempdir, "test.zip")
  15. self.client.download_learnware(learnware_id, self.zip_path)
  16. with zipfile.ZipFile(self.zip_path, "r") as zip_file:
  17. with zip_file.open("semantic_specification.json") as json_file:
  18. semantic_spec = json.load(json_file)
  19. LearnwareClient.check_learnware(self.zip_path, semantic_spec)
  20. def test_check_learnware_conda(self):
  21. learnware_id = "00000148"
  22. with tempfile.TemporaryDirectory(prefix="learnware_") as tempdir:
  23. self.zip_path = os.path.join(tempdir, "test.zip")
  24. self.client.download_learnware(learnware_id, self.zip_path)
  25. with zipfile.ZipFile(self.zip_path, "r") as zip_file:
  26. with zip_file.open("semantic_specification.json") as json_file:
  27. semantic_spec = json.load(json_file)
  28. LearnwareClient.check_learnware(self.zip_path, semantic_spec)
  29. def test_check_learnware_dependency(self):
  30. learnware_id = "00000147"
  31. with tempfile.TemporaryDirectory(prefix="learnware_") as tempdir:
  32. self.zip_path = os.path.join(tempdir, "test.zip")
  33. self.client.download_learnware(learnware_id, self.zip_path)
  34. with zipfile.ZipFile(self.zip_path, "r") as zip_file:
  35. with zip_file.open("semantic_specification.json") as json_file:
  36. semantic_spec = json.load(json_file)
  37. LearnwareClient.check_learnware(self.zip_path, semantic_spec)
  38. def test_check_learnware_image(self):
  39. learnware_id = "00000677"
  40. with tempfile.TemporaryDirectory(prefix="learnware_") as tempdir:
  41. self.zip_path = os.path.join(tempdir, "test.zip")
  42. self.client.download_learnware(learnware_id, self.zip_path)
  43. with zipfile.ZipFile(self.zip_path, "r") as zip_file:
  44. with zip_file.open("semantic_specification.json") as json_file:
  45. semantic_spec = json.load(json_file)
  46. LearnwareClient.check_learnware(self.zip_path, semantic_spec)
  47. def test_check_learnware_text(self):
  48. learnware_id = "00000662"
  49. with tempfile.TemporaryDirectory(prefix="learnware_") as tempdir:
  50. self.zip_path = os.path.join(tempdir, "test.zip")
  51. self.client.download_learnware(learnware_id, self.zip_path)
  52. with zipfile.ZipFile(self.zip_path, "r") as zip_file:
  53. with zip_file.open("semantic_specification.json") as json_file:
  54. semantic_spec = json.load(json_file)
  55. LearnwareClient.check_learnware(self.zip_path, semantic_spec)
  56. if __name__ == "__main__":
  57. unittest.main()