Files
ZQYY.FQ-ETL/tests/unit/test_config_properties.py

56 lines
2.1 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# -*- coding: utf-8 -*-
"""配置映射属性测试 — 使用 hypothesis 验证配置键兼容映射的通用正确性属性。"""
import os
import warnings
import pytest
from hypothesis import given, settings
from hypothesis import strategies as st
from config.settings import AppConfig, _FLOW_TO_DATA_SOURCE
# ── 确保测试不读取 .env 文件 ──────────────────────────────────
@pytest.fixture(autouse=True)
def skip_dotenv(monkeypatch):
monkeypatch.setenv("ETL_SKIP_DOTENV", "1")
# ── 生成策略 ──────────────────────────────────────────────────
flow_st = st.sampled_from(["FULL", "FETCH_ONLY", "INGEST_ONLY"])
# ── Property 11: pipeline_flow → data_source 映射一致性 ──────
# Feature: scheduler-refactor, Property 11: pipeline_flow → data_source 映射一致性
# **Validates: Requirements 8.1, 8.2, 8.3, 5.2, 8.4**
#
# 对于任意旧 pipeline_flow 值FULL/FETCH_ONLY/INGEST_ONLY
# 映射到 data_source 的结果应与预定义映射表一致:
# FULL→hybrid、FETCH_ONLY→online、INGEST_ONLY→offline。
# 同样,配置键 pipeline.flow 应自动映射到 run.data_source。
class TestProperty11FlowToDataSourceMapping:
"""Property 11: pipeline_flow → data_source 映射一致性。"""
@given(flow=flow_st)
@settings(max_examples=100)
def test_pipeline_flow_maps_to_data_source(self, flow):
"""通过 pipeline.flow 设置旧值后run.data_source 应与映射表一致。"""
expected = _FLOW_TO_DATA_SOURCE[flow]
with warnings.catch_warnings():
warnings.simplefilter("ignore", DeprecationWarning)
config = AppConfig.load({
"app": {"store_id": 1},
"pipeline": {"flow": flow},
})
actual = config.get("run.data_source")
assert actual == expected, (
f"pipeline.flow={flow!r} 应映射为 run.data_source={expected!r}"
f"实际为 {actual!r}"
)