• BDD中数据的类型及处理方法(python)


    BDD中提供了两种数据类型,table和text,以下是数据的文档介绍,最后有我的两个小例子。

    1、class behave.model.Table(headings, line=None, rows=None)

    A table extracted from a feature file.

    Table instance data is accessible using a number of methods:

    iteration

    Iterating over the Table will yield the Row instances from the .rows attribute.

    indexed access

    Individual rows may be accessed directly by index on the Table instance; table[0] gives the first non-heading row and table[-1] gives the last row.

    The attributes are:

    headings

    The headings of the table as a list of strings.

    rows

    An list of instances of Row that make up the body of the table in the feature file.

    Tables are also comparable, for what that’s worth. Headings and row data are compared.

    2、class behave.model.Row(headings, cells, line=None, comments=None)

    One row of a table parsed from a feature file.

    Row data is accessible using a number of methods:

    iteration

    Iterating over the Row will yield the individual cells as strings.

    named access

    Individual cells may be accessed by heading name; row[‘name’] would give the cell value for the column with heading “name”.

    indexed access

    Individual cells may be accessed directly by index on the Row instance; row[0] gives the first cell and row[-1] gives the last cell.

    The attributes are:

    cells

    The list of strings that form the cells of this row.

    headings

    The headings of the table as a list of strings.

    Rows are also comparable, for what that’s worth. Only the cells are compared.

    And Text may be associated with Steps:

    3、class behave.model.Text

    Store multiline text from a Step definition.

    The attributes are:

    value

    The actual text parsed from the feature file.

    content_type

    Currently only ‘text/plain’.

    例子:

    1、table

    json_data = []

    for row in context.table:

             adict = {}

             if hasattr(row, 'name'):

                      adict['name'] = row['name']

             json_data.append(adict)

    2、text

    expected_datas = json.loads(context.text)

  • 相关阅读:
    DVWA--SQL Injection(SQL注入)
    DVWA--Insecure CAPTCHA(不安全的验证码)
    DVWA--File Upload(文件上传)+中国菜刀下载及使用
    DWVA--File Inclusion(文件包含)
    DVWA--CSRF(跨站请求伪造)
    DVWA--Command Injection(命令行注入)
    2020.08.06【省选B组】模拟 总结
    2020.08.05【省选B组】模拟 总结
    2020.08.04【省选B组】模拟 总结
    jzoj 5251. 【GDOI2018模拟8.11】决战
  • 原文地址:https://www.cnblogs.com/tangdouguard/p/4913625.html
Copyright © 2020-2023  润新知