Generating Data Frames for your test

using Pandas stratgies in Hypothesis

Hello I am Cheuk

  • Open-Source contributor


     
  • Organisers of community events


     
  • PSF director and fellow
     
  • Community manager at OpenSSF

Who is familiar with Property based testing?

Property

  • the given is obvious

     
  • works extra well with typing

     
  • edge case automatically be found

Example

  • need to think of what is and what is not
     
  • take extra steps to write examples

     
  • may overlook edge cases

Testing by...

import pytest


@pytest.mark.parametrize("s", ["", "something", "12345"])
def test_decode_inverts_encode(s):
    assert decode(encode(s)) == s

Test by example

from hypothesis import given
from hypothesis.strategies import text


@given(text())
def test_decode_inverts_encode(s):
    assert decode(encode(s)) == s

Test by property

How does Hypothesis do it?

decorators

entry point to modify the test

strategies

generating test data

Core strategies

  • binary
  • booleans
  • characters
  • complex_numbers
  • dates
  • datetimes
  • decimals
  • emails
  • floats
  • fractions
  • from_regex
  • integers
  • ip_addresses
  • none
  • text
  • timedeltas
  • times
  • timezones
  • uuids

Combine / Build your strategies

  • lists
  • dictionaries
  • one_of
  • builds

Do you know the component of a pandas DataFrame?

Pandas strategies

  • series
  • column
  • data_frames

Numpy strategies

  • arrays
  • array_shapes

Generating Data Frames for your test

By Cheuk Ting Ho

Generating Data Frames for your test

  • 229