100600bfbSopenharmony_ci#!/usr/bin/env python3 200600bfbSopenharmony_ci# -*- coding: utf-8 -*- 300600bfbSopenharmony_ci# Copyright (C) 2024 Huawei Device Co., Ltd. 400600bfbSopenharmony_ci# Licensed under the Apache License, Version 2.0 (the "License"); 500600bfbSopenharmony_ci# you may not use this file except in compliance with the License. 600600bfbSopenharmony_ci# You may obtain a copy of the License at 700600bfbSopenharmony_ci# 800600bfbSopenharmony_ci# http://www.apache.org/licenses/LICENSE-2.0 900600bfbSopenharmony_ci# 1000600bfbSopenharmony_ci# Unless required by applicable law or agreed to in writing, software 1100600bfbSopenharmony_ci# distributed under the License is distributed on an "AS IS" BASIS, 1200600bfbSopenharmony_ci# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 1300600bfbSopenharmony_ci# See the License for the specific language governing permissions and 1400600bfbSopenharmony_ci# limitations under the License. 1500600bfbSopenharmony_ci 1600600bfbSopenharmony_ciimport subprocess 1700600bfbSopenharmony_ciimport pkg_resources 1800600bfbSopenharmony_ciimport pytest 1900600bfbSopenharmony_ciimport os 2000600bfbSopenharmony_ciimport time 2100600bfbSopenharmony_ci 2200600bfbSopenharmony_ciGetVersion = "V1.0.0" 2300600bfbSopenharmony_ci 2400600bfbSopenharmony_cidef check_library_installation(library_name): 2500600bfbSopenharmony_ci try: 2600600bfbSopenharmony_ci pkg_resources.get_distribution(library_name) 2700600bfbSopenharmony_ci return 0 2800600bfbSopenharmony_ci except pkg_resources.DistributionNotFound: 2900600bfbSopenharmony_ci print(f"\n\n{library_name} is not installed.\n\n") 3000600bfbSopenharmony_ci print(f"try to use command below:") 3100600bfbSopenharmony_ci print(f"pip install {library_name}") 3200600bfbSopenharmony_ci return 1 3300600bfbSopenharmony_ci 3400600bfbSopenharmony_ci 3500600bfbSopenharmony_ciif __name__ == '__main__': 3600600bfbSopenharmony_ci if check_library_installation("pytest"): 3700600bfbSopenharmony_ci subprocess.check_call(["pip", "install", "-r", "requirements.txt"]) 3800600bfbSopenharmony_ci if check_library_installation("pytest"): 3900600bfbSopenharmony_ci exit(1) 4000600bfbSopenharmony_ci 4100600bfbSopenharmony_ci start_time = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(time.time())) 4200600bfbSopenharmony_ci pytest.main() 4300600bfbSopenharmony_ci end_time = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(time.time())) 4400600bfbSopenharmony_ci report_time = time.strftime('%Y-%m-%d_%H_%M_%S', time.localtime(time.time())) 4500600bfbSopenharmony_ci report_dir = os.path.join(os.getcwd(), "reports") 4600600bfbSopenharmony_ci report_file = os.path.join(report_dir, f"{report_time}report.html") 4700600bfbSopenharmony_ci print(f"Test over, the script version is {GetVersion}," 4800600bfbSopenharmony_ci f" start at {start_time}, end at {end_time} \n" 4900600bfbSopenharmony_ci f"=======>{report_file} is saved. \n" 5000600bfbSopenharmony_ci ) 5100600bfbSopenharmony_ci input("=======>press [Enter] key to Show logs.") 5200600bfbSopenharmony_ci 5300600bfbSopenharmony_ci 5400600bfbSopenharmony_ci # os.system("allure generate temp -o reports") 55