示例工程 34-pandas-dataframes

34-pandas-dataframes/02-index-alignment/test_index_alignment.py

python · 0.6 KB

"""test_index_alignment.py"""
 
from __future__ import annotations
 
import pandas as pd
import pytest
 
pytest.importorskip("pandas")
 
from index_alignment import aligned_sum, main
 
 
def test_alignment_produces_nan() -> None:
    result = aligned_sum()
    assert list(result.index) == ["a", "b", "c"]
    assert result["b"] == 12
    assert pd.isna(result["a"])
    assert pd.isna(result["c"])
 
 
def test_main_runs(capsys: pytest.CaptureFixture[str]) -> None:
    main()
    out = capsys.readouterr().out
    assert "index: ['a', 'b', 'c']" in out
    assert "'b': 12.0" in out