Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: require core config top- and second-level params to be documented #966

Merged
merged 2 commits into from
Oct 30, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions tests/test_docs.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import importlib
import os
from pathlib import Path
import yaml

import pytest


TOP_PATHS = ["probes", "detectors", "harnesses", "generators", "evaluators", "buffs"]
DOC_SOURCE = os.path.join("docs", "source")

Expand Down Expand Up @@ -165,3 +168,34 @@ def test_root_modules_docs(doc_index_source_text, root_module: str):
assert (
f" {root_module.stem}\n" in doc_index_source_text
), f"root module doc page for {root_module.name} should be linked from doc root index"


def test_core_config_options_explained():
import garak._config

core_config_file_name = (
garak._config.transient.package_dir / "resources" / "garak.core.yaml"
)
l1_nodes_to_check = []
l2_nodes_to_check = []

with open(core_config_file_name, encoding="utf-8") as settings_file:
settings = yaml.safe_load(settings_file)
for top_level_setting in settings:
l1_nodes_to_check.append(top_level_setting)
for second_level_setting in settings[top_level_setting]:
l2_nodes_to_check.append(second_level_setting)

configurable_rst = open(
Path("docs") / "source" / "configurable.rst", "r", encoding="utf-8"
).read()

for l1_node in l1_nodes_to_check:
assert (
f"\n``{l1_node}`` config items\n" in configurable_rst
), f"core config value '{l1_node}' must be documented in configurable.rst"

for l2_node in l2_nodes_to_check:
assert (
f"\n* ``{l2_node}`` - " in configurable_rst
), f"core config value '{l2_node}' must be documented in configurable.rst"
Loading