Refactor test cases for improved clarity and functionality
Browse files- Updated the temporary directory creation in `test_chroma_rag.py` to use the default location.
- Introduced a new helper function `seed_peft_original_markdown` in `test_update_kb_wiki.py` to streamline the setup of markdown files for testing.
- Modified the `test_update_kb_wiki_seeds_navigation_pages` and `test_update_kb_wiki_preserves_authored_topic_content_and_appends_log` tests to utilize the new helper function, enhancing code reuse and readability.
- tests/test_chroma_rag.py +1 -1
- tests/test_update_kb_wiki.py +19 -1
tests/test_chroma_rag.py
CHANGED
|
@@ -106,7 +106,7 @@ After the example.
|
|
| 106 |
}
|
| 107 |
]
|
| 108 |
|
| 109 |
-
with tempfile.TemporaryDirectory(
|
| 110 |
db_path = Path(temp_dir)
|
| 111 |
count = write_retrieval_artifacts(
|
| 112 |
config={
|
|
|
|
| 106 |
}
|
| 107 |
]
|
| 108 |
|
| 109 |
+
with tempfile.TemporaryDirectory() as temp_dir:
|
| 110 |
db_path = Path(temp_dir)
|
| 111 |
count = write_retrieval_artifacts(
|
| 112 |
config={
|
tests/test_update_kb_wiki.py
CHANGED
|
@@ -3,6 +3,7 @@ from __future__ import annotations
|
|
| 3 |
import json
|
| 4 |
from pathlib import Path
|
| 5 |
|
|
|
|
| 6 |
from data.scraping_scripts.build_kb_artifacts import build_kb_artifacts
|
| 7 |
from data.scraping_scripts.update_kb_wiki import update_kb_wiki
|
| 8 |
|
|
@@ -13,7 +14,22 @@ def write_jsonl(path: Path, rows: list[dict]) -> None:
|
|
| 13 |
handle.write(json.dumps(row) + "\n")
|
| 14 |
|
| 15 |
|
| 16 |
-
def
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 17 |
input_file = tmp_path / "all_sources_data.jsonl"
|
| 18 |
kb_dir = tmp_path / "kb"
|
| 19 |
write_jsonl(
|
|
@@ -63,7 +79,9 @@ def test_update_kb_wiki_seeds_navigation_pages(tmp_path: Path) -> None:
|
|
| 63 |
|
| 64 |
def test_update_kb_wiki_preserves_authored_topic_content_and_appends_log(
|
| 65 |
tmp_path: Path,
|
|
|
|
| 66 |
) -> None:
|
|
|
|
| 67 |
input_file = tmp_path / "all_sources_data.jsonl"
|
| 68 |
kb_dir = tmp_path / "kb"
|
| 69 |
write_jsonl(
|
|
|
|
| 3 |
import json
|
| 4 |
from pathlib import Path
|
| 5 |
|
| 6 |
+
from data.scraping_scripts import build_kb_artifacts as builder
|
| 7 |
from data.scraping_scripts.build_kb_artifacts import build_kb_artifacts
|
| 8 |
from data.scraping_scripts.update_kb_wiki import update_kb_wiki
|
| 9 |
|
|
|
|
| 14 |
handle.write(json.dumps(row) + "\n")
|
| 15 |
|
| 16 |
|
| 17 |
+
def seed_peft_original_markdown(tmp_path: Path, monkeypatch) -> None:
|
| 18 |
+
"""Point the peft source at a tmp original-markdown tree so the mirrored
|
| 19 |
+
`raw/docs/peft/package_reference/lora.md` path is produced on any machine,
|
| 20 |
+
instead of depending on the locally downloaded corpus (data/peft_md_files)."""
|
| 21 |
+
md_page = tmp_path / "peft_md_files" / "package_reference" / "lora.md"
|
| 22 |
+
md_page.parent.mkdir(parents=True)
|
| 23 |
+
md_page.write_text(
|
| 24 |
+
"# LoRA\n\nUse `LoraConfig` for adapter fine-tuning.\n", encoding="utf-8"
|
| 25 |
+
)
|
| 26 |
+
peft_config = dict(builder.SOURCE_CONFIGS["peft"])
|
| 27 |
+
peft_config["input_directory"] = str(tmp_path / "peft_md_files")
|
| 28 |
+
monkeypatch.setitem(builder.SOURCE_CONFIGS, "peft", peft_config)
|
| 29 |
+
|
| 30 |
+
|
| 31 |
+
def test_update_kb_wiki_seeds_navigation_pages(tmp_path: Path, monkeypatch) -> None:
|
| 32 |
+
seed_peft_original_markdown(tmp_path, monkeypatch)
|
| 33 |
input_file = tmp_path / "all_sources_data.jsonl"
|
| 34 |
kb_dir = tmp_path / "kb"
|
| 35 |
write_jsonl(
|
|
|
|
| 79 |
|
| 80 |
def test_update_kb_wiki_preserves_authored_topic_content_and_appends_log(
|
| 81 |
tmp_path: Path,
|
| 82 |
+
monkeypatch,
|
| 83 |
) -> None:
|
| 84 |
+
seed_peft_original_markdown(tmp_path, monkeypatch)
|
| 85 |
input_file = tmp_path / "all_sources_data.jsonl"
|
| 86 |
kb_dir = tmp_path / "kb"
|
| 87 |
write_jsonl(
|