mirror of
https://github.com/Alishahryar1/free-claude-code.git
synced 2026-04-28 19:40:54 +00:00
Phase 7: Directory restructuring (messaging/ and tests/)
- Create messaging/platforms/ (base, discord, telegram, factory) - Create messaging/rendering/ (discord_markdown, telegram_markdown) - Create messaging/trees/ (data, repository, processor, queue_manager) - Organize tests/ into api/, providers/, messaging/, cli/, config/ - Add backward-compatible re-exports at old locations - Update handler.py and test_messaging_factory.py imports - Fix Telegram type hints for TELEGRAM_AVAILABLE=False case - Fix Python 3 except syntax in discord_markdown Co-authored-by: Ali Khokhar <alishahryar2@gmail.com>
This commit is contained in:
parent
38a7980546
commit
4b4f87515d
76 changed files with 3294 additions and 3124 deletions
60
tests/config/test_logging_config.py
Normal file
60
tests/config/test_logging_config.py
Normal file
|
|
@ -0,0 +1,60 @@
|
|||
"""Tests for config/logging_config.py."""
|
||||
|
||||
import json
|
||||
import logging
|
||||
from pathlib import Path
|
||||
|
||||
|
||||
from config.logging_config import configure_logging
|
||||
|
||||
|
||||
def test_configure_logging_writes_json_to_file(tmp_path):
|
||||
"""configure_logging writes JSON lines to the specified file."""
|
||||
log_file = str(tmp_path / "test.log")
|
||||
configure_logging(log_file, force=True)
|
||||
|
||||
# Emit a log via stdlib (intercepted to loguru)
|
||||
logger = logging.getLogger("test.module")
|
||||
logger.info("Test message for JSON")
|
||||
|
||||
# Force flush - loguru may buffer
|
||||
from loguru import logger as loguru_logger
|
||||
|
||||
loguru_logger.complete()
|
||||
|
||||
content = Path(log_file).read_text(encoding="utf-8")
|
||||
lines = [line for line in content.strip().split("\n") if line]
|
||||
assert len(lines) >= 1
|
||||
|
||||
# Each line should be valid JSON
|
||||
for line in lines:
|
||||
record = json.loads(line)
|
||||
assert "text" in record or "message" in record or "record" in record
|
||||
|
||||
|
||||
def test_configure_logging_idempotent(tmp_path):
|
||||
"""configure_logging is idempotent - safe to call twice with force."""
|
||||
log_file = str(tmp_path / "test.log")
|
||||
configure_logging(log_file, force=True)
|
||||
configure_logging(log_file, force=True) # Should not raise
|
||||
|
||||
logger = logging.getLogger("test.idempotent")
|
||||
logger.info("After second configure")
|
||||
|
||||
|
||||
def test_configure_logging_skips_when_already_configured(tmp_path):
|
||||
"""Without force, second call is a no-op (avoids reconfig on hot reload)."""
|
||||
log_file = str(tmp_path / "test.log")
|
||||
configure_logging(log_file, force=True)
|
||||
# Second call without force - should skip; no exception, log file unchanged
|
||||
configure_logging(str(tmp_path / "other.log"), force=False)
|
||||
# Logs still go to first file
|
||||
logger = logging.getLogger("test.skip")
|
||||
logger.info("Still goes to first file")
|
||||
from loguru import logger as loguru_logger
|
||||
|
||||
loguru_logger.complete()
|
||||
assert (tmp_path / "test.log").exists()
|
||||
assert "Still goes to first file" in (tmp_path / "test.log").read_text(
|
||||
encoding="utf-8"
|
||||
)
|
||||
Loading…
Add table
Add a link
Reference in a new issue