# -*- coding:utf-8 -*-
# 作者：齐振鋆
# 日期：2022/11/10
# 描述:
import logging
import re

import pytest

from unit.public.UI.BasePage import BasePage

log = logging.getLogger('gyxc')


class VerifyTool(BasePage):
    verify_object = {
        're': '正则匹配',
        'in': '包含',
        'large': '大于',
        'less': '小于',
        'eq': '等于'
    }

    def verify_text(self, actual_result, expect_result, verify_type, fail_msg):
        """
        param: actual_result  实际结果
        param: expect_result    预期结果
        param: verify_type  校验类型[re:正则，in：包含，large：大于，less：小于，eq：等于]
        param: fail_msg 失败信息
        """
        res_flag = False
        if verify_type == 're':
            res = re.search(expect_result, actual_result)
            if res:
                res_flag = True
        if verify_type == 'in':
            res_flag = expect_result in actual_result
        if verify_type == 'large':
            res_flag = actual_result > expect_result
        if verify_type == 'less':
            res_flag = actual_result < expect_result
        if verify_type == 'eq':
            res_flag = actual_result == expect_result
        log.info('{} {} {}，结果为：{}'.format(actual_result, self.verify_object[verify_type], expect_result, res_flag))
        if res_flag is False:
            self.screenshot()
            pytest.fail(fail_msg)

    def verify_attribute(self):
        pass
