1#!/usr/bin/env python
2# -*- coding: utf-8 -*-
3# Copyright (c) 2021 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
16import unittest
17
18from log_exception import UPDATE_LOGGER
19from log_exception import handle_exception
20from log_exception import VendorExpandError
21from script_generator import Script
22
23
24class TestLogException(unittest.TestCase):
25
26    def setUp(self):
27        print("set up")
28
29    def tearDown(self):
30        print("tear down")
31
32    def test_print_log_error_type(self):
33        """
34        print_log, Input exception type
35        :return:
36        """
37        UPDATE_LOGGER.print_log("Test log!", log_type="TEST_TYPE")
38
39    def test_handle_exception1(self):
40        """
41        handle_exception1, Exception occurred.
42        :return:
43        """
44        vendor_error = VendorExpandError(type(Script), 'test_func')
45        handle_exception(VendorExpandError, None, None)
46        vendor_error.__str__()
47
48    def test_handle_exception2(self):
49        """
50        handle_exception2, Exception occurred.
51        :return:
52        """
53        handle_exception(KeyboardInterrupt, None, None)
54