feat: --commit flag (#44)
- --commit: после генерации отчёта сохраняет период в period.last_used.from/to YAML-конфига - При period.dynamic=true следующий запуск вычисляет период от last_used: полный месяц → следующий месяц, произвольный диапазон → та же длина - При period.dynamic=false перезаписывает default_from/default_to - При period.precision=datetime сохраняет timestamps с точностью до секунд - --commit без --output сохраняет отчёт по шаблону из конфига - compute_next_period() в config.py - save_period_to_config() в yaml_config.py - 23 новых теста (7 CLI, 6 config, 6 yaml, 4 date_range) Closes #44
This commit is contained in:
@@ -451,3 +451,109 @@ class TestConfigPeriodPrecision:
|
||||
cfg = AppConfig.from_yaml(yaml_path)
|
||||
assert cfg.period_last_used_from == ""
|
||||
assert cfg.period_last_used_to == ""
|
||||
|
||||
|
||||
class TestComputeNextPeriod:
|
||||
"""Tests for compute_next_period()."""
|
||||
|
||||
def test_full_month_goes_to_next_full_month(self):
|
||||
from redmine_reporter.config import compute_next_period
|
||||
|
||||
nf, nt = compute_next_period("2026-06-01", "2026-06-30", "date")
|
||||
assert nf == "2026-07-01"
|
||||
assert nt == "2026-07-31"
|
||||
|
||||
def test_december_to_next_year_january(self):
|
||||
from redmine_reporter.config import compute_next_period
|
||||
|
||||
nf, nt = compute_next_period("2025-12-01", "2025-12-31", "date")
|
||||
assert nf == "2026-01-01"
|
||||
assert nt == "2026-01-31"
|
||||
|
||||
def test_february_2026_non_leap_to_march(self):
|
||||
from redmine_reporter.config import compute_next_period
|
||||
|
||||
nf, nt = compute_next_period("2026-02-01", "2026-02-28", "date")
|
||||
assert nf == "2026-03-01"
|
||||
assert nt == "2026-03-31"
|
||||
|
||||
def test_arbitrary_range_same_length_from_to_plus_one(self):
|
||||
from redmine_reporter.config import compute_next_period
|
||||
|
||||
nf, nt = compute_next_period("2026-06-15", "2026-06-20", "date")
|
||||
assert nf == "2026-06-21"
|
||||
assert nt == "2026-06-26"
|
||||
|
||||
def test_single_day_range_moves_one_day(self):
|
||||
from redmine_reporter.config import compute_next_period
|
||||
|
||||
nf, nt = compute_next_period("2026-06-15", "2026-06-15", "date")
|
||||
assert nf == "2026-06-16"
|
||||
assert nt == "2026-06-16"
|
||||
|
||||
def test_cross_month_range(self):
|
||||
from redmine_reporter.config import compute_next_period
|
||||
|
||||
nf, nt = compute_next_period("2026-06-25", "2026-07-05", "date")
|
||||
assert nf == "2026-07-06"
|
||||
assert nt == "2026-07-16"
|
||||
|
||||
def test_datetime_precision_moves_by_seconds(self):
|
||||
from redmine_reporter.config import compute_next_period
|
||||
|
||||
nf, nt = compute_next_period("2026-06-30T09:00:00", "2026-06-30T12:00:00", "datetime")
|
||||
assert nf == "2026-06-30T12:00:01"
|
||||
assert nt == "2026-06-30T15:00:01"
|
||||
|
||||
|
||||
class TestDefaultDateRangeWithLastUsed:
|
||||
"""Tests that get_default_date_range() uses last_used when dynamic=True."""
|
||||
|
||||
@mock.patch.dict(os.environ, {}, clear=True)
|
||||
def test_uses_last_used_when_dynamic_true(self):
|
||||
with tempfile.TemporaryDirectory() as tmp:
|
||||
yaml_path = Path(tmp) / "config.yml"
|
||||
yaml_path.write_text(
|
||||
"period:\n"
|
||||
" precision: date\n"
|
||||
" dynamic: true\n"
|
||||
" last_used:\n"
|
||||
" from: '2026-05-01'\n"
|
||||
" to: '2026-05-31'\n"
|
||||
)
|
||||
Config._app = AppConfig.from_yaml(yaml_path)
|
||||
result = Config.get_default_date_range()
|
||||
assert result == "2026-06-01--2026-06-30"
|
||||
|
||||
@mock.patch.dict(os.environ, {}, clear=True)
|
||||
def test_ignores_last_used_when_dynamic_false(self):
|
||||
with tempfile.TemporaryDirectory() as tmp:
|
||||
yaml_path = Path(tmp) / "config.yml"
|
||||
yaml_path.write_text(
|
||||
"period:\n"
|
||||
" precision: date\n"
|
||||
" dynamic: false\n"
|
||||
" default_from: '2026-03-01'\n"
|
||||
" default_to: '2026-03-15'\n"
|
||||
" last_used:\n"
|
||||
" from: '2026-06-01'\n"
|
||||
" to: '2026-06-30'\n"
|
||||
)
|
||||
Config._app = AppConfig.from_yaml(yaml_path)
|
||||
result = Config.get_default_date_range()
|
||||
assert result == "2026-03-01--2026-03-15"
|
||||
|
||||
@mock.patch.dict(os.environ, {}, clear=True)
|
||||
def test_falls_back_when_no_last_used_even_with_dynamic(self):
|
||||
with tempfile.TemporaryDirectory() as tmp:
|
||||
yaml_path = Path(tmp) / "config.yml"
|
||||
yaml_path.write_text(
|
||||
"period:\n"
|
||||
" precision: date\n"
|
||||
" dynamic: true\n"
|
||||
" default_from: '2026-04-01'\n"
|
||||
" default_to: '2026-04-15'\n"
|
||||
)
|
||||
Config._app = AppConfig.from_yaml(yaml_path)
|
||||
result = Config.get_default_date_range()
|
||||
assert result == "2026-04-01--2026-04-15"
|
||||
|
||||
Reference in New Issue
Block a user