1#!/usr/bin/env python 2# -*- coding: utf-8 -*- 3# Copyright (c) 2023 Huawei Device Co., Ltd. 4# Licensed under the Apache License, Version 2.0 (the "License"); 5# you may not use this file except in compliance with the License. 6# You may obtain a copy of the License at 7# 8# http://www.apache.org/licenses/LICENSE-2.0 9# 10# Unless required by applicable law or agreed to in writing, software 11# distributed under the License is distributed on an "AS IS" BASIS, 12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13# See the License for the specific language governing permissions and 14# limitations under the License. 15 16 17import sys 18import os 19import json 20import unittest 21sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), "../../src"))) 22from coreImpl.check.check import get_check_result_list, write_in_txt 23 24 25class TestMethods(unittest.TestCase): 26 def test_check(self): 27 test_path = os.path.abspath(os.path.join(os.path.dirname(__file__), "..\\")) 28 test_case_path = os.path.join(test_path, "ut\\check") 29 output_path = os.path.join(test_path, "output\\check") 30 expect_path = os.path.join(test_path, "expect\\check") 31 for dirpath, dirnames, filenames in os.walk(test_case_path): 32 for item in filenames: 33 file_name = item.split('.')[0] 34 check_result = get_check_result_list([os.path.join(dirpath, item)]) 35 write_in_txt(check_result, os.path.join(output_path, "{}.txt".format(file_name))) 36 with open(os.path.join(expect_path, "{}.txt".format(file_name))) as json_file: 37 permission_file_content = json.load(json_file) 38 result_json = json.dumps(permission_file_content, default=lambda obj: obj.__dict__, indent=4) 39 self.assertEqual(result_json, "result_json", "{} case is error".format(os.path.join(dirpath, item))) 40 41 42if __name__ == '__main__': 43 unittest.main() 44