Skip to content

Commit dd16cf9

Browse files
committed
work both ways
1 parent afae11a commit dd16cf9

File tree

2 files changed

+40
-17
lines changed

2 files changed

+40
-17
lines changed

snooty/parser.py

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -900,6 +900,15 @@ def handle_composable(self, node: n.ComposableDirective) -> None:
900900
"composable-tutorial", "option_ids", "at least one", node.start[0]
901901
)
902902
)
903+
return
904+
905+
if len(default_ids) != len(option_ids):
906+
self.diagnostics.append(
907+
InvalidChildCount(
908+
"composable-tutorial", "defaults", str(len(option_ids)), node.start[0]
909+
)
910+
)
911+
return
903912

904913
# get the expected composable options from the spec
905914
spec_composables = specparser.Spec.get(
@@ -939,19 +948,7 @@ def handle_composable(self, node: n.ComposableDirective) -> None:
939948
)
940949
continue
941950
ordered_spec_composables.append(composable_from_spec)
942-
try:
943-
specified_default_id = default_ids[index]
944-
except IndexError:
945-
# error to be verbose about default ids not matching up with option ids
946-
self.diagnostics.append(
947-
InvalidChildCount(
948-
"composable-tutorial",
949-
"defaults",
950-
str(len(option_ids)),
951-
node.start[0],
952-
)
953-
)
954-
continue
951+
specified_default_id = default_ids[index]
955952
allowed_values_dict = {
956953
option.id: option for option in composable_from_spec.options
957954
}

snooty/test_postprocess.py

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4273,6 +4273,7 @@ def test_composable_tutorial_errors() -> None:
42734273
MissingChild,
42744274
]
42754275

4276+
# below test has mismatch of options and default ids (defaults has more ids than options)
42764277
with make_test(
42774278
{
42784279
Path(
@@ -4288,10 +4289,35 @@ def test_composable_tutorial_errors() -> None:
42884289
}
42894290
) as result:
42904291
diagnostics = result.diagnostics[FileId("index.txt")]
4291-
assert len(diagnostics) == 1
4292-
assert [type(d) for d in diagnostics] == [
4293-
InvalidChildCount,
4294-
]
4292+
assert len(diagnostics) >= 1
4293+
invalidChildError = next(
4294+
(d for d in diagnostics if isinstance(d, InvalidChildCount)), None
4295+
)
4296+
assert invalidChildError
4297+
assert "defaults" in invalidChildError.message
4298+
4299+
# below test has mismatch of options and default ids (defaults has less ids than options)
4300+
with make_test(
4301+
{
4302+
Path(
4303+
"source/index.txt"
4304+
): """
4305+
.. composable-tutorial::
4306+
:options: interface, language, cluster-topology
4307+
:defaults: driver, None, repl, gcp
4308+
4309+
.. selected-content::
4310+
:selections: driver, None, repl, gcp
4311+
"""
4312+
}
4313+
) as result:
4314+
diagnostics = result.diagnostics[FileId("index.txt")]
4315+
assert len(diagnostics) >= 1
4316+
invalidChildError = next(
4317+
(d for d in diagnostics if isinstance(d, InvalidChildCount)), None
4318+
)
4319+
assert invalidChildError
4320+
assert "defaults" in invalidChildError.message
42954321

42964322

42974323
def test_composable_headings() -> None:

0 commit comments

Comments
 (0)