Types of data in BDD and how to handle it (python)

Source: Internet
Author: User
Tags comparable

There are two types of data in BDD, table and text, the following is a description of the data, and finally two small examples of me.

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 would yield the Row instances from the. Rows attribute.

Indexed access

Individual rows 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, the body of the table in the feature file.

Tables is also comparable, for what's that ' s worth. Headings and row data is 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 would yield the individual cells as strings.

Named access

Individual cells accessed by heading name; row[' name '] would give the cell value for the column with heading "name".

Indexed access

Individual cells 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 is also comparable, for what is that ' s worth. Only the cells is compared.

And Text May is 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 '.

Example:

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)

Types of data in BDD and how to handle it (python)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.