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.
Changelog
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")
@given("a gherkin table as input")
def step_impl(context,):
context.input = context.table
@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
Metadata
Release files for behave-pandas 0.5.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| behave_pandas-0.5.0-py3-none-any.whl | Python 3 | none | any | Details for behave_pandas-0.5.0-py3-none-any.whl |
Release files / behave_pandas-0.5.0-py3-none-any.whl
| Download URL | behave_pandas-0.5.0-py3-none-any.whl |
|---|---|
| Size | 6.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
ff67906387e778e5f83c430e679d8b0709c53a6093b1ab551dc63e24795b0afb
|
|
BLAKE2b-256 checksum How to use checksums |
7a8148eeaf56a2176590d7ec925cae64505d797c0a0086411f7ab7d4b161e1b8
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.11.0
|
Security for behave-pandas 0.5.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.