Skip to content

Commit 8b9214a

Browse files
committed
🧪 TESTS: test hide option in directive
1 parent de2f989 commit 8b9214a

File tree

12 files changed

+215
-0
lines changed

12 files changed

+215
-0
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Minimal makefile for Sphinx documentation
2+
#
3+
4+
# You can set these variables from the command line, and also
5+
# from the environment for the first two.
6+
SPHINXOPTS ?=
7+
SPHINXBUILD ?= sphinx-build
8+
SOURCEDIR = .
9+
BUILDDIR = build
10+
11+
# Put it first so that "make" without argument is like "make help".
12+
help:
13+
@$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
14+
15+
.PHONY: help Makefile
16+
17+
# Catch-all target: route all unknown targets to Sphinx using the new
18+
# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS).
19+
%: Makefile
20+
@$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
_enum_duplicatelabel_hidden
2+
===========================
3+
4+
.. exercise:: duplicate directive 1
5+
:label: ex-hidden-number
6+
:hidden:
7+
8+
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
_enum_hidden
2+
============
3+
4+
.. exercise:: duplicate directive 1
5+
:label: ex-hidden-number
6+
:hidden:
7+
8+
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
_linked_enum_hidden
2+
===================
3+
4+
5+
.. solution:: ex-hidden-number
6+
:label: solution-hidden-label
7+
:hidden:
8+
9+
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
_linked_unenum_hidden
2+
=====================
3+
4+
5+
.. solution:: unenum-hidden
6+
:label: solution-unenum-label
7+
:hidden:
8+
9+
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
_unenum_hidden
2+
==============
3+
4+
.. exercise:: Excepteur sint occaecat
5+
:label: unenum-hidden
6+
:nonumber:
7+
:hidden:
8+
9+
10+
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
# Configuration file for the Sphinx documentation builder.
2+
#
3+
# This file only contains a selection of the most common options. For a full
4+
# list see the documentation:
5+
# https://www.sphinx-doc.org/en/master/usage/configuration.html
6+
7+
# -- Path setup --------------------------------------------------------------
8+
9+
# If extensions (or modules to document with autodoc) are in another directory,
10+
# add these directories to sys.path here. If the directory is relative to the
11+
# documentation root, use os.path.abspath to make it absolute, like shown here.
12+
#
13+
# import os
14+
# import sys
15+
# sys.path.insert(0, os.path.abspath('.'))
16+
17+
18+
# -- Project information -----------------------------------------------------
19+
20+
project = "sphinx-exercise Test"
21+
copyright = "2020, QuantEcon Developers"
22+
author = "QuantEcon Developers"
23+
24+
25+
# -- General configuration ---------------------------------------------------
26+
27+
# Add any Sphinx extension module names here, as strings. They can be
28+
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
29+
# ones.
30+
extensions = ["sphinx_exercise", "myst_nb"]
31+
32+
# Add any paths that contain templates here, relative to this directory.
33+
templates_path = ["_templates"]
34+
35+
# List of patterns, relative to source directory, that match files and
36+
# directories to ignore when looking for source files.
37+
# This pattern also affects html_static_path and html_extra_path.
38+
exclude_patterns = []
39+
40+
41+
# -- Options for HTML output -------------------------------------------------
42+
43+
# The theme to use for HTML and HTML Help pages. See the documentation for
44+
# a list of builtin themes.
45+
#
46+
html_theme = "alabaster"
47+
48+
# Add any paths that contain custom static files (such as style sheets) here,
49+
# relative to this directory. They are copied after the builtin static files,
50+
# so a file named "default.css" will overwrite the builtin "default.css".
51+
# html_static_path = ['_static']
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
Hidding directives
2+
==================
3+
4+
.. toctree::
5+
6+
_enum_hidden
7+
_unenum_hidden
8+
_linked_enum_hidden
9+
_linked_unenum_hidden
10+
_enum_duplicatelabel_hidden
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
@ECHO OFF
2+
3+
pushd %~dp0
4+
5+
REM Command file for Sphinx documentation
6+
7+
if "%SPHINXBUILD%" == "" (
8+
set SPHINXBUILD=sphinx-build
9+
)
10+
set SOURCEDIR=.
11+
set BUILDDIR=build
12+
13+
if "%1" == "" goto help
14+
15+
%SPHINXBUILD% >NUL 2>NUL
16+
if errorlevel 9009 (
17+
echo.
18+
echo.The 'sphinx-build' command was not found. Make sure you have Sphinx
19+
echo.installed, then set the SPHINXBUILD environment variable to point
20+
echo.to the full path of the 'sphinx-build' executable. Alternatively you
21+
echo.may add the Sphinx directory to PATH.
22+
echo.
23+
echo.If you don't have Sphinx installed, grab it from
24+
echo.http://sphinx-doc.org/
25+
exit /b 1
26+
)
27+
28+
%SPHINXBUILD% -M %1 %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O%
29+
goto end
30+
31+
:help
32+
%SPHINXBUILD% -M help %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O%
33+
34+
:end
35+
popd

tests/test_hiddendirective.py

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
from bs4 import BeautifulSoup
2+
import pytest
3+
import shutil
4+
5+
6+
@pytest.mark.sphinx("html", testroot="hiddendirectives")
7+
def test_warning(app, warnings):
8+
"""Test warning thrown during the build"""
9+
build_path = app.srcdir.joinpath("_build")
10+
shutil.rmtree(build_path)
11+
app.build()
12+
13+
assert (
14+
"_enum_hidden.rst: WARNING: duplicate label: ex-hidden-number;"
15+
) in warnings(app)
16+
17+
18+
@pytest.mark.sphinx("html", testroot="hiddendirectives")
19+
@pytest.mark.parametrize(
20+
"idir",
21+
[
22+
"_enum_hidden.html",
23+
"_unenum_hidden.html",
24+
],
25+
)
26+
def test_hidden_exercise(app, idir, file_regression):
27+
"""Test exercise directive markup."""
28+
app.build()
29+
path_to_directive = app.outdir / idir
30+
assert path_to_directive.exists()
31+
32+
# get content markup
33+
soup = BeautifulSoup(path_to_directive.read_text(encoding="utf8"), "html.parser")
34+
exercise = soup.select("div.exercise")
35+
assert len(exercise) == 0
36+
37+
38+
@pytest.mark.sphinx("html", testroot="hiddendirectives")
39+
@pytest.mark.parametrize(
40+
"idir",
41+
[
42+
"_linked_enum_hidden.html",
43+
"_linked_unenum_hidden.html",
44+
],
45+
)
46+
def test_hidden_solution(app, idir, file_regression):
47+
"""Test exercise directive markup."""
48+
app.build()
49+
path_to_directive = app.outdir / idir
50+
assert path_to_directive.exists()
51+
52+
# get content markup
53+
soup = BeautifulSoup(path_to_directive.read_text(encoding="utf8"), "html.parser")
54+
solution = soup.select("div.solution")
55+
assert len(solution) == 0

0 commit comments

Comments
 (0)