"""
 -*-coding:utf-8 -*- 
----------------------------------------------------------------------------
--ProjectName:   pytest
--FileName:      test_bpm.py
--Author:        Lin
--Datetime:      2024/11/05 下午7:19
--Description:  读取json文件
-----------------(❁´◡`❁)---------------------------------------------------
"""
import json
import os

from APIAutomaticTesting import log, logor


def read_json(file_path):
    """读取json文件,将json文件的内容序列化为python对象在返回"""
    log.info(f"执行的函数为:read_json,描述为:读取json文件,将json文件的内容序列化为python对象在返回,传入的参数为:{file_path}")
    if isinstance(file_path, str) and os.path.isfile(file_path) and file_path.endswith(".json"):
        with open(file_path, mode="r", encoding="utf-8") as f:
            try:
                return json.loads(f.read())
            except Exception as e:
                log.error(
                    f"执行的函数为:read_json,描述为:读取json文件,将json文件的内容序列化为python对象在返回,传入的参数为:{file_path}, 文件路径不存在"
                    f"错误类型为:{type(e)}, 错误的描述为:{e}")
                raise e
    else:
        log.error(f"执行的函数为:read_json,描述为:读取json文件,将json文件的内容序列化为python对象在返回,传入的参数为:{file_path}, 文件路径不存在"
                  f"错误类型为:FileNotFoundError, 错误的描述为:文件路径错误")
        raise FileNotFoundError("文件路径错误")