Browse Source

[MNT] add semantic_spec in tests

tags/v0.3.2
Gene 2 years ago
parent
commit
22ab5dfdc4
2 changed files with 32 additions and 6 deletions
  1. +5
    -1
      tests/test_learnware_client/test_all_learnware.py
  2. +27
    -5
      tests/test_learnware_client/test_check_learnware.py

+ 5
- 1
tests/test_learnware_client/test_all_learnware.py View File

@@ -1,5 +1,6 @@
import os import os
import json import json
import zipfile
import unittest import unittest
import tempfile import tempfile


@@ -48,8 +49,11 @@ class TestAllLearnware(unittest.TestCase):
for idx in learnware_ids: for idx in learnware_ids:
zip_path = os.path.join(tempdir, f"test_{idx}.zip") zip_path = os.path.join(tempdir, f"test_{idx}.zip")
self.client.download_learnware(idx, zip_path) self.client.download_learnware(idx, zip_path)
with zipfile.ZipFile(zip_path, "r") as zip_file:
with zip_file.open("semantic_specification.json") as json_file:
semantic_spec = json.load(json_file)
try: try:
LearnwareClient.check_learnware(zip_path)
LearnwareClient.check_learnware(zip_path, semantic_spec)
print(f"check learnware {idx} succeed") print(f"check learnware {idx} succeed")
except: except:
failed_ids.append(idx) failed_ids.append(idx)


+ 27
- 5
tests/test_learnware_client/test_check_learnware.py View File

@@ -1,4 +1,6 @@
import os import os
import json
import zipfile
import unittest import unittest
import tempfile import tempfile


@@ -16,35 +18,55 @@ class TestCheckLearnware(unittest.TestCase):
with tempfile.TemporaryDirectory(prefix="learnware_") as tempdir: with tempfile.TemporaryDirectory(prefix="learnware_") as tempdir:
self.zip_path = os.path.join(tempdir, "test.zip") self.zip_path = os.path.join(tempdir, "test.zip")
self.client.download_learnware(learnware_id, self.zip_path) self.client.download_learnware(learnware_id, self.zip_path)
LearnwareClient.check_learnware(self.zip_path)

with zipfile.ZipFile(self.zip_path, "r") as zip_file:
with zip_file.open("semantic_specification.json") as json_file:
semantic_spec = json.load(json_file)
LearnwareClient.check_learnware(self.zip_path, semantic_spec)


def test_check_learnware_conda(self): def test_check_learnware_conda(self):
learnware_id = "00000148" learnware_id = "00000148"
with tempfile.TemporaryDirectory(prefix="learnware_") as tempdir: with tempfile.TemporaryDirectory(prefix="learnware_") as tempdir:
self.zip_path = os.path.join(tempdir, "test.zip") self.zip_path = os.path.join(tempdir, "test.zip")
self.client.download_learnware(learnware_id, self.zip_path) self.client.download_learnware(learnware_id, self.zip_path)
LearnwareClient.check_learnware(self.zip_path)

with zipfile.ZipFile(self.zip_path, "r") as zip_file:
with zip_file.open("semantic_specification.json") as json_file:
semantic_spec = json.load(json_file)
LearnwareClient.check_learnware(self.zip_path, semantic_spec)


def test_check_learnware_dependency(self): def test_check_learnware_dependency(self):
learnware_id = "00000147" learnware_id = "00000147"
with tempfile.TemporaryDirectory(prefix="learnware_") as tempdir: with tempfile.TemporaryDirectory(prefix="learnware_") as tempdir:
self.zip_path = os.path.join(tempdir, "test.zip") self.zip_path = os.path.join(tempdir, "test.zip")
self.client.download_learnware(learnware_id, self.zip_path) self.client.download_learnware(learnware_id, self.zip_path)
LearnwareClient.check_learnware(self.zip_path)

with zipfile.ZipFile(self.zip_path, "r") as zip_file:
with zip_file.open("semantic_specification.json") as json_file:
semantic_spec = json.load(json_file)
LearnwareClient.check_learnware(self.zip_path, semantic_spec)


def test_check_learnware_image(self): def test_check_learnware_image(self):
learnware_id = "00000677" learnware_id = "00000677"
with tempfile.TemporaryDirectory(prefix="learnware_") as tempdir: with tempfile.TemporaryDirectory(prefix="learnware_") as tempdir:
self.zip_path = os.path.join(tempdir, "test.zip") self.zip_path = os.path.join(tempdir, "test.zip")
self.client.download_learnware(learnware_id, self.zip_path) self.client.download_learnware(learnware_id, self.zip_path)
LearnwareClient.check_learnware(self.zip_path)

with zipfile.ZipFile(self.zip_path, "r") as zip_file:
with zip_file.open("semantic_specification.json") as json_file:
semantic_spec = json.load(json_file)
LearnwareClient.check_learnware(self.zip_path, semantic_spec)


def test_check_learnware_text(self): def test_check_learnware_text(self):
learnware_id = "00000662" learnware_id = "00000662"
with tempfile.TemporaryDirectory(prefix="learnware_") as tempdir: with tempfile.TemporaryDirectory(prefix="learnware_") as tempdir:
self.zip_path = os.path.join(tempdir, "test.zip") self.zip_path = os.path.join(tempdir, "test.zip")
self.client.download_learnware(learnware_id, self.zip_path) self.client.download_learnware(learnware_id, self.zip_path)
LearnwareClient.check_learnware(self.zip_path)

with zipfile.ZipFile(self.zip_path, "r") as zip_file:
with zip_file.open("semantic_specification.json") as json_file:
semantic_spec = json.load(json_file)
LearnwareClient.check_learnware(self.zip_path, semantic_spec)




if __name__ == "__main__": if __name__ == "__main__":


Loading…
Cancel
Save