Spaces:
Paused
Paused
Download tests/test_data_loader.py from YGCXLab/yeogibrain-mcp: direct link, hf CLI and curl.
- Browser
- Download file 9.15 kB
-
https://huggingface.co/spaces/YGCXLab/yeogibrain-mcp/resolve/main/tests/test_data_loader.py
- Command line
-
hf download hf://spaces/YGCXLab/yeogibrain-mcp/tests/test_data_loader.py
-
curl -L -o test_data_loader.py https://huggingface.co/spaces/YGCXLab/yeogibrain-mcp/resolve/main/tests/test_data_loader.py
9.15 kB
| import pytest | |
| from yeogibrain_mcp.data_loader import DataStore | |
| def store(): | |
| return DataStore() | |
| def test_loads_all_categories(store): | |
| assert len(store.documents) > 0 | |
| categories = {d["category"] for d in store.documents.values()} | |
| assert categories == {"prd", "ac", "ab", "research", "nng", "baymard", "dovetail"} | |
| def test_document_has_required_fields(store): | |
| for doc_id, doc in store.documents.items(): | |
| assert "id" in doc | |
| assert "title" in doc | |
| assert "category" in doc | |
| # dovetail은 utterances 기반이라 md_path 없음 | |
| if doc["category"] != "dovetail": | |
| assert "md_path" in doc | |
| def test_document_count(store): | |
| by_cat = {} | |
| for doc in store.documents.values(): | |
| by_cat[doc["category"]] = by_cat.get(doc["category"], 0) + 1 | |
| # 원본 prd_articles.json에 중복 ID가 1건 존재하여 고유 문서는 424건 | |
| assert by_cat["prd"] == 424 | |
| assert by_cat["ac"] == 176 | |
| assert by_cat["ab"] == 259 | |
| assert by_cat["research"] == 145 | |
| def test_get_by_id(store): | |
| doc = store.get("PRD-001") | |
| assert doc is not None | |
| assert doc["category"] == "prd" | |
| def test_get_by_id_case_insensitive(store): | |
| assert store.get("prd-001") is not None | |
| assert store.get("res-001") is not None | |
| assert store.get("AC-001") is not None | |
| assert store.get("ab-001") is not None | |
| def test_get_nonexistent_returns_none(store): | |
| assert store.get("FAKE-999") is None | |
| def test_relationships_loaded(store): | |
| assert len(store.relationships) > 0 | |
| def test_get_related_prd(store): | |
| related = store.get_related("PRD-001") | |
| assert isinstance(related, dict) | |
| assert "ac" in related | |
| assert "ab" in related | |
| assert "research" in related | |
| assert "prd" in related | |
| def test_get_related_nonexistent(store): | |
| related = store.get_related("FAKE-999") | |
| assert related == {"ac": [], "ab": [], "research": [], "prd": []} | |
| def test_read_content(store): | |
| content = store.read_content("PRD-001") | |
| assert content is not None | |
| assert len(content) > 0 | |
| def test_read_content_nonexistent(store): | |
| assert store.read_content("FAKE-999") is None | |
| def test_get_date_prd(store): | |
| doc = store.get("PRD-001") | |
| date = store.get_date(doc) | |
| assert date is None or isinstance(date, str) | |
| def test_get_date_research(store): | |
| doc = store.get("RES-001") | |
| date = store.get_date(doc) | |
| assert date is not None | |
| def test_get_author_research(store): | |
| doc = store.get("RES-001") | |
| author = store.get_author(doc) | |
| assert author is not None | |
| def test_get_author_ac(store): | |
| docs = [d for d in store.documents.values() if d["category"] == "ac" and d.get("author")] | |
| if docs: | |
| author = store.get_author(docs[0]) | |
| assert author is not None | |
| def test_content_cache(store): | |
| content1 = store.read_content_cached("PRD-001") | |
| content2 = store.read_content_cached("PRD-001") | |
| assert content1 == content2 | |
| assert content1 is not None | |
| def test_filter_by_category(store): | |
| results = store.filter_documents(category="research") | |
| assert len(results) == 145 | |
| assert all(d["category"] == "research" for d in results) | |
| def test_filter_by_author(store): | |
| results = store.filter_documents(category="research", author="욘두") | |
| assert len(results) > 0 | |
| assert all(store.get_author(d) == "욘두" for d in results) | |
| def test_filter_by_date_range(store): | |
| results = store.filter_documents(category="research", date_from="2024-01-01", date_to="2024-12-31") | |
| for d in results: | |
| date = store.get_date(d) | |
| assert date is not None | |
| assert "2024" in date | |
| def test_filter_by_methodology(store): | |
| results = store.filter_documents(category="research", methodology="UT") | |
| assert len(results) > 0 | |
| assert all(d.get("methodology") == "UT" for d in results) | |
| def test_filter_by_domain(store): | |
| results = store.filter_documents(domain="search") | |
| assert len(results) > 0 | |
| assert all(d.get("domain") == "search" for d in results) | |
| def test_filter_by_space(store): | |
| results = store.filter_documents(space="FIN") | |
| assert len(results) > 0 | |
| assert all(d.get("space") == "FIN" for d in results) | |
| def test_filter_sort_date_desc(store): | |
| results = store.filter_documents(category="research", sort_by="date_desc") | |
| dates = [store.get_date(d) for d in results if store.get_date(d)] | |
| assert dates == sorted(dates, reverse=True) | |
| def test_filter_sort_date_asc(store): | |
| results = store.filter_documents(category="research", sort_by="date_asc") | |
| dates = [store.get_date(d) for d in results if store.get_date(d)] | |
| assert dates == sorted(dates) | |
| def test_filter_with_limit_and_offset(store): | |
| all_results = store.filter_documents(category="research") | |
| page = store.filter_documents(category="research", limit=10, offset=5) | |
| assert len(page) == 10 | |
| assert page[0]["id"] == all_results[5]["id"] | |
| def test_filter_combined(store): | |
| results = store.filter_documents( | |
| category="research", | |
| author="욘두", | |
| date_from="2022-01-01", | |
| ) | |
| for d in results: | |
| assert d["category"] == "research" | |
| assert store.get_author(d) == "욘두" | |
| date = store.get_date(d) | |
| assert date is not None and date >= "2022-01-01" | |
| def test_ab_summary_enrichment(store): | |
| """AB 문서에 마크다운 기반 summary가 보강되었는지 확인.""" | |
| ab_docs = [d for d in store.documents.values() if d["category"] == "ab"] | |
| with_summary = [d for d in ab_docs if d.get("summary")] | |
| # 마크다운이 있는 AB 문서 중 상당수가 summary를 가져야 함 | |
| assert len(with_summary) > 50, f"AB summary 보강: {len(with_summary)}/{len(ab_docs)}" | |
| def test_ab_summary_content(store): | |
| """AB-158 (Launch 결정 문서)의 summary에 의미 있는 내용이 있는지 확인.""" | |
| doc = store.get("AB-158") | |
| assert doc is not None | |
| summary = doc.get("summary", "") | |
| assert len(summary) > 20 | |
| # ------------------------------------------------------------------ | |
| # NNg 문서 테스트 | |
| # ------------------------------------------------------------------ | |
| def test_nng_document_count(store): | |
| nng_docs = [d for d in store.documents.values() if d["category"] == "nng"] | |
| assert len(nng_docs) == 439 | |
| def test_nng_id_format(store): | |
| doc = store.get("NNG-001") | |
| assert doc is not None | |
| assert doc["category"] == "nng" | |
| assert doc["title"] != "" | |
| def test_nng_has_required_fields(store): | |
| doc = store.get("NNG-001") | |
| assert "slug" in doc | |
| assert "url" in doc | |
| assert "topics" in doc | |
| assert "date" in doc | |
| def test_nng_date_normalized(store): | |
| """NNg 날짜가 YYYY-MM-DD 형태로 정규화되었는지 확인.""" | |
| doc = store.get("NNG-001") | |
| date = store.get_date(doc) | |
| assert date is not None | |
| assert len(date) == 10 # YYYY-MM-DD | |
| assert date[4] == "-" | |
| def test_nng_author(store): | |
| doc = store.get("NNG-001") | |
| author = store.get_author(doc) | |
| assert author is not None and len(author) > 0 | |
| def test_nng_filter_by_category(store): | |
| results = store.filter_documents(category="nng") | |
| assert len(results) == 439 | |
| assert all(d["category"] == "nng" for d in results) | |
| # ------------------------------------------------------------------ | |
| # Baymard 문서 테스트 | |
| # ------------------------------------------------------------------ | |
| def test_baymard_document_count(store): | |
| docs = [d for d in store.documents.values() if d["category"] == "baymard"] | |
| assert len(docs) == 520 | |
| def test_baymard_id_format(store): | |
| doc = store.get("BMD-001") | |
| assert doc is not None | |
| assert doc["category"] == "baymard" | |
| def test_baymard_has_required_fields(store): | |
| doc = store.get("BMD-001") | |
| assert "theme" in doc | |
| assert "issue" in doc | |
| assert "advice" in doc | |
| assert "importance" in doc | |
| assert "platforms" in doc | |
| def test_baymard_read_content(store): | |
| doc = store.get("BMD-001") | |
| assert doc.get("md_path") != "" | |
| content = store.read_content("BMD-001") | |
| assert content is not None | |
| assert len(content) > 100 | |
| def test_baymard_filter_by_category(store): | |
| results = store.filter_documents(category="baymard") | |
| assert len(results) == 520 | |
| # ------------------------------------------------------------------ | |
| # Dovetail 문서 테스트 | |
| # ------------------------------------------------------------------ | |
| def test_dovetail_document_count(store): | |
| docs = [d for d in store.documents.values() if d["category"] == "dovetail"] | |
| assert len(docs) == 647 | |
| def test_dovetail_id_format(store): | |
| doc = store.get("TRS-001") | |
| assert doc is not None | |
| assert doc["category"] == "dovetail" | |
| def test_dovetail_has_required_fields(store): | |
| doc = store.get("TRS-001") | |
| assert "project" in doc | |
| assert "date" in doc | |
| assert "utterance_count" in doc | |
| def test_dovetail_transcript(store): | |
| transcript = store.get_dovetail_transcript("TRS-001") | |
| assert len(transcript) > 0 | |
| assert ":" in transcript # "화자: 발화" 형태 | |
| def test_dovetail_filter_by_category(store): | |
| results = store.filter_documents(category="dovetail") | |
| assert len(results) == 647 | |