源码网_python源码从哪下载

源码网_python源码从哪下载源码目录结构我们首先来看下models.py的代码结构我们可以看到这个模块中定义了12个属性和22个模型类,我们依次来看属性源码分析importosfromenumimportEnu

大家好,又见面了,我是你们的朋友全栈君。如果您正在找激活码,请点击查看最新教程,关注关注公众号 “全栈程序员社区” 获取激活教程,可能之前旧版本教程已经失效.最新Idea2022.1教程亲测有效,一键激活。

Jetbrains全系列IDE使用 1年只要46元 售后保障 童叟无欺

源码目录结构

我们首先来看下models.py的代码结构
源码网_python源码从哪下载
我们可以看到这个模块中定义了12个属性和22个模型类,我们依次来看
 

属性源码分析

import os
from enum import Enum
from typing import Any
from typing import Dict, Text, Union, Callable
from typing import List

from pydantic import BaseModel, Field
from pydantic import HttpUrl

Name = Text
Url = Text
BaseUrl = Union[HttpUrl, Text]
VariablesMapping = Dict[Text, Any]
FunctionsMapping = Dict[Text, Callable]
Headers = Dict[Text, Text]
Cookies = Dict[Text, Text]
Verify = bool
Hooks = List[Union[Text, Dict[Text, Text]]]
Export = List[Text]
Validators = List[Dict]
Env = Dict[Text, Any]

一句话总结:用到了typingpydantic模块,目的是告诉读者我这些属性是什么类型的
 

模型类源码分析

这里以代码注解的方式讲解
 

MethodEnum

class MethodEnum(Text, Enum):
    """
    枚举请求方法,定义了常用的http请求方法
    """
    GET = "GET"
    POST = "POST"
    PUT = "PUT"
    DELETE = "DELETE"
    HEAD = "HEAD"
    OPTIONS = "OPTIONS"
    PATCH = "PATCH

 

TConfig

class TConfig(BaseModel):
    """
    定义配置信息,包含如下:
    1.name      (str)
    2.verify    (bool)
    3.base_url  (http/https开头的str类型)
    4.variables (dict)
    5.parameters(dict)
    6.export    (list[str])
    7.path      (str)
    8.weight    (int)
    """
    name: Name  # str类型
    verify: Verify = False  
    base_url: BaseUrl = ""
    # Text: prepare variables in debugtalk.py, ${gen_variables()}
    variables: Union[VariablesMapping, Text] = {}
    parameters: Union[VariablesMapping, Text] = {}
    # setup_hooks: Hooks = []
    # teardown_hooks: Hooks = []
    export: Export = []
    path: Text = None
    weight: int = 1

 

TRequest

class TRequest(BaseModel):
    """
    requests.Request model
    
    1.method  (枚举类型)
    2.url     (str)
    3.params  (dict)
    4.headers (dict)
    5.req_json(dict/list/str)
    6.data    (dict/str)
    7.cookie  (dict)
    8.timeout (float)
    9.allow_redirects (bool)
    10.verify (bool)
    11.upload (dict)
    """
    
    method: MethodEnum
    url: Url
    params: Dict[Text, Text] = {}
    headers: Headers = {}
    req_json: Union[Dict, List, Text] = Field(None, alias="json")
    data: Union[Text, Dict[Text, Any]] = None
    cookies: Cookies = {}
    timeout: float = 120
    allow_redirects: bool = True
    verify: Verify = False
    upload: Dict = {}  # used for upload files

 

TStep

class TStep(BaseModel):
    """
    测试步骤,里面包含了request请求

    1.name              (str)
    2.request           (TRequest)
    3.testcase          (str/Callable)
    4.variables         (dict)
    5.setup_hooks       (list(dict))
    6.teardown_hooks    (list(dict))
    7.extract           (dict)
    8.export            (list)
    9.validators        (list(dict))
    10.validate_script  (list[str])
    """
    name: Name
    request: Union[TRequest, None] = None
    testcase: Union[Text, Callable, None] = None
    variables: VariablesMapping = {}
    setup_hooks: Hooks = []
    teardown_hooks: Hooks = []
    # used to extract request's response field
    extract: VariablesMapping = {}
    # used to export session variables from referenced testcase
    export: Export = []
    validators: Validators = Field([], alias="validate")
    validate_script: List[Text] = []

 

TestCase

