跳转到主要内容

inline-snapshot的内联集成(仅限内部人员使用)

项目描述

ci Docs pypi version Python Versions PyPI - Downloads coverage GitHub Sponsors

安装

此项目目前仅限于内部人员使用,这意味着如果您赞助我,您将能够访问它。然后您应该能够访问此存储库

pip install git+ssh://git@github.com:15r10nk-insiders/inline-snapshot-pandas.git@insiders

使用

此软件包提供特殊的assert_(frame|series|index)_equal实现,接受快照作为第二个参数。

from pandas import DataFrame
from inline_snapshot_pandas import assert_frame_equal
from inline_snapshot import snapshot


def test_assert_equal():
    df = DataFrame({"col0": [1, 2]})

    assert_frame_equal(df, snapshot())
pytest --inline-snapshot=create
from pandas import DataFrame
from inline_snapshot_pandas import assert_frame_equal
from inline_snapshot import snapshot


def test_assert_equal():
    df = DataFrame({"col0": [1, 2]})

    assert_frame_equal(
        df,
        snapshot(DataFrame([{"col0": 1}, {"col0": 2}])),
    )

另一种使用方法是调用conftest.py中的setup(),它替换了pandas使用的实现。

from inline_snapshot_pandas import setup

setup()

然后您可以使用具有快照的pandas实现。

from pandas import DataFrame
from pandas.testing import assert_frame_equal
from inline_snapshot import snapshot


def test_assert_equal():
    df = DataFrame({"col0": [1, 2], "col1": [1, 5j], "col3": ["a", "b"]})

    # the second argument can be a snapshot
    assert_frame_equal(
        df,
        snapshot(
            DataFrame(
                [
                    {"col0": 1, "col1": (1 + 0j), "col3": "a"},
                    {"col0": 2, "col1": 5j, "col3": "b"},
                ]
            )
        ),
    )

非内部人员使用方法

目前可在pip上提供的版本提供了非内部人员可以使用的功能。它们提供了一个特殊的snapshot函数,其实现为lambda value: value,可用于pandas的正常assert_*_equal函数。

以下代码可以与内部人员和非内部人员版本一起执行

from pandas import DataFrame
from inline_snapshot_pandas import assert_frame_equal

# importing snapshot from inline_snapshot_pandas is important
from inline_snapshot_pandas import snapshot


def test_assert_equal():
    df = DataFrame({"col0": [1, 2]})

    assert_frame_equal(
        df,
        snapshot(DataFrame([{"col0": 1}, {"col0": 2}])),
    )

问题

如果您遇到任何问题,请报告问题,并提供详细描述。

许可证

根据MIT许可证发布,“inline-snapshot-pandas”是免费且开源的软件。

项目详情


下载文件

下载适用于您平台的文件。如果您不确定选择哪个,请了解更多关于 安装包 的信息。

源代码分发

inline_snapshot_pandas-0.1.1.tar.gz (29.8 kB 查看哈希值)

上传时间 源代码

构建分发

inline_snapshot_pandas-0.1.1-py3-none-any.whl (2.9 kB 查看哈希值)

上传时间 Python 3

支持者

AWS AWS 云计算和安全赞助商 Datadog Datadog 监控 Fastly Fastly CDN Google Google 下载分析 Microsoft Microsoft PSF 赞助商 Pingdom Pingdom 监控 Sentry Sentry 错误日志 StatusPage StatusPage 状态页面