|
| 1 | +import json |
1 | 2 | import os |
2 | 3 | import pathlib |
3 | 4 | import re |
| 5 | +import sys |
| 6 | +from importlib import import_module |
4 | 7 |
|
5 | 8 | EXCLUDED_DIRS = [ |
6 | 9 | # These directories contain notebook files that should not be linked to in the README. |
|
13 | 16 |
|
14 | 17 |
|
15 | 18 | def test_readme(): |
| 19 | + """ Each entry in the README should have an actual file in the repository """ |
16 | 20 | root_path = pathlib.Path(__file__).parent.parent.parent.resolve() |
17 | 21 |
|
18 | 22 | examples_path = os.path.join(root_path, "examples") |
@@ -40,3 +44,39 @@ def test_readme(): |
40 | 44 | assert ( |
41 | 45 | missing_in_readme == set() |
42 | 46 | ), "There are some new notebooks that haven't been added to the README summary: " |
| 47 | + |
| 48 | +def test_readme_matches_entries(): |
| 49 | + """ Each entry in the README should come from an ENTRIES.json entry. """ |
| 50 | + root_path = pathlib.Path(__file__).parent.parent.parent.resolve() |
| 51 | + |
| 52 | + with open(os.path.join(root_path, "docs/ENTRIES.json"), "r") as f: |
| 53 | + entries = json.load(f) |
| 54 | + |
| 55 | + with open(os.path.join(root_path, "README.md"), "r") as f: |
| 56 | + readme = f.read() |
| 57 | + |
| 58 | + readme_links = set(re.findall(LINK_EXAMPLES_REGEX, readme)) |
| 59 | + entries_links = {entry["location"] for entry in entries.values()} |
| 60 | + |
| 61 | + missing_in_entries = readme_links - entries_links |
| 62 | + extra_in_entries = entries_links - readme_links |
| 63 | + |
| 64 | + assert missing_in_entries == set(), f"README links not in ENTRIES.json: {missing_in_entries}" |
| 65 | + assert extra_in_entries == set(), f"ENTRIES.json links not in README: {extra_in_entries}" |
| 66 | + |
| 67 | +def test_readme_build_successful(): |
| 68 | + """ Doc build should run successful as a dry_run """ |
| 69 | + root_path = pathlib.Path(__file__).parent.parent.parent.resolve() |
| 70 | + original_cwd = os.getcwd() |
| 71 | + |
| 72 | + try: |
| 73 | + os.chdir(root_path) |
| 74 | + sys.path.insert(0, str(root_path / "docs")) |
| 75 | + build_body = import_module("build_body") |
| 76 | + build_index = import_module("build_index") |
| 77 | + build_body.main(dry_run=True) |
| 78 | + build_index.main(dry_run=True) |
| 79 | + finally: |
| 80 | + os.chdir(original_cwd) |
| 81 | + sys.path.pop(0) |
| 82 | + |
0 commit comments