From 1a0d4af55a2eee69d89633874890f50eda8f8700 Mon Sep 17 00:00:00 2001 From: "yingda.chen" Date: Thu, 23 Jun 2022 16:55:48 +0800 Subject: [PATCH] [to #42322933] test level check Link: https://code.alibaba-inc.com/Ali-MaaS/MaaS-lib/codereview/9143809 --- tests/pipelines/test_image_matting.py | 2 +- tests/pipelines/test_person_image_cartoon.py | 2 +- tests/pipelines/test_sentence_similarity.py | 6 +++--- tests/pipelines/test_speech_signal_process.py | 2 ++ tests/pipelines/test_text_classification.py | 8 ++------ tests/pipelines/test_text_generation.py | 2 +- tests/pipelines/test_text_to_speech.py | 11 ++++------- tests/pipelines/test_word_segmentation.py | 4 ++-- tests/preprocessors/test_image.py | 1 - tests/pydatasets/test_py_dataset.py | 5 +++-- 10 files changed, 19 insertions(+), 24 deletions(-) diff --git a/tests/pipelines/test_image_matting.py b/tests/pipelines/test_image_matting.py index 751b6975..f7838d5e 100644 --- a/tests/pipelines/test_image_matting.py +++ b/tests/pipelines/test_image_matting.py @@ -52,7 +52,7 @@ class ImageMattingTest(unittest.TestCase): cv2.imwrite('result.png', result['output_png']) print(f'Output written to {osp.abspath("result.png")}') - @unittest.skipUnless(test_level() >= 0, 'skip test in current test level') + @unittest.skipUnless(test_level() >= 2, 'skip test in current test level') def test_run_modelhub_default_model(self): img_matting = pipeline(Tasks.image_matting) diff --git a/tests/pipelines/test_person_image_cartoon.py b/tests/pipelines/test_person_image_cartoon.py index ed912b1c..f47ca008 100644 --- a/tests/pipelines/test_person_image_cartoon.py +++ b/tests/pipelines/test_person_image_cartoon.py @@ -42,7 +42,7 @@ class ImageCartoonTest(unittest.TestCase): img_cartoon = pipeline(Tasks.image_generation, model=self.model_id) self.pipeline_inference(img_cartoon, self.test_image) - @unittest.skipUnless(test_level() >= 1, 'skip test in current test level') + @unittest.skipUnless(test_level() >= 2, 'skip test in current test level') def test_run_modelhub_default_model(self): img_cartoon = pipeline(Tasks.image_generation) self.pipeline_inference(img_cartoon, self.test_image) diff --git a/tests/pipelines/test_sentence_similarity.py b/tests/pipelines/test_sentence_similarity.py index 43e585ba..df38593f 100644 --- a/tests/pipelines/test_sentence_similarity.py +++ b/tests/pipelines/test_sentence_similarity.py @@ -16,7 +16,7 @@ class SentenceSimilarityTest(unittest.TestCase): sentence1 = '今天气温比昨天高么?' sentence2 = '今天湿度比昨天高么?' - @unittest.skipUnless(test_level() >= 0, 'skip test in current test level') + @unittest.skipUnless(test_level() >= 2, 'skip test in current test level') def test_run(self): cache_path = snapshot_download(self.model_id) tokenizer = SequenceClassificationPreprocessor(cache_path) @@ -32,7 +32,7 @@ class SentenceSimilarityTest(unittest.TestCase): f'sentence1: {self.sentence1}\nsentence2: {self.sentence2}\n' f'pipeline1: {pipeline2(input=(self.sentence1, self.sentence2))}') - @unittest.skipUnless(test_level() >= 0, 'skip test in current test level') + @unittest.skipUnless(test_level() >= 2, 'skip test in current test level') def test_run_with_model_from_modelhub(self): model = Model.from_pretrained(self.model_id) tokenizer = SequenceClassificationPreprocessor(model.model_dir) @@ -48,7 +48,7 @@ class SentenceSimilarityTest(unittest.TestCase): task=Tasks.sentence_similarity, model=self.model_id) print(pipeline_ins(input=(self.sentence1, self.sentence2))) - @unittest.skipUnless(test_level() >= 0, 'skip test in current test level') + @unittest.skipUnless(test_level() >= 2, 'skip test in current test level') def test_run_with_default_model(self): pipeline_ins = pipeline(task=Tasks.sentence_similarity) print(pipeline_ins(input=(self.sentence1, self.sentence2))) diff --git a/tests/pipelines/test_speech_signal_process.py b/tests/pipelines/test_speech_signal_process.py index 23939f8e..1b070fda 100644 --- a/tests/pipelines/test_speech_signal_process.py +++ b/tests/pipelines/test_speech_signal_process.py @@ -6,6 +6,7 @@ from modelscope.fileio import File from modelscope.metainfo import Pipelines from modelscope.pipelines import pipeline from modelscope.utils.constant import Tasks +from modelscope.utils.test_utils import test_level NEAREND_MIC_URL = 'https://isv-data.oss-cn-hangzhou.aliyuncs.com/ics/MaaS/AEC/sample_audio/nearend_mic.wav' FAREND_SPEECH_URL = 'https://isv-data.oss-cn-hangzhou.aliyuncs.com/ics/MaaS/AEC/sample_audio/farend_speech.wav' @@ -33,6 +34,7 @@ class SpeechSignalProcessTest(unittest.TestCase): # A temporary hack to provide c++ lib. Download it first. download(AEC_LIB_URL, AEC_LIB_FILE) + @unittest.skipUnless(test_level() >= 1, 'skip test in current test level') def test_run(self): download(NEAREND_MIC_URL, NEAREND_MIC_FILE) download(FAREND_SPEECH_URL, FAREND_SPEECH_FILE) diff --git a/tests/pipelines/test_text_classification.py b/tests/pipelines/test_text_classification.py index 2581c220..3c66d3e6 100644 --- a/tests/pipelines/test_text_classification.py +++ b/tests/pipelines/test_text_classification.py @@ -1,12 +1,8 @@ # Copyright (c) Alibaba, Inc. and its affiliates. import shutil import unittest -import zipfile -from pathlib import Path -from modelscope.fileio import File from modelscope.models import Model -from modelscope.models.nlp import BertForSequenceClassification from modelscope.pipelines import SequenceClassificationPipeline, pipeline from modelscope.preprocessors import SequenceClassificationPreprocessor from modelscope.pydatasets import PyDataset @@ -62,7 +58,7 @@ class SequenceClassificationTest(unittest.TestCase): hub=Hubs.huggingface)) self.printDataset(result) - @unittest.skipUnless(test_level() >= 1, 'skip test in current test level') + @unittest.skipUnless(test_level() >= 2, 'skip test in current test level') def test_run_with_default_model(self): text_classification = pipeline(task=Tasks.text_classification) result = text_classification( @@ -74,7 +70,7 @@ class SequenceClassificationTest(unittest.TestCase): hub=Hubs.huggingface)) self.printDataset(result) - @unittest.skipUnless(test_level() >= 1, 'skip test in current test level') + @unittest.skipUnless(test_level() >= 2, 'skip test in current test level') def test_run_with_dataset(self): model = Model.from_pretrained(self.model_id) preprocessor = SequenceClassificationPreprocessor( diff --git a/tests/pipelines/test_text_generation.py b/tests/pipelines/test_text_generation.py index cb5194c2..9df3b8bb 100644 --- a/tests/pipelines/test_text_generation.py +++ b/tests/pipelines/test_text_generation.py @@ -68,7 +68,7 @@ class TextGenerationTest(unittest.TestCase): pipeline_ins = pipeline(task=Tasks.text_generation, model=model_id) print(pipeline_ins(input)) - @unittest.skipUnless(test_level() >= 1, 'skip test in current test level') + @unittest.skipUnless(test_level() >= 2, 'skip test in current test level') def test_run_with_default_model(self): pipeline_ins = pipeline(task=Tasks.text_generation) print(pipeline_ins(self.input_zh)) diff --git a/tests/pipelines/test_text_to_speech.py b/tests/pipelines/test_text_to_speech.py index 0d76cbac..e92047d6 100644 --- a/tests/pipelines/test_text_to_speech.py +++ b/tests/pipelines/test_text_to_speech.py @@ -1,7 +1,5 @@ -import time import unittest -import json import tensorflow as tf # NOTICE: Tensorflow 1.15 seems not so compatible with pytorch. # A segmentation fault may be raise by pytorch cpp library @@ -10,21 +8,20 @@ import tensorflow as tf import torch from scipy.io.wavfile import write -from modelscope.fileio import File from modelscope.metainfo import Pipelines, Preprocessors -from modelscope.models import Model, build_model -from modelscope.models.audio.tts.am import SambertNetHifi16k -from modelscope.models.audio.tts.vocoder import AttrDict, Hifigan16k +from modelscope.models import Model from modelscope.pipelines import pipeline from modelscope.preprocessors import build_preprocessor -from modelscope.utils.constant import Fields, InputFields, Tasks +from modelscope.utils.constant import Fields from modelscope.utils.logger import get_logger +from modelscope.utils.test_utils import test_level logger = get_logger() class TextToSpeechSambertHifigan16kPipelineTest(unittest.TestCase): + @unittest.skipUnless(test_level() >= 1, 'skip test in current test level') def test_pipeline(self): lang_type = 'pinyin' text = '明天天气怎么样' diff --git a/tests/pipelines/test_word_segmentation.py b/tests/pipelines/test_word_segmentation.py index 7c57d9ad..a6c27893 100644 --- a/tests/pipelines/test_word_segmentation.py +++ b/tests/pipelines/test_word_segmentation.py @@ -37,13 +37,13 @@ class WordSegmentationTest(unittest.TestCase): task=Tasks.word_segmentation, model=model, preprocessor=tokenizer) print(pipeline_ins(input=self.sentence)) - @unittest.skipUnless(test_level() >= 0, 'skip test in current test level') + @unittest.skipUnless(test_level() >= 1, 'skip test in current test level') def test_run_with_model_name(self): pipeline_ins = pipeline( task=Tasks.word_segmentation, model=self.model_id) print(pipeline_ins(input=self.sentence)) - @unittest.skipUnless(test_level() >= 0, 'skip test in current test level') + @unittest.skipUnless(test_level() >= 2, 'skip test in current test level') def test_run_with_default_model(self): pipeline_ins = pipeline(task=Tasks.word_segmentation) print(pipeline_ins(input=self.sentence)) diff --git a/tests/preprocessors/test_image.py b/tests/preprocessors/test_image.py index 21ae780e..4d66c171 100644 --- a/tests/preprocessors/test_image.py +++ b/tests/preprocessors/test_image.py @@ -5,7 +5,6 @@ import unittest import PIL from modelscope.preprocessors import load_image -from modelscope.utils.logger import get_logger class ImagePreprocessorTest(unittest.TestCase): diff --git a/tests/pydatasets/test_py_dataset.py b/tests/pydatasets/test_py_dataset.py index 4ad767fa..9cefe003 100644 --- a/tests/pydatasets/test_py_dataset.py +++ b/tests/pydatasets/test_py_dataset.py @@ -33,6 +33,7 @@ class ImgPreprocessor(Preprocessor): class PyDatasetTest(unittest.TestCase): + @unittest.skipUnless(test_level() >= 1, 'skip test in current test level') def test_ds_basic(self): ms_ds_full = PyDataset.load('squad') ms_ds_full_hf = hfdata.load_dataset('squad') @@ -82,7 +83,7 @@ class PyDatasetTest(unittest.TestCase): drop_remainder=True) print(next(iter(tf_dataset))) - @unittest.skipUnless(test_level() >= 1, 'skip test in current test level') + @unittest.skipUnless(test_level() >= 2, 'skip test in current test level') @require_torch def test_to_torch_dataset_img(self): ms_image_train = PyDataset.from_hf_dataset( @@ -94,7 +95,7 @@ class PyDatasetTest(unittest.TestCase): dataloader = torch.utils.data.DataLoader(pt_dataset, batch_size=5) print(next(iter(dataloader))) - @unittest.skipUnless(test_level() >= 1, 'skip test in current test level') + @unittest.skipUnless(test_level() >= 2, 'skip test in current test level') @require_tf def test_to_tf_dataset_img(self): import tensorflow as tf