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 4.0 kB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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_only_zip(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. LearnwareClient.check_learnware(self.zip_path)
  17. def test_check_learnware_pip(self):
  18. learnware_id = "00000208"
  19. with tempfile.TemporaryDirectory(prefix="learnware_") as tempdir:
  20. self.zip_path = os.path.join(tempdir, "test.zip")
  21. self.client.download_learnware(learnware_id, self.zip_path)
  22. with zipfile.ZipFile(self.zip_path, "r") as zip_file:
  23. with zip_file.open("semantic_specification.json") as json_file:
  24. semantic_spec = json.load(json_file)
  25. LearnwareClient.check_learnware(self.zip_path, semantic_spec)
  26. def test_check_learnware_conda(self):
  27. learnware_id = "00000148"
  28. with tempfile.TemporaryDirectory(prefix="learnware_") as tempdir:
  29. self.zip_path = os.path.join(tempdir, "test.zip")
  30. self.client.download_learnware(learnware_id, self.zip_path)
  31. with zipfile.ZipFile(self.zip_path, "r") as zip_file:
  32. with zip_file.open("semantic_specification.json") as json_file:
  33. semantic_spec = json.load(json_file)
  34. LearnwareClient.check_learnware(self.zip_path, semantic_spec)
  35. def test_check_learnware_dependency(self):
  36. learnware_id = "00000147"
  37. with tempfile.TemporaryDirectory(prefix="learnware_") as tempdir:
  38. self.zip_path = os.path.join(tempdir, "test.zip")
  39. self.client.download_learnware(learnware_id, self.zip_path)
  40. with zipfile.ZipFile(self.zip_path, "r") as zip_file:
  41. with zip_file.open("semantic_specification.json") as json_file:
  42. semantic_spec = json.load(json_file)
  43. LearnwareClient.check_learnware(self.zip_path, semantic_spec)
  44. def test_check_learnware_image(self):
  45. learnware_id = "00000677"
  46. with tempfile.TemporaryDirectory(prefix="learnware_") as tempdir:
  47. self.zip_path = os.path.join(tempdir, "test.zip")
  48. self.client.download_learnware(learnware_id, self.zip_path)
  49. with zipfile.ZipFile(self.zip_path, "r") as zip_file:
  50. with zip_file.open("semantic_specification.json") as json_file:
  51. semantic_spec = json.load(json_file)
  52. LearnwareClient.check_learnware(self.zip_path, semantic_spec)
  53. def test_check_learnware_text(self):
  54. learnware_id = "00000662"
  55. with tempfile.TemporaryDirectory(prefix="learnware_") as tempdir:
  56. self.zip_path = os.path.join(tempdir, "test.zip")
  57. self.client.download_learnware(learnware_id, self.zip_path)
  58. with zipfile.ZipFile(self.zip_path, "r") as zip_file:
  59. with zip_file.open("semantic_specification.json") as json_file:
  60. semantic_spec = json.load(json_file)
  61. LearnwareClient.check_learnware(self.zip_path, semantic_spec)
  62. def suite():
  63. _suite = unittest.TestSuite()
  64. _suite.addTest(TestCheckLearnware("test_check_learnware_pip_only_zip"))
  65. _suite.addTest(TestCheckLearnware("test_check_learnware_pip"))
  66. _suite.addTest(TestCheckLearnware("test_check_learnware_conda"))
  67. _suite.addTest(TestCheckLearnware("test_check_learnware_dependency"))
  68. _suite.addTest(TestCheckLearnware("test_check_learnware_image"))
  69. _suite.addTest(TestCheckLearnware("test_check_learnware_text"))
  70. return _suite
  71. if __name__ == "__main__":
  72. runner = unittest.TextTestRunner()
  73. runner.run(suite())