CSV extension for the Hypothesis framework
Project description
==============
hypothesis-csv
==============
:code:`hypothesis-csv` is an extension to the `hypothesis` framework. The goal of this framework is to offer a flexible tool
to perform generative-testing/property-based testing for software that accepts CSV files as an input.
Description
===========
`hypothesis-csv` is designed with two main use cases in mind:
* test software that accepts a wide spectrum of CSV formats and doesn't make assumptions on the content (i.e. CSV parsers)
* test software that accepts very specific CSV formats and makes assumption on the content, types and header fields.
It provides two strategies, :code:`data_rows` and :code:`csv`, to pursue this goal, both contained in the `strategies` module.
Please refer to their documentation and the examples for more details.
Examples
========
Generate arbitrary, non-empty CSV
---------------------------------
.. code-block:: python
:name: Generate arbitrary, non-empty CSV
from hypothesis_csv.strategies import csv
@given(csv=csv())
def test_my_csv_parse(csv):
parsed_csv=my_csv_parser(csv)
assert ...
Generate CSV of a given size (5 columns x 20 rows)
--------------------------------------------------
.. code-block:: python
:name: Generate CSV of a given size (5 columns x 20 rows)
from hypothesis_csv.strategies import csv
@given(csv=csv(lines=20,header=5))
def test_my_csv_parse(csv):
parsed_csv=my_csv_parser(csv)
assert parsed_csv.num_columns == 5
assert parsed_csv.num_rows == 20
Generate CSV with a header
--------------------------
.. code-block:: python
:name: Generate CSV with a header
from hypothesis_csv.strategies import csv
@given(csv=csv(header=["timestamp","val_1","val_2"]))
def test_my_csv_parse(csv):
parsed_csv=my_csv_parser(csv)
assert parsed_csv.num_columns == 3
Generate CSV with columns of a given type
-----------------------------------------
.. code-block:: python
:name: Generate CSV with columns of a given type
from hypothesis_csv.strategies import csv
@given(csv=csv(columns=[text(),int(),float()]))
def test_my_csv_parse(csv):
parsed_csv=my_csv_parser(csv)
assert parsed_csv.num_columns == 3
Generate CSV with a given dialect
---------------------------------
.. code-block:: python
:name: Generate CSV in a given dialect
from hypothesis_csv.strategies import csv
@given(csv=csv(columns=[text(),int(),float()], dialect="excel-tab"))
def test_my_csv_parse(csv):
...
Generate CSV with drawns dialects
---------------------------------
.. code-block:: python
:name: Generate CSV in a given dialect
from hypothesis_csv.strategies import csv
@given(csv=csv(columns=[text(),int(),float()], dialect=None))
def test_my_csv_parse(csv):
...
hypothesis-csv
==============
:code:`hypothesis-csv` is an extension to the `hypothesis` framework. The goal of this framework is to offer a flexible tool
to perform generative-testing/property-based testing for software that accepts CSV files as an input.
Description
===========
`hypothesis-csv` is designed with two main use cases in mind:
* test software that accepts a wide spectrum of CSV formats and doesn't make assumptions on the content (i.e. CSV parsers)
* test software that accepts very specific CSV formats and makes assumption on the content, types and header fields.
It provides two strategies, :code:`data_rows` and :code:`csv`, to pursue this goal, both contained in the `strategies` module.
Please refer to their documentation and the examples for more details.
Examples
========
Generate arbitrary, non-empty CSV
---------------------------------
.. code-block:: python
:name: Generate arbitrary, non-empty CSV
from hypothesis_csv.strategies import csv
@given(csv=csv())
def test_my_csv_parse(csv):
parsed_csv=my_csv_parser(csv)
assert ...
Generate CSV of a given size (5 columns x 20 rows)
--------------------------------------------------
.. code-block:: python
:name: Generate CSV of a given size (5 columns x 20 rows)
from hypothesis_csv.strategies import csv
@given(csv=csv(lines=20,header=5))
def test_my_csv_parse(csv):
parsed_csv=my_csv_parser(csv)
assert parsed_csv.num_columns == 5
assert parsed_csv.num_rows == 20
Generate CSV with a header
--------------------------
.. code-block:: python
:name: Generate CSV with a header
from hypothesis_csv.strategies import csv
@given(csv=csv(header=["timestamp","val_1","val_2"]))
def test_my_csv_parse(csv):
parsed_csv=my_csv_parser(csv)
assert parsed_csv.num_columns == 3
Generate CSV with columns of a given type
-----------------------------------------
.. code-block:: python
:name: Generate CSV with columns of a given type
from hypothesis_csv.strategies import csv
@given(csv=csv(columns=[text(),int(),float()]))
def test_my_csv_parse(csv):
parsed_csv=my_csv_parser(csv)
assert parsed_csv.num_columns == 3
Generate CSV with a given dialect
---------------------------------
.. code-block:: python
:name: Generate CSV in a given dialect
from hypothesis_csv.strategies import csv
@given(csv=csv(columns=[text(),int(),float()], dialect="excel-tab"))
def test_my_csv_parse(csv):
...
Generate CSV with drawns dialects
---------------------------------
.. code-block:: python
:name: Generate CSV in a given dialect
from hypothesis_csv.strategies import csv
@given(csv=csv(columns=[text(),int(),float()], dialect=None))
def test_my_csv_parse(csv):
...
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Close
Hashes for hypothesis-csv-0.3.2.linux-x86_64.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | b99c91ae63835cee92540b246b4624950df20b6d0b8fcab18749089212be16ee |
|
MD5 | bc1c7547c0caf65afedca81a472995f6 |
|
BLAKE2b-256 | 689d96fb9f8b2c59443046afd0e9ae75b6b4ce5c5543a7bf8851ed2f54d84772 |