pytest-ditto plugin for pandas snapshots.
Project description
pytest-ditto-pandas
pytest-ditto
plugin for pandas snapshots.
@ditto Marks
If the default persistence format, pickle
, isn't appropriate different formats can be
specified per test by using ditto
marks - customised pytest
mark decorators.
Usage
pd.DataFrame
import pandas as pd
import ditto
def awesome_fn_to_test(df: pd.DataFrame):
df.loc[:, "a"] *= 2
return df
# The following test uses pandas.DataFrame.to_parquet to write the data snapshot to the
# `.ditto` directory with filename:
# `test_fn_with_parquet_dataframe_snapshot@ab_dataframe.pandas.parquet`.
@ditto.pandas.parquet
def test_fn_with_parquet_dataframe_snapshot(snapshot):
input_data = pd.DataFrame({"a": [1, 2, 3], "b": [4, 5, 9]})
result = awesome_fn_to_test(input_data)
pd.testing.assert_frame_equal(result, snapshot(result, key="ab_dataframe"))
# The following test uses pandas.DataFrame.to_json(orient="table") to write the data
# snapshot to the `.ditto` directory with filename:
# `test_fn_with_json_dataframe_snapshot@ab_dataframe.pandas.json`.
@ditto.pandas.json
def test_fn_with_json_dataframe_snapshot(snapshot):
input_data = pd.DataFrame({"a": [1, 2, 3], "b": [4, 5, 9]})
result = awesome_fn_to_test(input_data)
pd.testing.assert_frame_equal(result, snapshot(result, key="ab_dataframe"))
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 Distribution
Built Distribution
Close
Hashes for pytest_ditto_pandas-0.0.1.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6c3d6d062ac42f99d7dc8663c9ec842f840c86837cc06e47ba03b6e986d133c5 |
|
MD5 | 6bf52921a5aed9de50a2dfc65a14d70b |
|
BLAKE2b-256 | 0572451ded961ce7b3bd1ebda6b36e6f197e1b726277c0fdd4f2aa600f201467 |
Close
Hashes for pytest_ditto_pandas-0.0.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 65bed0703482495a76c44d6f0c531eae61bef01b75d750f021ac027ac259761a |
|
MD5 | a5568f969eb5f33525b4605b03412bc6 |
|
BLAKE2b-256 | df2f3ce02e0d0d8094c4cc45cae316c215aacc27db052a5073f5d712587b7098 |