示例工程 24-profiling-performance
24-profiling-performance/02-profile-hotspot/test_profile_hotspot.py
"""test_profile_hotspot.py"""
from __future__ import annotations
import pytest
from profile_hotspot import find_duplicates, main, profile_text
def test_duplicates_count() -> None:
values = list(range(2000)) + list(range(500))
assert len(find_duplicates(values)) == 500
def test_profile_points_to_list_index() -> None:
text = profile_text(list(range(1000)) + list(range(200)))
assert "index" in text
assert "find_duplicates" in text
def test_main_runs(capsys: pytest.CaptureFixture[str]) -> None:
main()
out = capsys.readouterr().out
assert "duplicates: 500" in out
assert "tottime" in out