|
43 | 43 | from docutils import nodes |
44 | 44 | from docutils.parsers.rst import Directive, directives |
45 | 45 | from docutils.statemachine import StringList |
| 46 | +from sphinx.util import logging |
46 | 47 | from sphinx.util.nodes import make_refnode |
47 | 48 |
|
| 49 | +logger = logging.getLogger(__name__) |
| 50 | + |
48 | 51 | # --------------------------------------------------------------------------- |
49 | 52 | # Custom node types |
50 | 53 | # --------------------------------------------------------------------------- |
@@ -309,6 +312,19 @@ def run(self) -> List[nodes.Node]: |
309 | 312 | available = _all_scenarios(feature_abs) |
310 | 313 | scenario_titles = self._requested_scenarios(available) |
311 | 314 |
|
| 315 | + if "scenario" in self.options: |
| 316 | + available_titles = {title for _, title in available} |
| 317 | + requested = [ |
| 318 | + t.strip() for t in self.options["scenario"].splitlines() if t.strip() |
| 319 | + ] |
| 320 | + missing = [t for t in requested if t not in available_titles] |
| 321 | + if missing: |
| 322 | + raise self.error( |
| 323 | + f"Scenario(s) not found in {feature_file}: {', '.join(missing)}" |
| 324 | + ) |
| 325 | + if not scenario_titles: |
| 326 | + raise self.error(f"No scenarios matched in {feature_file}.") |
| 327 | + |
312 | 328 | if self._is_pdf() and "inline" not in self.options: |
313 | 329 | return self._render_pdf(feature_file, feature_abs, scenario_titles) |
314 | 330 |
|
@@ -454,6 +470,12 @@ def resolve_scenario_appendix_refs( |
454 | 470 | else: |
455 | 471 | para += nodes.Text(" in the Appendix.") |
456 | 472 | else: |
| 473 | + logger.warning( |
| 474 | + "PDF build will omit deferred scenario examples because no " |
| 475 | + "'.. scenario-appendix::' directive was found in the document tree; " |
| 476 | + "add it to a page (e.g. an appendix) to include deferred examples.", |
| 477 | + location=ref_node, |
| 478 | + ) |
457 | 479 | para += nodes.Text(f"See \u201c{title}\u201d {examples} in the Appendix.") |
458 | 480 |
|
459 | 481 | ref_node.replace_self(para) |
|
0 commit comments