diff --git a/testTs/config.py b/testTs/config.py index d15970083919289f444abb126e201c35900178fe..c051991bf01c6d6b64580fe8353fe0c2b727f82a 100644 --- a/testTs/config.py +++ b/testTs/config.py @@ -1,3 +1,23 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- + +""" +Copyright (c) 2022 Huawei Device Co., Ltd. +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. + +Description: Use ark to execute test 262 test suite +""" + import os import json TS_GIT_PATH = 'https://gitee.com/zhangrengao1/TypeScript.git' @@ -26,7 +46,7 @@ EXPECT_PATH = os.sep.join([".", "testTs", "expect"]) TS_EXT = ".ts" TXT_EXT = ".txt" ABC_EXT = ".abc" -f = open(IMPORT_FILE_PATH,'r') -content = f.read() -f.close() -IMPORT_TEST = json.loads(content) \ No newline at end of file +IMPORT_TEST = "" +with open(IMPORT_FILE_PATH,'r') as f: + content = f.read() + IMPORT_TEST = json.loads(content) \ No newline at end of file diff --git a/testTs/run_testTs.py b/testTs/run_testTs.py index 1e21b9ed5bbaad255a119757f7d45a479e1aabf9..c4552087bb7cf02bce7e6363b639396cab403771 100644 --- a/testTs/run_testTs.py +++ b/testTs/run_testTs.py @@ -1,3 +1,23 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- + +""" +Copyright (c) 2022 Huawei Device Co., Ltd. +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. + +Description: Use ark to execute test 262 test suite +""" + import os import subprocess import argparse @@ -22,21 +42,20 @@ def parse_args(): def skip(filepath,flag = False): - f = open(SKIP_FILE_PATH,'r') - content = f.read() - f.close() - test_list = [] - import_list =[] - skip_test = json.loads(content) - skip_test_list = skip_test['error.txt'] + skip_test['no2015'] + skip_test['tsc_error'] + skip_test['import_skip'] + skip_test['code_rule'] + skip_test['no_case'] - if os.path.isfile(filepath): - if '.ts' in filepath: - if filepath not in skip_test_list: - return True - else: - if flag: - print(f'This file is outside the scope of validation : {filepath}\n') - return False + with open(SKIP_FILE_PATH,'r') as f: + content = f.read() + test_list = [] + import_list =[] + skip_test = json.loads(content) + skip_test_list = skip_test['error.txt'] + skip_test['no2015'] + skip_test['tsc_error'] + skip_test['import_skip'] + skip_test['code_rule'] + skip_test['no_case'] + if os.path.isfile(filepath): + if '.ts' in filepath: + if filepath not in skip_test_list: + return True + else: + if flag: + print(f'This file is outside the scope of validation : {filepath}\n') + return False def abc_judge(filepath): if not os.path.getsize(filepath): @@ -124,14 +143,12 @@ def run_test_machine(args): run_test(test_path, ark_frontend_tool) result = compare(test_path) result_path.append(result) - f = open(OUT_RESULT_FILE,'w') - f.writelines(result_path) - f.close() + with open(OUT_RESULT_FILE,'w') as f: + f.writelines(result_path) def read_out_file(file_path): - f = open(file_path,'r') - content = f.read() - f.close() + with open(file_path, 'r') as f: + content = f.read() if content: if '}\n{' in content: out_list = content.split('}\n{') @@ -172,11 +189,10 @@ def compare(file,flag = False): for fi in files: fi = f'{root}/{fi}' if fi != out_path: - f = open(fi,'r') - el_file_txt = f.read() - f.close() - write_append(out_path,el_file_txt) - remove_file(fi) + with open(fi,'r') as f: + el_file_txt = f.read() + write_append(out_path,el_file_txt) + remove_file(fi) if (not os.path.exists(out_path) or not os.path.exists(expect_path)): print("There are no expected files or validation file generation: %s", file) result = f'FAIL {file}\n' @@ -200,10 +216,11 @@ def summary(): return count = -1 fail_count = 0 - for count, line in enumerate(open(OUT_RESULT_FILE, 'r')): - if line.startswith("FAIL"): - fail_count += 1 - pass + with open(OUT_RESULT_FILE, 'r') as f: + for count, line in enumerate(f): + if line.startswith("FAIL"): + fail_count += 1 + pass count += 1 print("\n Regression summary") diff --git a/testTs/utils.py b/testTs/utils.py index 41d066c776332cecd0d1ea06feb5a83e2aa56599..bb29b833e3426453d3087477d80328067fc9101d 100644 --- a/testTs/utils.py +++ b/testTs/utils.py @@ -1,3 +1,23 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- + +""" +Copyright (c) 2022 Huawei Device Co., Ltd. +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. + +Description: Use ark to execute test 262 test suite +""" + import os import datetime import shutil @@ -10,7 +30,7 @@ import json #执行终端命令 def command_os(order): cmd = order - os.system(cmd) + subprocess.run(cmd) #创建文件夹 def mk_dir(path): @@ -33,32 +53,26 @@ def remove_file(path): #清空文件内容(path:文件路径) def clean_file(path): - f = open(path,'w') - f.write('') - f.close() + with open(path,'w') as f: + f.write('') #读取文件内容(全部) def read_file(path): - try: - f =open(path,'r') + content = [] + with open(path,'r') as f: content = f.readlines() - f.close() - except: - content = [] return content #写入文件,覆盖之前内容 def write_file(path,content): - f = open(path,'w') - f.write(content) - f.close() + with open(path,'w') as f: + f.write(content) #追加写入文件(path:文件路径,content:写入内容) def write_append(path,content): - f = open(path,'a+') - f.write(content) - f.close() + with open(path,'a+') as f: + f.write(content) def move_file(srcfile, dstfile): subprocess.getstatusoutput("mv %s %s" % (srcfile, dstfile))