inline-snapshot的内联集成(仅限内部人员使用)
项目描述
安装
此项目目前仅限于内部人员使用,这意味着如果您赞助我,您将能够访问它。然后您应该能够访问此存储库。
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 查看哈希值)
构建分发
关闭
哈希值 for inline_snapshot_pandas-0.1.1-py3-none-any.whl
算法 | 哈希摘要 | |
---|---|---|
SHA256 | f87180bd73803191cef59a1b6265527c973d36f68ea041389db0566c0c0f2a36 |
|
MD5 | 4f2f0118921e8a5764a327ab6995cb6d |
|
BLAKE2b-256 | 2c367196c229b105c865916f2be72c55c5998fb70854aa76d480486a6a15640b |