Provides helper functions to help converting behave tables into pandas dataframes and vice versa.
Project description
behave-pandas
Utility package for the Behave BDD testing framework, to make converting gherkin tables to and from pandas data frames a breeze.
Build Status
Installation
pip install behave-pandas
Features
- Easily convert a Gherkin table into a pandas data frame with explicit dtype information
- Easily convert a pandas data frame into a behave table that can be parsed by behave-pandas
- Support converting data frames with multiple index levels either on columns or rows
- Handle missing data for dtypes that support it.
API
The behave-pandas api is extremely simple, and consists in two functions:
from behave_pandas import table_to_dataframe, dataframe_to_table
Example
Feature: Table printer
as a tester
I want to be able to create gherkin tables from existing data frames
Scenario: simple index
Given a gherkin table as input
| str | float | str |
| index_col | float_col | str_col |
| egg | 3.0 | silly walks |
| spam | 4.1 | spanish inquisition |
| bacon | 5.2 | dead parrot |
When converted to a data frame using 1 row as column names and 1 column as index
And printed using data_frame_to_table
Then it prints a valid string copy pasteable into gherkin files
"""
| object | float64 | object |
| index_col | float_col | str_col |
| egg | 3.0 | silly walks |
| spam | 4.1 | spanish inquisition |
| bacon | 5.2 | dead parrot |
"""
Associated steps:
from behave import *
from behave_pandas import table_to_dataframe, dataframe_to_table
use_step_matcher("parse")
@when('converted to a data frame using {column_levels:d} row as column names and {index_levels:d} column as index')
def step_impl(context, column_levels, index_levels):
context.parsed = table_to_dataframe(context.input, column_levels=column_levels, index_levels=index_levels)
@then("it prints a valid string copy pasteable into gherkin files")
def step_impl(context):
assert context.result == context.text
@step("printed using data_frame_to_table")
def step_impl(context):
context.result = dataframe_to_table(context.parsed)
Parsed dataframe:
>>> context.parsed
float_col str_col
index_col
egg 3.0 silly walks
spam 4.1 spanish inquisition
bacon 5.2 dead parrot
>>> context.parsed.info()
<class 'pandas.core.frame.DataFrame'>
Index: 3 entries, egg to bacon
Data columns (total 2 columns):
float_col 3 non-null float64
str_col 3 non-null object
dtypes: float64(1), object(1)
memory usage: 72.0+ bytes
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
No source distribution files available for this release.See tutorial on generating distribution archives.
Built Distribution
Close
Hashes for behave_pandas-0.3.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | edd7d43a512d342d9e945a444514fb4b6a57ac2913f3b8653a57eee27529450e |
|
MD5 | 83a755af1b09c157fdc77ad1cb48abdb |
|
BLAKE2b-256 | e584ce70ad9edca2b1beadc6bc2195a758439e0bddaf2cc5ea24e4016a162d48 |