File size: 2,349 Bytes
4be6a52
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
"""Public packaging stays navigable without the private repository."""

import importlib.util
import re
from pathlib import Path

import pytest


@pytest.fixture
def script():
    path = Path(__file__).resolve().parents[1] / "scripts/build_release.py"
    spec = importlib.util.spec_from_file_location("stackcraft_test_packaging", path)
    assert spec is not None and spec.loader is not None
    module = importlib.util.module_from_spec(spec)
    spec.loader.exec_module(module)
    return module


def test_public_source_includes_download_verifier(script):
    paths = script.code_files(Path(__file__).resolve().parents[1], demo=False)
    assert Path("scripts/verify_release.py") in paths


def test_source_readme_replaces_only_known_private_plan_link(script):
    before = (
        "See [the project plan](plan.md) for milestones.\n"
        "Literal plan.md and [another link](elsewhere.md) remain untouched.\n"
    )
    assert script.bundled_source_readme(before) == (
        "See [the release tutorial](docs/tutorials/06-release.md) for milestones.\n"
        "Literal plan.md and [another link](elsewhere.md) remain untouched.\n"
    )
    assert script.bundled_source_readme("No planning link here.\n") == "No planning link here.\n"


@pytest.mark.parametrize("report_url", [None, "https://example.org/released-study"])
def test_space_readme_links_only_shipped_files_or_explicit_report(script, report_url):
    readme = script.space_readme(report_url)
    root = Path(__file__).resolve().parents[1]
    files = {str(path) for path in script.code_files(root, demo=True)}
    links = re.findall(r"\]\(([^)]+)\)", readme)
    assert links
    for link in links:
        if link.startswith("<"):
            assert link == f"<{report_url}>"
        elif link.endswith("/"):
            assert any(path.startswith(link) for path in files), link
        else:
            assert link in files, link
    assert readme.startswith("---\ntitle: Stackcraft\nsdk: docker\napp_port: 7860\n")
    assert "**Human play is live. Bot comparisons are recorded.**" in readme
    assert "runs on CPU" in readme
    assert "Playback speed changes the animation, not measured inference latency." in readme
    assert "plan.md" not in readme
    assert "huggingface.co/" not in readme
    assert ("Complete study report" in readme) == (report_url is not None)