From 22ab5dfdc4874f76a7b7067df564e3004a23beba Mon Sep 17 00:00:00 2001 From: Gene Date: Sun, 26 Nov 2023 18:06:18 +0800 Subject: [PATCH] [MNT] add semantic_spec in tests --- .../test_all_learnware.py | 6 +++- .../test_check_learnware.py | 32 ++++++++++++++++--- 2 files changed, 32 insertions(+), 6 deletions(-) diff --git a/tests/test_learnware_client/test_all_learnware.py b/tests/test_learnware_client/test_all_learnware.py index 37b9046..2303089 100644 --- a/tests/test_learnware_client/test_all_learnware.py +++ b/tests/test_learnware_client/test_all_learnware.py @@ -1,5 +1,6 @@ import os import json +import zipfile import unittest import tempfile @@ -48,8 +49,11 @@ class TestAllLearnware(unittest.TestCase): for idx in learnware_ids: zip_path = os.path.join(tempdir, f"test_{idx}.zip") 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: - LearnwareClient.check_learnware(zip_path) + LearnwareClient.check_learnware(zip_path, semantic_spec) print(f"check learnware {idx} succeed") except: failed_ids.append(idx) diff --git a/tests/test_learnware_client/test_check_learnware.py b/tests/test_learnware_client/test_check_learnware.py index 218e222..77a44c3 100644 --- a/tests/test_learnware_client/test_check_learnware.py +++ b/tests/test_learnware_client/test_check_learnware.py @@ -1,4 +1,6 @@ import os +import json +import zipfile import unittest import tempfile @@ -16,35 +18,55 @@ class TestCheckLearnware(unittest.TestCase): with tempfile.TemporaryDirectory(prefix="learnware_") as tempdir: self.zip_path = os.path.join(tempdir, "test.zip") 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): learnware_id = "00000148" with tempfile.TemporaryDirectory(prefix="learnware_") as tempdir: self.zip_path = os.path.join(tempdir, "test.zip") 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): learnware_id = "00000147" with tempfile.TemporaryDirectory(prefix="learnware_") as tempdir: self.zip_path = os.path.join(tempdir, "test.zip") 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): learnware_id = "00000677" with tempfile.TemporaryDirectory(prefix="learnware_") as tempdir: self.zip_path = os.path.join(tempdir, "test.zip") 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): learnware_id = "00000662" with tempfile.TemporaryDirectory(prefix="learnware_") as tempdir: self.zip_path = os.path.join(tempdir, "test.zip") 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__":