diet-guard/diet_guard/tests/test_cli_future_ate.py
Krzysztof kuhy Rudnicki 4b1de83e27
Some checks are pending
dependency freshness / dependencies on newest stable (push) Waiting to run
file-length / file length <= 250 lines (push) Waiting to run
md-naming / markdown naming convention (push) Waiting to run
pre-commit / pre-commit (${{ matrix.group }}) (mypy, mypy, ) (push) Waiting to run
pre-commit / pre-commit (${{ matrix.group }}) (pylint, pylint, ) (push) Waiting to run
pre-commit / pre-commit (${{ matrix.group }}) (rest, , mypy,pylint) (push) Waiting to run
Tests / test (push) Waiting to run
release-apk / release (APK) (push) Waiting to run
Pre-log meals for a future date and slot (CLI --date/--hour, app 'Log for later')
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-09-27 19:59:38 +02:00

60 lines
2.3 KiB
Python

"""Tests for ``diet_guard ate --date/--hour`` — pre-logging a future meal.
Split out of test_cli.py's ``TestAte`` for the repo's 250-line cap.
"""
from __future__ import annotations
from datetime import timedelta
from typing import TYPE_CHECKING
from unittest.mock import patch
from diet_guard import _cli_log
from diet_guard._budget import write_budget
from diet_guard._cli import main
from diet_guard._estimator import Nutrition
from diet_guard._state import load_log, now_local
if TYPE_CHECKING:
import pytest
_NUT = Nutrition(250, 12, 30, 10, 200, "manual")
class TestAteFutureDate:
"""Logging a meal against a future ``--date``/``--hour`` from the CLI."""
def test_future_date_and_hour_logs_under_that_date(
self, capsys: pytest.CaptureFixture[str]
) -> None:
"""--date/--hour together pre-log against a future slot."""
write_budget(2000)
tomorrow = (now_local() + timedelta(days=1)).date().isoformat()
with patch.object(_cli_log, "resolve_nutrition", return_value=_NUT):
assert (
main(["ate", "future lunch", "--date", tomorrow, "--hour", "12"]) == 0
)
out = capsys.readouterr().out
assert "logged:" in out
assert tomorrow in out
assert load_log()[tomorrow][0]["slot"] == 12
def test_date_without_hour_errors(self, capsys: pytest.CaptureFixture[str]) -> None:
"""A lone --date without --hour is rejected before resolving food."""
assert main(["ate", "x", "--date", "2099-01-01"]) == 1
assert "must be given together" in capsys.readouterr().out
def test_invalid_future_hour_errors(
self, capsys: pytest.CaptureFixture[str]
) -> None:
"""An hour that isn't a configured slot is rejected."""
tomorrow = (now_local() + timedelta(days=1)).date().isoformat()
assert main(["ate", "x", "--date", tomorrow, "--hour", "13"]) == 1
assert "not a meal slot" in capsys.readouterr().out
def test_past_date_errors(self, capsys: pytest.CaptureFixture[str]) -> None:
"""A non-future date is rejected."""
yesterday = (now_local() - timedelta(days=1)).date().isoformat()
assert main(["ate", "x", "--date", yesterday, "--hour", "12"]) == 1
assert "not a future date" in capsys.readouterr().out