Run ruff format changes and finalize indentation and lint fixes.
This commit is contained in:
@@ -7,12 +7,73 @@ import pytest
|
||||
import pandas as pd
|
||||
from unittest.mock import Mock
|
||||
import logging
|
||||
import warnings
|
||||
import os as _os
|
||||
|
||||
# Add src to path for imports
|
||||
import sys
|
||||
sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..', 'src'))
|
||||
# Force a headless-friendly Matplotlib backend in tests
|
||||
_os.environ.setdefault("MPLBACKEND", "Agg")
|
||||
|
||||
from src.medicine_manager import MedicineManager, Medicine
|
||||
|
||||
@pytest.fixture(autouse=True, scope="session")
|
||||
def _matplotlib_headless_backend():
|
||||
"""Force Matplotlib to use the Agg backend for all tests.
|
||||
|
||||
Doing this at session scope ensures any pyplot usage in code under test
|
||||
doesn't try to initialize interactive Tk backends.
|
||||
"""
|
||||
try:
|
||||
import matplotlib as _mpl
|
||||
_mpl.use("Agg", force=True)
|
||||
except Exception:
|
||||
# If Matplotlib isn't available or already configured, ignore.
|
||||
pass
|
||||
|
||||
|
||||
@pytest.fixture(autouse=True)
|
||||
def _stub_pyplot_ui_calls(monkeypatch):
|
||||
"""No-op pyplot UI calls that can be noisy or slow in CI.
|
||||
|
||||
This reduces flicker and avoids timing issues without changing behavior.
|
||||
"""
|
||||
try:
|
||||
import matplotlib.pyplot as _plt
|
||||
monkeypatch.setattr(_plt, "pause", lambda *args, **kwargs: None, raising=False)
|
||||
monkeypatch.setattr(_plt, "draw", lambda *args, **kwargs: None, raising=False)
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
|
||||
@pytest.fixture(autouse=True, scope="session")
|
||||
def _tune_reportlab_for_tests():
|
||||
"""Apply small ReportLab tweaks for stable tests without heavy font checks."""
|
||||
try:
|
||||
from reportlab import rl_config
|
||||
# Disable glyph warnings which are irrelevant for our tests
|
||||
rl_config.warnOnMissingFontGlyphs = 0 # type: ignore[attr-defined]
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
# Test-only warning hygiene to keep output clean while preserving behavior
|
||||
# - Silence legacy deprecation shims that originate inside package internals
|
||||
warnings.filterwarnings(
|
||||
"ignore",
|
||||
message=r".*search_filter is deprecated.*",
|
||||
category=DeprecationWarning,
|
||||
)
|
||||
# - Silence a Pillow deprecation surfaced via Matplotlib's Tk backend used by tests
|
||||
warnings.filterwarnings(
|
||||
"ignore",
|
||||
message=r".*'mode' parameter is deprecated and will be removed in Pillow 13.*",
|
||||
category=DeprecationWarning,
|
||||
)
|
||||
# - Silence pandas parse fallback warning triggered intentionally by invalid test data
|
||||
warnings.filterwarnings(
|
||||
"ignore",
|
||||
message=r"Could not infer format, so each element will be parsed individually.*",
|
||||
category=UserWarning,
|
||||
)
|
||||
|
||||
from thechart.managers import MedicineManager, Medicine
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
|
||||
Reference in New Issue
Block a user