|
1 | | -"""Company.panel(topic) 전수 스모크 — registry 등록된 모든 topic 을 iterate. |
2 | | -
|
3 | | -core/registry 는 37개+ topic 을 자동 등록한다. 이 파일은 매 topic 을 |
4 | | -`c.panel(topic)` 으로 호출해 크래시/silent-None 을 잡는다. |
5 | | -
|
6 | | -과거 회귀: topic/panel 표면이 silent None → 후속 .columns 접근 크래시. |
7 | | -""" |
| 1 | +"""공개 Company.topics에 표시된 모든 topic의 본문과 출처를 실제로 조회한다.""" |
8 | 2 |
|
9 | 3 | from __future__ import annotations |
10 | 4 |
|
11 | | -import pytest |
| 5 | +import gc |
12 | 6 |
|
| 7 | +import polars as pl |
| 8 | +import pytest |
13 | 9 |
|
14 | | -def _allTopics() -> list[str]: |
15 | | - """registry 에서 자동 수집된 모든 topic 이름.""" |
16 | | - from dartlab.providers.dart.company import _getModuleEntries |
| 10 | +from tests.conftest import SAMSUNG, _has_data |
17 | 11 |
|
18 | | - return sorted({e.funcName for e in _getModuleEntries()}) |
| 12 | +MISSING_DATA = "__missing_samsung_panel__" |
19 | 13 |
|
20 | 14 |
|
21 | | -ALL_TOPICS = _allTopics() |
| 15 | +def _publicTopics() -> list[str]: |
| 16 | + """은퇴한 내부 함수 등록부 대신 사용자가 보는 데이터 지도를 따른다.""" |
| 17 | + if not _has_data(SAMSUNG, "panel"): |
| 18 | + return [MISSING_DATA] |
| 19 | + from dartlab import Company |
22 | 20 |
|
| 21 | + company = Company(SAMSUNG) |
| 22 | + try: |
| 23 | + catalog = company.topics |
| 24 | + assert isinstance(catalog, pl.DataFrame) and "topic" in catalog.columns |
| 25 | + topics = sorted(set(catalog["topic"].drop_nulls().to_list())) |
| 26 | + assert topics, "Company.topics가 비어 있어 전수 검사를 실행할 수 없습니다" |
| 27 | + return topics |
| 28 | + finally: |
| 29 | + del company |
| 30 | + gc.collect() |
23 | 31 |
|
24 | | -# 데이터 부재 시 None/빈 DataFrame 이 허용되는 topic. |
25 | | -# 비상장 성격/소규모 회사에서는 특정 공시 파트가 비어있을 수 있음. |
26 | | -_TOPIC_NONE_ALLOWED: frozenset[str] = frozenset( |
27 | | - { |
28 | | - "bond", # 채무증권 발행 이력 없을 수 있음 |
29 | | - "sanction", # 제재 이력 없을 수 있음 |
30 | | - "contingentLiability", # 우발부채 없을 수 있음 |
31 | | - "fundraising", # 증자감자 이벤트 없을 수 있음 |
32 | | - "investmentInOther", # 타법인 출자 없을 수 있음 |
33 | | - "riskDerivative", # 파생상품 없을 수 있음 |
34 | | - "relatedPartyTx", # 관계자 거래 없을 수 있음 |
35 | | - "affiliate", # 관계기업 투자 없을 수 있음 |
36 | | - "executivePay", # 임원보수 공시 안한 경우 |
37 | | - "dividend", # 무배당 회사 |
38 | | - "otherFinance", # 기타 재무 없음 가능 |
39 | | - # fixture 한계로 None 허용 (로컬 실데이터에서는 데이터 존재) |
40 | | - "business", # 사업의내용 — fixture panel 데이터 한계 |
41 | | - "companyOverviewDetail", # 회사개요 상세 — 동일 |
42 | | - } |
43 | | -) |
44 | 32 |
|
45 | | -# 2026-04-21 Phase D: show() 가 registered-but-empty topic 을 ValueError 대신 None |
46 | | -# 으로 리턴하도록 수정 → 해당 frozenset 비움 (xfail 불필요). |
47 | | -_SHOW_ROUTING_KNOWN_ISSUES: frozenset[str] = frozenset() |
| 33 | +PUBLIC_TOPICS = _publicTopics() |
48 | 34 |
|
49 | 35 |
|
50 | 36 | @pytest.mark.realData |
51 | 37 | @pytest.mark.integration |
52 | | -@pytest.mark.parametrize("topic", ALL_TOPICS) |
53 | | -def test_show_topicNoSilentFail(samsungRealData, topic): |
54 | | - """c.panel(topic) 이 각 topic 에서 크래시하지 않고, None 은 허용 topic 에서만.""" |
55 | | - try: |
56 | | - result = samsungRealData.panel(topic) |
57 | | - except NotImplementedError: |
58 | | - pytest.skip(f"show({topic}) 미구현") |
59 | | - except ValueError as e: |
60 | | - if topic in _SHOW_ROUTING_KNOWN_ISSUES and "찾을 수 없습니다" in str(e): |
61 | | - pytest.xfail(f"show({topic!r}) 기존 라우팅 버그 — registry 등록됐으나 show() 가 ValueError") |
62 | | - pytest.fail(f"show({topic!r}) 크래시: {type(e).__name__}: {e}") |
63 | | - except Exception as e: |
64 | | - pytest.fail(f"show({topic!r}) 크래시: {type(e).__name__}: {e}") |
65 | | - |
66 | | - if result is None: |
67 | | - if topic in _TOPIC_NONE_ALLOWED: |
68 | | - return |
69 | | - pytest.fail( |
70 | | - f"show({topic!r}) None — 화이트리스트에 없음. " |
71 | | - f"삼성전자는 충분히 큰 회사여서 빈 topic 이 의심스럽다. " |
72 | | - f"정말 데이터 없음이 정상이면 _TOPIC_NONE_ALLOWED 에 추가." |
73 | | - ) |
| 38 | +@pytest.mark.parametrize("topic", PUBLIC_TOPICS) |
| 39 | +def testPanelPublicTopicReturnsData(samsungRealData, topic): |
| 40 | + """공개 목록에 있는 topic은 실제 읽을 수 있는 본문을 반환해야 한다.""" |
| 41 | + assert topic != MISSING_DATA, "samsungRealData의 데이터 부재 가드가 실행되지 않았습니다" |
| 42 | + result = samsungRealData.panel(topic) |
| 43 | + assert isinstance(result, pl.DataFrame), f"panel({topic!r}) 본문 없음: {type(result).__name__}" |
| 44 | + assert not result.is_empty(), f"panel({topic!r}) 빈 본문" |
74 | 45 |
|
75 | 46 |
|
76 | 47 | @pytest.mark.realData |
77 | 48 | @pytest.mark.integration |
78 | | -@pytest.mark.parametrize("topic", ALL_TOPICS) |
79 | | -def test_trace_topicNoSilentFail(samsungRealData, topic): |
80 | | - """c.trace(topic) — 데이터 출처 추적. show 쌍둥이 커버.""" |
81 | | - try: |
82 | | - result = samsungRealData.trace(topic) |
83 | | - except NotImplementedError: |
84 | | - pytest.skip(f"trace({topic}) 미구현") |
85 | | - except Exception as e: |
86 | | - pytest.fail(f"trace({topic!r}) 크래시: {type(e).__name__}: {e}") |
87 | | - |
88 | | - # fixture 환경에서는 trace 데이터가 제한적이므로 None 허용 폭을 관대하게. |
89 | | - # 로컬 실데이터 환경에서만 엄격 검증. |
90 | | - import os |
91 | | - |
92 | | - inFixtureEnv = "fixtures" in os.environ.get("DARTLAB_DATA_DIR", "") |
93 | | - if inFixtureEnv: |
94 | | - return |
95 | | - # 로컬: show 기반 핵심 topic 만 엄격 검증 |
96 | | - if result is None and topic in {"sections", "business", "mdna", "rnd"}: |
97 | | - pytest.fail(f"trace({topic!r}) None — 핵심 topic 에서 trace 실종") |
| 49 | +@pytest.mark.parametrize("topic", PUBLIC_TOPICS) |
| 50 | +def testTracePublicTopicHasSource(samsungRealData, topic): |
| 51 | + """본문이 광고된 topic은 fixture 환경에서도 실제 출처를 제시해야 한다.""" |
| 52 | + assert topic != MISSING_DATA, "samsungRealData의 데이터 부재 가드가 실행되지 않았습니다" |
| 53 | + result = samsungRealData.trace(topic) |
| 54 | + assert isinstance(result, dict), f"trace({topic!r}) 출처 없음" |
| 55 | + assert result.get("primarySource"), f"trace({topic!r}) primarySource 없음" |
| 56 | + assert result.get("availableSources"), f"trace({topic!r}) availableSources 없음" |
0 commit comments