Package src/speed_calc with the decorator, fast_function, slow_function, constants.py and runnable lecture steps; pytest tests with a fake clock; four screenshots rendered from real output; README lecture steps; review record RC-007. Task: MIL-002#1 Task: MIL-002#2 Task: MIL-002#3 Task: MIL-002#4 Task: MIL-002#5 Task: MIL-002#6 Task: MIL-002#7
37 lines
1.1 KiB
Python
37 lines
1.1 KiB
Python
"""Tests for the lecture steps."""
|
|
|
|
import pytest
|
|
|
|
from speed_calc.lecture_steps import main
|
|
|
|
|
|
def test_step_1_prints_the_current_time(capsys: pytest.CaptureFixture[str]) -> None:
|
|
assert main(["1"]) == 0
|
|
assert float(capsys.readouterr().out) > 0
|
|
|
|
|
|
def test_step_2_announces_the_call_and_keeps_the_name(
|
|
capsys: pytest.CaptureFixture[str],
|
|
) -> None:
|
|
assert main(["2"]) == 0
|
|
lines = capsys.readouterr().out.splitlines()
|
|
assert lines == [
|
|
"calling fast_function",
|
|
"name kept by functools.wraps: fast_function",
|
|
]
|
|
|
|
|
|
def test_step_3_prints_one_timing_line(capsys: pytest.CaptureFixture[str]) -> None:
|
|
assert main(["3"]) == 0
|
|
assert capsys.readouterr().out.startswith("fast_function run speed: ")
|
|
|
|
|
|
def test_step_4_prints_three_lines(capsys: pytest.CaptureFixture[str]) -> None:
|
|
assert main(["4"]) == 0
|
|
assert len(capsys.readouterr().out.splitlines()) == 3
|
|
|
|
|
|
def test_bad_step_number_is_refused(capsys: pytest.CaptureFixture[str]) -> None:
|
|
assert main(["9"]) == 2
|
|
assert "usage" in capsys.readouterr().out
|