Skip to content

Commit aaf2ced

Browse files
authored
test: use fixtures for extraction smoke tests (#7)
1 parent 4ffa42d commit aaf2ced

4 files changed

Lines changed: 102 additions & 6 deletions

File tree

docs/README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,12 @@ Edit `config.yaml` (optional). Defaults: Unity 6.3 URL, paths under `data/unity/
5757
pytest
5858
```
5959

60+
Optional real-doc extraction integration tests:
61+
```
62+
UNITYDOCS_E2E=1 pytest tests/test_extraction.py
63+
```
64+
These require local Unity raw docs under `data/unity/<version>/raw/UnityDocumentation`.
65+
6066
## Notes
6167
- Bake/index steps are idempotent: existing artifacts with matching config/version skip work.
6268
- Link extraction ignores external and anchor-only links; internal links are normalized to doc_ids for related lookups.

tests/fixtures/manual_index.html

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<!doctype html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="utf-8" />
5+
<title>Create and run a job</title>
6+
<link rel="canonical" href="https://docs.unity3d.com/6000.3/Documentation/Manual/job-system-creating-jobs.html" />
7+
</head>
8+
<body>
9+
<div id="content-wrap">
10+
<div class="section">
11+
<h1>Create and run a job</h1>
12+
<p>
13+
Unity jobs let you schedule small units of work so the main thread can keep rendering and gameplay responsive.
14+
A job typically operates on NativeArray data, is scheduled from the main thread, and completed when the results
15+
are needed. This fixture intentionally contains enough text to exercise markdown conversion and extraction logic.
16+
</p>
17+
<h2>Schedule and Complete best practices</h2>
18+
<p>
19+
Use JobHandle dependencies to chain work, avoid forcing the main thread to wait too early, and call Complete as
20+
late as possible when you need job results. This helps maximize parallel throughput and keeps frame time stable.
21+
</p>
22+
<p>
23+
For data-parallel workloads, use IJobParallelFor with a tuned batch count and avoid oversynchronizing unrelated
24+
jobs. Profiling helps determine whether you should split long jobs into smaller dependent jobs.
25+
</p>
26+
<a href="../ScriptReference/Unity.Jobs.IJobParallelFor.html">IJobParallelFor API</a>
27+
</div>
28+
</div>
29+
</body>
30+
</html>
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<!doctype html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="utf-8" />
5+
<title>IJobParallelFor</title>
6+
<link rel="canonical" href="https://docs.unity3d.com/6000.3/Documentation/ScriptReference/Unity.Jobs.IJobParallelFor.html" />
7+
</head>
8+
<body>
9+
<div id="content-wrap">
10+
<div class="section">
11+
<h1>IJobParallelFor</h1>
12+
<p>
13+
IJobParallelFor defines an Execute method that runs once per index in a NativeArray-style data source.
14+
Unity partitions work into batches and schedules these across worker threads to improve throughput on
15+
multicore CPUs. This fixture is representative rather than canonical documentation content.
16+
</p>
17+
<h2>Description</h2>
18+
<p>
19+
Implement Execute(int index) to process one element at a time. Use Schedule(length, batchSize) to control
20+
how many elements are processed and how work stealing can rebalance uneven workloads.
21+
</p>
22+
<pre><code class="lang-cs">public struct MyParallelJob : IJobParallelFor
23+
{
24+
public NativeArray<float> values;
25+
public float deltaTime;
26+
27+
public void Execute(int index)
28+
{
29+
values[index] += deltaTime;
30+
}
31+
}</code></pre>
32+
</div>
33+
</div>
34+
</body>
35+
</html>

tests/test_extraction.py

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,47 @@
1+
import os
12
from pathlib import Path
23

4+
import pytest
5+
36
from unity_docs_mcp.bake.extract_manual import extract_manual
47
from unity_docs_mcp.bake.extract_scriptref import extract_scriptref
58
from unity_docs_mcp.bake.html_to_md import HtmlToTextOptions
69

10+
FIXTURES_DIR = Path(__file__).parent / "fixtures"
11+
REAL_DOCS_ROOT = Path("data/unity/6000.3/raw/UnityDocumentation/Documentation/en")
12+
ENABLE_E2E = os.environ.get("UNITYDOCS_E2E") == "1"
13+
714

815
def test_manual_extraction_smoke():
9-
sample = Path("data/unity/6000.3/raw/UnityDocumentation/Documentation/en/Manual/index.html")
10-
assert sample.exists(), "Manual index missing; ensure Unity docs present"
16+
sample = FIXTURES_DIR / "manual_index.html"
17+
assert sample.exists(), "Fixture missing"
1118
res = extract_manual(sample, HtmlToTextOptions(), drop_sections_list=[])
19+
assert "Create and run a job" in res["title"]
1220
assert len(res["text_md"]) > 200
1321

1422

1523
def test_scriptref_extraction_smoke():
16-
sample = Path(
17-
"data/unity/6000.3/raw/UnityDocumentation/Documentation/en/ScriptReference/Unity.Jobs.IJobParallelFor.html"
18-
)
19-
assert sample.exists(), "ScriptReference sample missing; ensure Unity docs present"
24+
sample = FIXTURES_DIR / "scriptref_iJobParallelFor.html"
25+
assert sample.exists(), "Fixture missing"
26+
res = extract_scriptref(sample, HtmlToTextOptions())
27+
assert "IJobParallelFor" in res["title"]
28+
assert len(res["text_md"]) > 200
29+
30+
31+
@pytest.mark.skipif(not ENABLE_E2E, reason="set UNITYDOCS_E2E=1 to run real-doc integration tests")
32+
def test_manual_extraction_real_docs():
33+
sample = REAL_DOCS_ROOT / "Manual/index.html"
34+
if not sample.exists():
35+
pytest.skip("Manual docs not present under data/unity/6000.3/raw")
36+
res = extract_manual(sample, HtmlToTextOptions(), drop_sections_list=[])
37+
assert len(res["text_md"]) > 200
38+
39+
40+
@pytest.mark.skipif(not ENABLE_E2E, reason="set UNITYDOCS_E2E=1 to run real-doc integration tests")
41+
def test_scriptref_extraction_real_docs():
42+
sample = REAL_DOCS_ROOT / "ScriptReference/Unity.Jobs.IJobParallelFor.html"
43+
if not sample.exists():
44+
pytest.skip("ScriptReference docs not present under data/unity/6000.3/raw")
2045
res = extract_scriptref(sample, HtmlToTextOptions())
2146
assert "IJobParallelFor" in res["title"]
2247
assert len(res["text_md"]) > 200

0 commit comments

Comments
 (0)