Some checks failed
CI / test (push) Has been cancelled
핵심 기능: - 단축근무·표준·반일 등 다양한 근무 패턴 (5개 프리셋 + 사용자 정의) - Windows 이벤트 뷰어 자동 출퇴근 감지 - 30분 단위 연장근무 적립/사용 시스템 - 1.0/0.5/0.25일 연차·반차·반반차 - 자동 점심·저녁·외출·자동 백업·화면 잠금 자동 외출 - 한국 공휴일 자동 등록 (음력 포함, holidays 패키지) - matplotlib 차트 기반 주간/월간/패턴 통계 - 미니 위젯 + 시스템 트레이 통합 - 한국어/English i18n - 자가 업데이트 (updater.exe + Gitea Releases) 아키텍처: - core/ (db, time_calculator, notifier, i18n, version, settings_keys) - ui/ (main_window + 9 dialogs + 3 controllers) - utils/ (backup, lock_detector, debug_log, updater_client, time_format) - tests/ (66 pytest 단위) + 통합/i18n GUI 검증 CI/CD: - .gitea/workflows/ci.yml: push 시 pytest + 통합 테스트 - .gitea/workflows/release.yml: v* 태그 push 시 두 .exe 자동 빌드 + Releases 첨부 Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
91 lines
3.0 KiB
Python
91 lines
3.0 KiB
Python
"""
|
|
업데이터 단위 테스트.
|
|
"""
|
|
import os
|
|
import sys
|
|
|
|
import pytest
|
|
|
|
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
|
|
|
from utils.updater_client import _parse_version, is_newer, RELEASES_API
|
|
|
|
|
|
class TestVersionParsing:
|
|
@pytest.mark.parametrize("input_str,expected", [
|
|
('1.0.0', (1, 0, 0)),
|
|
('v1.0.0', (1, 0, 0)),
|
|
('V2.1.3', (2, 1, 3)),
|
|
('1.0', (1, 0, 0)), # 짧은 버전 → 0 패딩
|
|
('2', (2, 0, 0)),
|
|
('1.2.3.4', (1, 2, 3)), # 초과 부분 무시
|
|
('2.0rc1', (2, 0, 0)), # 접미사 제거
|
|
('', (0, 0, 0)),
|
|
])
|
|
def test_parse_version(self, input_str, expected):
|
|
assert _parse_version(input_str) == expected
|
|
|
|
|
|
class TestVersionComparison:
|
|
@pytest.mark.parametrize("remote,local,expected", [
|
|
('2.0.0', '1.0.0', True),
|
|
('1.0.1', '1.0.0', True),
|
|
('v2.1.0', '2.0.5', True),
|
|
('1.0.0', '1.0.0', False), # 동일 버전
|
|
('1.0.0', '2.0.0', False), # 로컬이 더 최신
|
|
('v1.0.0', 'v1.0.0', False),
|
|
])
|
|
def test_is_newer(self, remote, local, expected):
|
|
assert is_newer(remote, local) == expected
|
|
|
|
|
|
class TestApiUrl:
|
|
def test_default_points_to_gitea(self):
|
|
"""기본 URL이 자체 호스팅 Gitea를 가리키는지."""
|
|
assert 'kindnick-git.duckdns.org' in RELEASES_API
|
|
assert '/api/v1/repos/' in RELEASES_API
|
|
assert '/releases/latest' in RELEASES_API
|
|
|
|
def test_env_override(self, monkeypatch):
|
|
"""환경변수로 URL 오버라이드 가능."""
|
|
monkeypatch.setenv('CLOCKOUT_RELEASES_API', 'https://example.com/api/test')
|
|
# 모듈 재로드 필요
|
|
import importlib
|
|
from utils import updater_client
|
|
importlib.reload(updater_client)
|
|
assert updater_client.RELEASES_API == 'https://example.com/api/test'
|
|
# 원복
|
|
monkeypatch.delenv('CLOCKOUT_RELEASES_API', raising=False)
|
|
importlib.reload(updater_client)
|
|
|
|
|
|
class TestUpdaterScript:
|
|
"""updater.py 자체 로직."""
|
|
|
|
def test_is_pid_running_self(self):
|
|
"""현재 프로세스 PID는 running."""
|
|
import updater
|
|
assert updater.is_pid_running(os.getpid())
|
|
|
|
def test_is_pid_running_dead(self):
|
|
"""존재하지 않는 PID는 not running."""
|
|
import updater
|
|
# 절대 사용되지 않을 PID (32비트 max + 1)
|
|
assert not updater.is_pid_running(99999999)
|
|
|
|
def test_replace_file_round_trip(self, tmp_path):
|
|
"""파일 교체 + 백업 생성 검증."""
|
|
import updater
|
|
target = tmp_path / "main.exe"
|
|
new = tmp_path / "main_new.exe"
|
|
target.write_bytes(b'OLD VERSION')
|
|
new.write_bytes(b'NEW VERSION')
|
|
|
|
backup = updater.replace_file(new, target)
|
|
assert backup is not None
|
|
assert backup.exists()
|
|
assert backup.read_bytes() == b'OLD VERSION'
|
|
assert target.exists()
|
|
assert target.read_bytes() == b'NEW VERSION'
|
|
assert not new.exists() # 이동되었으므로 사라짐
|