1#!/usr/bin/env python 2# coding=utf-8 3 4# # 5# # Copyright (c) 2024 Huawei Device Co., Ltd. 6# # Licensed under the Apache License, Version 2.0 (the "License"); 7# # you may not use this file except in compliance with the License. 8# # You may obtain a copy of the License at 9# # 10# # http://www.apache.org/licenses/LICENSE-2.0 11# # 12# # Unless required by applicable law or agreed to in writing, software 13# # distributed under the License is distributed on an "AS IS" BASIS, 14# # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15# # See the License for the specific language governing permissions and 16# # limitations under the License. 17# # 18 19import argparse 20import os 21import sys 22import unittest 23import config 24 25 26class RunTest: 27 args = None 28 suite = unittest.TestSuite() 29 loader = unittest.TestLoader() 30 hap_list = [] 31 32 def __init__(self): 33 self.parse_args() 34 self.run_test() 35 36 def parse_args(self): 37 parser = argparse.ArgumentParser(description='Plugin test.') 38 parser.add_argument( 39 '-hdctool', 40 action='store', 41 required=True, 42 default=None, 43 help='Remote connnection tool.' 44 ) 45 self.args = parser.parse_args() 46 47 def discover_cases(self): 48 current_dir = os.path.dirname(os.path.abspath(__file__)) 49 case_dir = current_dir + os.sep + 'js_test_case' 50 discover = self.loader.discover(case_dir, pattern='*.py') 51 self.suite.addTest(discover) 52 53 def get_panda_list(self): 54 self.hap_list = config.hap_list 55 56 def run_test(self): 57 if self.args.hdctool is not None: 58 os.environ["HDCTool"] = self.args.hdctool 59 else: 60 print("please input the path to hdc tool!") 61 sys.exit(0) 62 self.get_panda_list() 63 for hap_name in self.hap_list: 64 if (hap_name != "com.example.myapplication1"): 65 os.environ["isRelease"] = "False" 66 else: 67 os.environ["isRelease"] = "True" 68 self.suite = unittest.TestSuite() 69 self.discover_cases() 70 os.environ["HapName"] = hap_name 71 runner = unittest.TextTestRunner(verbosity=2) 72 runner.run(self.suite) 73 74Main = RunTest 75 76if __name__ == '__main__': 77 Main() 78