class TestCase(BaseModel):
    """
    测试用例,包含了测试步骤和配置信息
    """
    config: TConfig
    teststeps: List[TStep]

 

ProjectMeta

class ProjectMeta(BaseModel):
    """
    项目结构
    1.debugtalk_py   (str)                   debugtakl文件内容
    2.debugtalk_path (str)                   debugtalk文件路径
    3.dot_env_path   (str)                   env文件路径
    4.functions      (dict(Callable/str))    在debugtalk中定义的函数
    5.env            (dict)                  环境
    6.RootDir        (str)                   根路径(绝对路径),debugtalk位于的路径
    """
    debugtalk_py: Text = ""  # debugtalk.py file content
    debugtalk_path: Text = ""  # debugtalk.py file path
    dot_env_path: Text = ""  # .env file path
    functions: FunctionsMapping = {}  # functions defined in debugtalk.py
    env: Env = {}
    RootDir: Text = os.getcwd()  # project root directory (ensure absolute), the path debugtalk.py located

 

TestsMapping

class TestsMapping(BaseModel):
    """
    测试映射
    1.project_meta
    2.testcases 测试用例集,list下有多个用例
    """
    project_meta: ProjectMeta
    testcases: List[TestCase]

 

TestCaseTime

class TestCaseTime(BaseModel):
    """
    测试用例时间

    1.start_at:开始时间默认为0
    2.start_at_iso_format:以iso格式启动
    3.duration:持续时间
    """
    start_at: float = 0
    start_at_iso_format: Text = ""
    duration: float = 0

 

TestCaseInOut

class TestCaseInOut(BaseModel):
    """
    测试用例的输入输出:

    config_vars:配置变量
    export_vars:导出变量
    """
    config_vars: VariablesMapping = {}
    export_vars: Dict = {}

 

RequestStat

class RequestStat(BaseModel):
    """
    请求指标:

    content_size:内容大小
    response_time_ms:响应时间(ms)
    elapsed_ms:逝去的时间(ms)
    """
    content_size: float = 0
    response_time_ms: float = 0
    elapsed_ms: float = 0

 

AddressData

class AddressData(BaseModel):
    """
    客户端与服务器地址数据

    client_ip:客户端ip地址
    client_port:客户端端口号
    server_ip:服务器ip地址
    server_port:服务器端口号
    """
    client_ip: Text = "N/A"
    client_port: int = 0
    server_ip: Text = "N/A"
    server_port: int = 0

 

RequestData

class RequestData(BaseModel):
    """
    请求数据

    method:请求方法,默认为GET
    url:url地址
    headers:请求头
    cookies:cookie信息
    body:请求体
    """
    method: MethodEnum = MethodEnum.GET
    url: Url
    headers: Headers = {}
    cookies: Cookies = {}
    body: Union[Text, bytes, List, Dict, None] = {}

 

ResponseData

class ResponseData(BaseModel):
    """
    响应数据

    status_code:状态码
    headers:响应头
    cookies:cookie信息
    encoding:编码格式
    content_type:内容类型
    body:响应体
    """
    status_code: int
    headers: Dict
    cookies: Cookies
    encoding: Union[Text, None] = None
    content_type: Text
    body: Union[Text, bytes, List, Dict]

 

ReqRespData

class ReqRespData(BaseModel):
    """
    请求响应数据
    request:RequestData
    response:ResponseData
    """
    request: RequestData
    response: ResponseData

 

SessionData

class SessionData(BaseModel):
    """
    request session data, including request, response, validators and stat data
    """

    success: bool = False
    # in most cases, req_resps only contains one request & response
    # while when 30X redirect occurs, req_resps will contain multiple request & response
    req_resps: List[ReqRespData] = []
    stat: RequestStat = RequestStat()
    address: AddressData = AddressData()
    validators: Dict = {}

 

StepData

class StepData(BaseModel):
    """
    teststep data, each step maybe corresponding to one request or one testcase
    测试步骤数据,每个步骤可能对应一个请求或一个测试用例
    """

    success: bool = False
    name: Text = ""  # teststep name
    data: Union[SessionData, List['StepData']] = None
    export_vars: VariablesMapping = {}

 

TestCaseSummary

