Skip to content

Commit ee6720b

Browse files
committed
Update Tests to include errors for gated exercises, and rework
1 parent b157945 commit ee6720b

File tree

12 files changed

+177
-12
lines changed

12 files changed

+177
-12
lines changed

sphinx_exercise/directive.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,7 @@ def run(self):
315315
"end": [],
316316
"sequence": [],
317317
"msg": [],
318+
"type": "exercise",
318319
}
319320
gated_registry[self.env.docname]["start"].append(self.lineno)
320321
gated_registry[self.env.docname]["sequence"].append("S")
@@ -346,6 +347,7 @@ def run(self):
346347
"end": [],
347348
"sequence": [],
348349
"msg": [],
350+
"type": "exercise",
349351
}
350352
gated_registry[self.env.docname]["end"].append(self.lineno)
351353
gated_registry[self.env.docname]["sequence"].append("E")
@@ -383,6 +385,7 @@ def run(self):
383385
"end": [],
384386
"sequence": [],
385387
"msg": [],
388+
"type": "solution",
386389
}
387390
gated_registry[self.env.docname]["start"].append(self.lineno)
388391
gated_registry[self.env.docname]["sequence"].append("S")
@@ -414,6 +417,7 @@ def run(self):
414417
"end": [],
415418
"sequence": [],
416419
"msg": [],
420+
"type": "solution",
417421
}
418422
gated_registry[self.env.docname]["end"].append(self.lineno)
419423
gated_registry[self.env.docname]["sequence"].append("E")

sphinx_exercise/transforms.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,18 +36,19 @@ def check_structure(self, registry):
3636
end = registry[docname]["end"]
3737
sequence = "".join(registry[docname]["sequence"])
3838
structure = "\n ".join(registry[docname]["msg"])
39+
nodetype = registry[docname]["type"]
3940
if len(start) > len(end):
40-
msg = f"The document ({docname}) is missing a solution-end directive\n {structure}" # noqa: E501
41+
msg = f"The document ({docname}) is missing a {nodetype}-end directive\n {structure}" # noqa: E501
4142
logger.error(msg)
4243
error = True
4344
if len(start) < len(end):
44-
msg = f"The document ({docname}) is missing a solution-start directive\n {structure}" # noqa: E501
45+
msg = f"The document ({docname}) is missing a {nodetype}-start directive\n {structure}" # noqa: E501
4546
logger.error(msg)
4647
error = True
4748
if len(start) == len(end):
4849
groups = re.findall("(SE)", sequence)
4950
if len(groups) != len(start):
50-
msg = f"The document ({docname}) contains nested solution-start and solution-end directives\n {structure}" # noqa: E501
51+
msg = f"The document ({docname}) contains nested {nodetype}-start and {nodetype}-end directives\n {structure}" # noqa: E501
5152
logger.error(msg)
5253
error = True
5354
if error:

tests/books/test-gateddirective/conf.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,12 @@
3535
# List of patterns, relative to source directory, that match files and
3636
# directories to ignore when looking for source files.
3737
# This pattern also affects html_static_path and html_extra_path.
38-
exclude_patterns = ["build", "_build", "solution_errors_[1,2,3]*"]
38+
exclude_patterns = [
39+
"build",
40+
"_build",
41+
"exercise_errors_[1,2,3]*",
42+
"solution_errors_[1,2,3]*",
43+
]
3944

4045

4146
# -- Options for HTML output -------------------------------------------------
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
---
2+
jupytext:
3+
text_representation:
4+
extension: .md
5+
format_name: myst
6+
kernelspec:
7+
display_name: Python 3
8+
language: python
9+
name: python3
10+
---
11+
12+
# Exercise Errors 1
13+
14+
Some malformed directives
15+
16+
## Missing `-end` directive
17+
18+
A solution using the gated directive
19+
20+
```{exercise-start}
21+
:label: error-exercise-1
22+
```
23+
24+
Replicate this figure using matplotlib
25+
26+
```{figure} sphx_glr_cohere_001_2_0x.png
27+
```
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
---
2+
jupytext:
3+
text_representation:
4+
extension: .md
5+
format_name: myst
6+
kernelspec:
7+
display_name: Python 3
8+
language: python
9+
name: python3
10+
---
11+
12+
# Exercise Errors 2
13+
14+
Some malformed directives
15+
16+
## Missing `-start` directive
17+
18+
Replicate this figure using matplotlib
19+
20+
```{figure} sphx_glr_cohere_001_2_0x.png
21+
```
22+
23+
```{exercise-end}
24+
```
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
---
2+
jupytext:
3+
text_representation:
4+
extension: .md
5+
format_name: myst
6+
kernelspec:
7+
display_name: Python 3
8+
language: python
9+
name: python3
10+
---
11+
12+
# Errors 3
13+
14+
## Incorrect Nesting of Gated Exercise Directives
15+
16+
```{exercise-start}
17+
```
18+
19+
```{exercise-start}
20+
```
21+
22+
```{exercise-end}
23+
```
24+
25+
```{exercise-end}
26+
```

tests/books/test-gateddirective/solution-exercise.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ kernelspec:
1111

1212
# Gated Solutions to exercise.md
1313

14-
A solution using the gated directives
14+
A solution using the gated directive
1515

1616
```{solution-start} exercise-1
1717
:label: solution-gated-1

tests/books/test-gateddirective/solution_errors_1.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ kernelspec:
99
name: python3
1010
---
1111

12-
# Errors 1
12+
# Solution Errors 1
1313

1414
Some malformed directives
1515

tests/books/test-gateddirective/solution_errors_2.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ kernelspec:
99
name: python3
1010
---
1111

12-
# Errors 2
12+
# Solution Errors 2
1313

1414
Some malformed directives
1515

tests/books/test-gateddirective/solution_errors_3.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ kernelspec:
99
name: python3
1010
---
1111

12-
# Errors 3
12+
# Solution Errors 3
1313

1414
## Incorrect Nesting of Gated Directives
1515

0 commit comments

Comments
 (0)