Warnings fixed: - datetime.utcnow() → datetime.now(UTC) across 48+ files (src/ + tests/) - datetime.utcnow (callback ref) → lambda: datetime.now(UTC) in model fields (18 files) - Pydantic class Config → model_config = ConfigDict(...) (16 files) - Pydantic .dict() → .model_dump() (8 files) - ConfigDict(allow_population_by_field_name=True) → validate_by_name=True - SQLAlchemy declarative_base() import path updated - FastAPI on_event → lifespan context manager (app.py) - Import sorting (ruff I001) auto-fixed across all files - Fixed broken re-export chains that ruff F401 cleanup broke: _validate_bcp47: service.py now imports from dictionary_validation directly job_to_response: _job_routes.py and test imports from service_utils directly fetch_datasource_metadata: restored re-export in service.py - Added missing TranslateJobService import in _job_routes.py (was deleted by F401) - Added ConfigDict(protected_namespaces=()) for DashboardDatasetItem schema field - pytest.ini: replaced deprecated importmode with asyncio_mode All 440 tests pass with zero deprecation warnings.
55 lines
2.5 KiB
Python
55 lines
2.5 KiB
Python
# #region TestLayoutUtils [C:3] [TYPE TestModule] [SEMANTICS test, layout, superset, height, estimation]
|
|
# @BRIEF Contract tests for layout utility functions — _estimate_markdown_height.
|
|
# Verifies the height estimation formula: empty → 19, short text → computed,
|
|
# padding accounted for, and long text capped at 200.
|
|
# @LAYER Test
|
|
# @RELATION BINDS_TO -> [LayoutUtils]
|
|
# @TEST_CONTRACT: _estimate_markdown_height(str) -> int in [19, 200]
|
|
# @TEST_EDGE: empty_content -> returns minimum height (19)
|
|
# @TEST_EDGE: html_only_content -> returns minimum height (19)
|
|
# @TEST_EDGE: content_with_padding -> padding:12 correctly increases height
|
|
# @TEST_EDGE: very_long_content -> capped at maximum height (200)
|
|
|
|
from src.core.superset_client._layout_utils import _estimate_markdown_height
|
|
|
|
|
|
class TestEstimateMarkdownHeight:
|
|
"""Tests for _estimate_markdown_height pure function."""
|
|
|
|
# #region test_empty_content [C:2] [TYPE Function]
|
|
# @BRIEF Empty string returns minimum height 19.
|
|
def test_empty_content(self):
|
|
assert _estimate_markdown_height("") == 19
|
|
# #endregion test_empty_content
|
|
|
|
# #region test_single_line_text [C:2] [TYPE Function]
|
|
# @BRIEF Short text without padding returns expected computed height.
|
|
# 200 chars → 200//40+1 = 6 lines → 6*22 = 132px → 40+132 = 172px → 172//8 = 21
|
|
def test_single_line_text(self):
|
|
text = "A" * 200
|
|
assert _estimate_markdown_height(text) == 21
|
|
# #endregion test_single_line_text
|
|
|
|
# #region test_content_with_padding [C:2] [TYPE Function]
|
|
# @BRIEF Content with padding:12 — 24px added to content height.
|
|
# 200 chars + padding:12 → 6*22 + 24 = 156 → 40+156 = 196 → 196//8 = 24
|
|
def test_content_with_padding(self):
|
|
content = '<div style="padding:12">' + "A" * 200 + "</div>"
|
|
assert _estimate_markdown_height(content) == 24
|
|
# #endregion test_content_with_padding
|
|
|
|
# #region test_very_long_content [C:2] [TYPE Function]
|
|
# @BRIEF Very long content (3000 chars) capped at max height 200.
|
|
def test_very_long_content(self):
|
|
text = "A" * 3000
|
|
assert _estimate_markdown_height(text) == 200
|
|
# #endregion test_very_long_content
|
|
|
|
# #region test_html_only_content [C:2] [TYPE Function]
|
|
# @BRIEF HTML-only content (no visible text) returns minimum height 19.
|
|
def test_html_only_content(self):
|
|
content = "<br/><hr/><div></div>"
|
|
assert _estimate_markdown_height(content) == 19
|
|
# #endregion test_html_only_content
|
|
# #endregion TestLayoutUtils
|