class TestCaseSummary(BaseModel):
    """
    测试用例结果

    name:测试用例名字
    success:测试用例成功的状态
    case_id:测试用例的id
    time:测试用例的时间
    in_out:测试用例的导入导出数据
    log:测试用例的日志
    step_datas:测试步骤的数据
    """
    name: Text
    success: bool
    case_id: Text
    time: TestCaseTime
    in_out: TestCaseInOut = {}
    log: Text = ""
    step_datas: List[StepData] = []

 

PlatformInfo

class PlatformInfo(BaseModel):
    """
    平台信息

    httprunner_version:httprunner版本号
    python_version:python版本
    platform:平台
    """
    httprunner_version: Text
    python_version: Text
    platform: Text

 

TestCaseRef

class TestCaseRef(BaseModel):
    """
    包含testcase
    """
    name: Text
    base_url: Text = ""
    testcase: Text
    variables: VariablesMapping = {}

 

TestSuite

class TestSuite(BaseModel):
    """
    测试套件
    TestSuite包含TestCaseRef
    TestCaseRef包含testcase
    """
    config: TConfig
    testcases: List[TestCaseRef]

 

Stat

class Stat(BaseModel):
    """
    统计信息

    total:总数
    success:成功的用例数
    fail:失败的用例数
    """
    total: int = 0
    success: int = 0
    fail: int = 0

 

TestSuiteSummary

class TestSuiteSummary(BaseModel):
    """
    测试套件结果

    success:成功的状态
    stat:统计信息
    time:测试用例花费的时间
    platform:平台信息
    testcases:测试用例集
    """
    success: bool = False
    stat: Stat = Stat()
    time: TestCaseTime = TestCaseTime()
    platform: PlatformInfo
    testcases: List[TestCaseSummary]
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。

发布者:全栈程序员-用户IM,转载请注明出处:https://javaforall.cn/165702.html原文链接:https://javaforall.cn

【正版授权,激活自己账号】: Jetbrains全家桶Ide使用,1年售后保障,每天仅需1毛

【官方授权 正版激活】: 官方授权 正版激活 支持Jetbrains家族下所有IDE 使用个人JB账号...

(0)
blank

相关推荐

  • SORT 多目标跟踪算法笔记[通俗易懂]

    SORT 多目标跟踪算法笔记[通俗易懂]sort是一种简单的在线实时多目标跟踪算法。文章要点为:以IoU作为前后帧间目标关系度量指标;利用卡尔曼滤波器预测当前位置;通过匈牙利算法关联检测框到目标;应用试探期甄别虚检;使用FasterR-CNN,证明检测好跟踪可以很简单。技术方案所提方法以检测作为关键组件,传播目标状态到未来帧中,将当前检测与现有目标相关联,并管理跟踪目标的生命周期。Detection为从…

    2022年10月23日
  • circle button键在哪_android按钮

    circle button键在哪_android按钮ucguibuttonbutton上面显示汉字BUTTON_HandlehButton;hButton=BUTTON_CreateEx(0,176-40,176,40,pMsg->hWin,WM_CF_SHOW|WM_CF_HASTRANS,0,GUI_ID_BUTTON_CONFIRM);//BUTTON_SetSkin(hButton,…

  • Java中的增强型for循环「建议收藏」

    Java中的增强型for循环「建议收藏」增强型for循环定义如下:for(ElementTypeelement:arrayName){};上述for循环可被读为:foreachelementinarrayNamedo{…}——————————————————————————————-…

  • 《算法和数据结构》从语言到算法的过渡篇缩写_对数据结构和算法的理解

    《算法和数据结构》从语言到算法的过渡篇缩写_对数据结构和算法的理解《算法和数据结构》学习路线总纲

  • r软件的下载与安装_R语言怎么安装

    r软件的下载与安装_R语言怎么安装一、R软件下载下载地址:https://cran.r-project.org/图1R软件下载页面下载之后是.exe执行文件,不是zip压缩格式文件,可以直接点击安装。二、R软件安装过程一直向下执行,直到安装完毕。最后一步是设置系统环境变量:三、Rstudio下载及安装过程下载地址:https://www.rstudio.com/products/rstudio/downl…

  • 剑指offer答案_一年级聪明格题目

    剑指offer答案_一年级聪明格题目本文为《剑指Offer》刷题笔记的总结篇,花了两个多月的时间,将牛客网上《剑指Offer》的66道题刷了一遍,以博客的形式整理了一遍,这66道题属于相对基础的算法题目,对于刷题练手是很好的实践,接下来

发表回复

您的电子邮箱地址不会被公开。

关注全栈程序员社区公众号