Files
fgtools/TEST_MODULES.md

5.0 KiB

모듈 테스트 실행 빠른 가이드

프로젝트의 모든 모듈을 개별적으로 테스트 실행할 수 있습니다.

빠른 시작

1. 환경 설정

cd c:\DEV\python\fgtools
$env:PYTHONPATH='c:\DEV\python\fgtools'
.\venv\Scripts\Activate.ps1

2. 모든 모듈 테스트 실행 스크립트

# 스크립트 저장: test_all_modules.ps1
$modules = @(
    "services/weather/asos.py",
    "services/weather/forecast.py",
    "services/weather/precipitation.py",
    "services/analytics/air_quality.py",
    "services/analytics/ga4.py",
    "services/analytics/visitor_forecast.py",
    "services/notification/mattermost.py",
    "services/notification/notion.py",
    "apps/dashboard/app.py",
    "apps/weather_api/app.py",
    "apps/webhook/app.py"
)

$env:PYTHONPATH='c:\DEV\python\fgtools'
$failed = @()

foreach ($module in $modules) {
    Write-Host "`n========================================" -ForegroundColor Cyan
    Write-Host "테스트: $module" -ForegroundColor Cyan
    Write-Host "========================================" -ForegroundColor Cyan
    
    $output = & python $module 2>&1
    if ($LASTEXITCODE -eq 0) {
        Write-Host "✓ 성공" -ForegroundColor Green
    } else {
        Write-Host "✗ 실패" -ForegroundColor Red
        $failed += $module
    }
    Write-Host $output
}

Write-Host "`n========================================" -ForegroundColor Cyan
Write-Host "테스트 완료 요약" -ForegroundColor Cyan
Write-Host "========================================" -ForegroundColor Cyan

if ($failed.Count -eq 0) {
    Write-Host "모든 모듈 테스트 성공! ✓" -ForegroundColor Green
} else {
    Write-Host "실패한 모듈:" -ForegroundColor Red
    $failed | ForEach-Object { Write-Host "  - $_" -ForegroundColor Red }
}

개별 모듈 테스트

Weather (기상청) 서비스

ASOS 모듈

python services/weather/asos.py
# 기능: 종관기상 데이터 조회, DB 저장

Forecast 모듈

python services/weather/forecast.py
# 기능: 초단기/단기/중기 예보 조회

Precipitation 모듈

python services/weather/precipitation.py
# 기능: 강수량 데이터 조회, HTML 생성

Analytics (분석) 서비스

Air Quality 모듈

python services/analytics/air_quality.py
# 기능: 대기질 데이터 수집 (PM2.5, PM10 등)

GA4 모듈

python services/analytics/ga4.py
# 기능: GA4 분석 데이터 수집

Visitor Forecast 모듈

python services/analytics/visitor_forecast.py
# 기능: 방문객 수 예측

Notification (알림) 서비스

Mattermost 모듈

python services/notification/mattermost.py
# 기능: Mattermost 메시지 발송

Notion 모듈

python services/notification/notion.py
# 기능: Notion 웹훅 처리

Flask 애플리케이션

Dashboard

python apps/dashboard/app.py
# 포트: 5000
# URL: http://localhost:5000/api/dashboard

Weather API

python apps/weather_api/app.py
# 포트: 5001
# URL: http://localhost:5001/api/weather

Webhook

python apps/webhook/app.py
# 포트: 5002
# URL: http://localhost:5002/webhook

통합 애플리케이션 실행

Docker Compose

docker compose up -d
# 모든 애플리케이션 실행

개별 터미널 실행

# 터미널 1
python apps/dashboard/app.py

# 터미널 2
python apps/weather_api/app.py

# 터미널 3
python apps/webhook/app.py

구조도

fgtools/
├── services/
│   ├── weather/
│   │   ├── asos.py ✓
│   │   ├── forecast.py ✓
│   │   └── precipitation.py ✓
│   ├── analytics/
│   │   ├── air_quality.py ✓
│   │   ├── ga4.py ✓
│   │   └── visitor_forecast.py ✓
│   └── notification/
│       ├── mattermost.py ✓
│       └── notion.py ✓
├── apps/
│   ├── dashboard/
│   │   └── app.py ✓
│   ├── weather_api/
│   │   └── app.py ✓
│   └── webhook/
│       └── app.py ✓
└── core/
    ├── config.py
    ├── database.py
    ├── logging_utils.py
    └── ...

✓ = 개별 실행 가능

로깅 및 디버깅

디버그 레벨 로깅

$env:LOG_LEVEL='DEBUG'
python services/weather/asos.py

로그 파일 확인

Get-Content logs/app.log -Tail 50

트러블슈팅

Python 경로 오류

$env:PYTHONPATH='c:\DEV\python\fgtools'

모듈 import 오류

python -c "import sys; print(sys.path)"

데이터베이스 연결 오류

# .env 파일 확인
ls .env
# 설정 확인
python -c "from core.config import get_config; c = get_config(); print(c.database)"

참고 문서