Phase 1 \u2014 \ubbf8\ub9ac \uc5f0\ucc28 \ub4f1\ub85d
- DB: get_leave_minutes_for(date) / has_full_day_leave(date) /
get_leave_records_by_date(date) / get_leave_records_by_range(start, end)
- TimeCalculator.effective_work_minutes(date_obj, db): \uc5f0\ucc28 \ubd84\ub9cc\ud07c \uc815\uaddc \uadfc\ubb34 \ucc28\uac10
- update_display() 1Hz hot-path:
\u2022 \uc885\uc77c \uc5f0\ucc28 \ub4f1\ub85d\uc77c + \ucd9c\uadfc \uc548 \ud55c \uc0c1\ud0dc \u2192 "\ud83c\udf34 \uc624\ub298\uc740 \ud734\uac00" \uce74\ub4dc \ud45c\uc2dc, \uce74\uc6b4\ud2b8\ub2e4\uc6b4 \uc81c\uac70
\u2022 \uc885\uc77c \uc5f0\ucc28 + \ucd9c\uadfc override \u2192 \ud734\uc77c\ucc98\ub7fc \uc804\uccb4 \uc801\ub9bd
\u2022 \ubd80\ubd84 \uc5f0\ucc28(\ubc18\ucc28/\uc2dc\uac04) \u2192 leave_used_today \uacbd\ub85c\ub85c \uae30\uc874 \ub2e8\ucd95 \uacc4\uc0b0 \uc720\uc9c0
- \uc790\ub3d9 \ucd9c\uadfc\uac10\uc9c0 \uac00\ub4dc: load_today_data\uc5d0\uc11c \uc885\uc77c \uc5f0\ucc28\uc77c\uc774\uba74 event_monitor \ud638\ucd9c \uc790\uccb4 \uc2a4\ud0b5
- \uc218\ub3d9 \ucd9c\uadfc \uac00\ub4dc: manual_clock_in\uc5d0\uc11c \uc885\uc77c \uc5f0\ucc28\uc77c \ud655\uc778 \ud504\ub86c\ud504\ud2b8
- AddLeaveDialog \uac80\uc99d \uac15\ud654:
\u2022 \ubbf8\ub798 1\ub144\uae4c\uc9c0 setMaximumDate
\u2022 \uc8fc\ub9d0/\uacf5\ud734\uc77c \ub4f1\ub85d \ucc28\ub2e8 (\uc774\ubbf8 \ube44\uadfc\ubb34\uc77c)
\u2022 \uac19\uc740 \ub0a0 1\uc77c \ucd08\uacfc \ub204\uc801 \ucc28\ub2e8
- leave_calendar_view: \uc608\uc815(\ud30c\ub791) / \uc0ac\uc6a9\uc644\ub8cc(\ub179/\ub178/\ubcf4) \uc0c9\uc0c1 \ubd84\ub9ac
Phase 2 \u2014 \ud1b5\ud569 \uc2a4\ucf00\uc904 + \ubc18\ubcf5 \uc5f0\ucc28
- recurring_leaves \ud14c\uc774\ube14 (pattern/leave_type/days/start/end/memo)
- core/recurring_leaves.py: weekly / biweekly / monthly \ud328\ud134 \ud30c\uc11c + expand_for_range/date
- get_leave_minutes_for() / has_full_day_leave()\uac00 \ubc18\ubcf5 \ud328\ud134\ub3c4 \ud568\uaed8 \ud569\uc0b0
- ui/recurring_leave_dialog.py: \ub9e4\uc8fc/\uaca9\uc8fc/\ub9e4\uc6d4 \uc785\ub825 + \uc785\ub825 \ub9ac\uc2a4\ud2b8 \uad00\ub9ac
- ui/schedule_view.py: \uc6d4\uac04 \uc2a4\ud50c\ub9ac\ud130 \ub808\uc774\uc544\uc6c3 (\uce98\ub9b0\ub354 + \uc0c1\uc138)
\u2022 \ud734\uc77c(\ube68\uac15) / \uc5f0\ucc28 \uc0ac\uc6a9(\ub179\u30fb\ub178\u30fb\ubcf4) / \uc608\uc815(\ud30c\ub791) / \ubc18\ubcf5(\ud68c\uc0c9) \uc0c9 \ucf54\ub4dc
\u2022 \ub0a0\uc9dc \ud074\ub9ad \u2192 \uc0c1\uc138 \ud328\ub110 (\ub3d9\uc77c\uc77c\uc790 \uad6c\uccb4 \uc5f0\ucc28 + \ubc18\ubcf5 \ub9e4\uce58)
\u2022 \ub9ac\uc2a4\ud2b8 \uc6b0\ud074\ub9ad \uc0ad\uc81c (\uad6c\uccb4 / \ubc18\ubcf5 \uad6c\ubd84)
\u2022 \uc6d4 \ubcc0\uacbd \uc2dc \uc790\ub3d9 reload
- \uc9c4\uc785\uc810: main_window.show_schedule(), tray menu '\ud83d\uddd3\ufe0f \uc2a4\ucf00\uc904', LeaveView '\ud83d\uddd3\ufe0f \uc2a4\ucf00\uc904' \ubc84\ud2bc
Tests
- tests/test_recurring_leaves.py 32\uac1c (\ud328\ud134 \ud30c\uc2f1 / \ub9e4\uce6d / expand / describe)
- tests/test_database.py +12 (TestLeaveQueriesByDate + TestRecurringLeavesDB)
- _integration_test.py +4 (S52B-S52E)
- pytest: 122 \u2192 175 \uc804\ubd80 green
- \ud1b5\ud569: 49 \u2192 53 \uc804\ubd80 green
- UI-5/UI-7 \uae30\uc874 \uace0\uc7a5 (v2.8.0 \ub514\uc790\uc778 \ub9ac\ub274\uc5bc \ub9c8\ub108)
154 lines
5.4 KiB
Python
154 lines
5.4 KiB
Python
"""
|
|
core.recurring_leaves 단위 테스트.
|
|
"""
|
|
import os
|
|
import sys
|
|
from datetime import date
|
|
|
|
import pytest
|
|
|
|
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
|
|
|
from core.recurring_leaves import (
|
|
matches, expand_for_range, expand_for_date, describe_pattern, _parse_pattern,
|
|
)
|
|
|
|
|
|
class TestParsePattern:
|
|
@pytest.mark.parametrize("pattern,expected_kind", [
|
|
('weekly:friday', 'weekly'),
|
|
('weekly:fri', 'weekly'),
|
|
('weekly:mon,wed,fri', 'weekly'),
|
|
('biweekly:friday', 'biweekly'),
|
|
('monthly:15', 'monthly'),
|
|
('monthly:1', 'monthly'),
|
|
])
|
|
def test_valid(self, pattern, expected_kind):
|
|
result = _parse_pattern(pattern)
|
|
assert result is not None
|
|
assert result[0] == expected_kind
|
|
|
|
@pytest.mark.parametrize("pattern", [
|
|
'', 'weekly', 'weekly:', 'weekly:xyz',
|
|
'monthly:0', 'monthly:32', 'monthly:abc',
|
|
'unknown:fri', None,
|
|
])
|
|
def test_invalid(self, pattern):
|
|
assert _parse_pattern(pattern) is None
|
|
|
|
|
|
class TestMatches:
|
|
def _rec(self, pattern, start='2026-01-01', end=None, days=0.5, leave_type='반차'):
|
|
return {
|
|
'pattern': pattern,
|
|
'start_date': start,
|
|
'end_date': end,
|
|
'days': days,
|
|
'leave_type': leave_type,
|
|
}
|
|
|
|
def test_weekly_single_day(self):
|
|
rec = self._rec('weekly:friday')
|
|
assert matches(rec, date(2026, 5, 1)) # Fri
|
|
assert not matches(rec, date(2026, 5, 2)) # Sat
|
|
assert not matches(rec, date(2026, 5, 4)) # Mon
|
|
|
|
def test_weekly_multiple_days(self):
|
|
rec = self._rec('weekly:mon,wed,fri')
|
|
assert matches(rec, date(2026, 5, 4)) # Mon
|
|
assert matches(rec, date(2026, 5, 6)) # Wed
|
|
assert matches(rec, date(2026, 5, 8)) # Fri
|
|
assert not matches(rec, date(2026, 5, 5)) # Tue
|
|
assert not matches(rec, date(2026, 5, 7)) # Thu
|
|
|
|
def test_biweekly_alignment(self):
|
|
# start_date 2026-01-02 = Friday (week 0)
|
|
rec = self._rec('biweekly:friday', start='2026-01-02')
|
|
assert matches(rec, date(2026, 1, 2)) # week 0
|
|
assert not matches(rec, date(2026, 1, 9)) # week 1
|
|
assert matches(rec, date(2026, 1, 16)) # week 2
|
|
|
|
def test_monthly(self):
|
|
rec = self._rec('monthly:15')
|
|
assert matches(rec, date(2026, 1, 15))
|
|
assert matches(rec, date(2026, 5, 15))
|
|
assert not matches(rec, date(2026, 5, 14))
|
|
assert not matches(rec, date(2026, 5, 16))
|
|
|
|
def test_monthly_skipped_in_short_month(self):
|
|
# 31일은 30일 달에는 매치되지 않음
|
|
rec = self._rec('monthly:31')
|
|
assert matches(rec, date(2026, 1, 31))
|
|
assert not matches(rec, date(2026, 4, 30)) # 4월 31일 없음
|
|
|
|
def test_before_start(self):
|
|
rec = self._rec('weekly:friday', start='2026-05-01')
|
|
assert matches(rec, date(2026, 5, 1))
|
|
assert not matches(rec, date(2026, 4, 24)) # 시작 전
|
|
|
|
def test_after_end(self):
|
|
rec = self._rec('weekly:friday', start='2026-01-01', end='2026-04-30')
|
|
assert matches(rec, date(2026, 4, 24)) # 종료일 이전 금요일
|
|
assert not matches(rec, date(2026, 5, 1)) # 종료일 이후
|
|
|
|
def test_no_end_means_forever(self):
|
|
rec = self._rec('weekly:friday', start='2026-01-01', end=None)
|
|
assert matches(rec, date(2030, 1, 4)) # 4년 후 금요일
|
|
|
|
def test_invalid_pattern_returns_false(self):
|
|
rec = self._rec('garbage:xyz')
|
|
assert not matches(rec, date(2026, 5, 1))
|
|
|
|
|
|
class TestExpandRange:
|
|
def _rec(self, pattern, start='2026-01-01'):
|
|
return {
|
|
'id': 1, 'pattern': pattern, 'start_date': start, 'end_date': None,
|
|
'days': 0.5, 'leave_type': '반차', 'memo': '',
|
|
}
|
|
|
|
def test_expand_weekly_one_month(self):
|
|
rec = self._rec('weekly:friday')
|
|
occs = expand_for_range([rec], date(2026, 5, 1), date(2026, 5, 31))
|
|
# 5월 금요일: 1, 8, 15, 22, 29 = 5회
|
|
assert len(occs) == 5
|
|
assert all(o.date.weekday() == 4 for o in occs)
|
|
|
|
def test_expand_empty_when_outside(self):
|
|
rec = self._rec('weekly:friday', start='2027-01-01')
|
|
occs = expand_for_range([rec], date(2026, 5, 1), date(2026, 5, 31))
|
|
assert occs == []
|
|
|
|
def test_expand_invalid_range(self):
|
|
# start > end
|
|
rec = self._rec('weekly:friday')
|
|
occs = expand_for_range([rec], date(2026, 5, 31), date(2026, 5, 1))
|
|
assert occs == []
|
|
|
|
def test_expand_multiple_recs(self):
|
|
rec_fri = self._rec('weekly:friday')
|
|
rec_mon = self._rec('weekly:monday')
|
|
rec_mon['id'] = 2
|
|
occs = expand_for_range([rec_fri, rec_mon], date(2026, 5, 1), date(2026, 5, 7))
|
|
# 5/1=Fri (rec_fri), 5/4=Mon (rec_mon)
|
|
assert len(occs) == 2
|
|
|
|
def test_expand_for_date_single(self):
|
|
rec = self._rec('monthly:15')
|
|
occs = expand_for_date([rec], date(2026, 5, 15))
|
|
assert len(occs) == 1
|
|
assert occs[0].date == date(2026, 5, 15)
|
|
|
|
|
|
class TestDescribePattern:
|
|
def test_weekly_korean(self):
|
|
assert '매주' in describe_pattern('weekly:friday')
|
|
assert '금' in describe_pattern('weekly:friday')
|
|
|
|
def test_biweekly(self):
|
|
assert '격주' in describe_pattern('biweekly:friday')
|
|
|
|
def test_monthly(self):
|
|
assert '매월' in describe_pattern('monthly:15')
|
|
assert '15' in describe_pattern('monthly:15')
|