├── .flake8 ├── .github └── workflows │ └── ci.yml ├── .gitignore ├── .pre-commit-config.yaml ├── .readthedocs.yml ├── CHANGELOG.md ├── LICENSE ├── README.md ├── codecov.yml ├── docs ├── Makefile ├── _static │ └── custom.css ├── make.bat ├── runtime.txt └── source │ ├── conf.py │ ├── developer-design.md │ ├── developer.md │ ├── img │ └── gated-directive-example.png │ ├── index.md │ ├── install.md │ └── syntax.md ├── pyproject.toml ├── pytest.ini ├── sphinx_exercise ├── __init__.py ├── _compat.py ├── assets │ └── html │ │ └── exercise.css ├── directive.py ├── latex.py ├── nodes.py ├── post_transforms.py ├── transforms.py └── utils.py ├── tests ├── books │ ├── test-duplicatelabel │ │ ├── Makefile │ │ ├── conf.py │ │ ├── index.rst │ │ └── make.bat │ ├── test-gateddirective │ │ ├── Makefile │ │ ├── conf.py │ │ ├── exercise-gated.md │ │ ├── exercise.md │ │ ├── exercise_errors_1.md │ │ ├── exercise_errors_2.md │ │ ├── exercise_errors_3.md │ │ ├── index.md │ │ ├── make.bat │ │ ├── solution-exercise-gated.md │ │ ├── solution-exercise.md │ │ ├── solution_errors_1.md │ │ ├── solution_errors_2.md │ │ ├── solution_errors_3.md │ │ └── sphx_glr_cohere_001_2_0x.png │ ├── test-hiddendirectives │ │ ├── Makefile │ │ ├── _enum_duplicatelabel_hidden.rst │ │ ├── _enum_hidden.rst │ │ ├── _linked_enum_hidden.rst │ │ ├── _linked_unenum_hidden.rst │ │ ├── _unenum_hidden.rst │ │ ├── conf.py │ │ ├── index.rst │ │ └── make.bat │ ├── test-mybook │ │ ├── Makefile │ │ ├── conf.py │ │ ├── exercise │ │ │ ├── _enum_duplicate_label.rst │ │ │ ├── _enum_mathtitle_label.rst │ │ │ ├── _enum_notitle_label.rst │ │ │ ├── _enum_numref_mathtitle.rst │ │ │ ├── _enum_numref_notitle.rst │ │ │ ├── _enum_numref_placeholders.rst │ │ │ ├── _enum_numref_title.rst │ │ │ ├── _enum_ref_mathtitle.rst │ │ │ ├── _enum_ref_notitle.rst │ │ │ ├── _enum_ref_title.rst │ │ │ ├── _enum_title_class_label.rst │ │ │ ├── _enum_title_nolabel.rst │ │ │ ├── _unenum_mathtitle_label.rst │ │ │ ├── _unenum_notitle_label.rst │ │ │ ├── _unenum_numref_mathtitle.rst │ │ │ ├── _unenum_numref_notitle.rst │ │ │ ├── _unenum_numref_title.rst │ │ │ ├── _unenum_ref_mathtitle.rst │ │ │ ├── _unenum_ref_notitle.rst │ │ │ ├── _unenum_ref_title.rst │ │ │ ├── _unenum_title_class_label.rst │ │ │ └── _unenum_title_nolabel.rst │ │ ├── index.rst │ │ ├── make.bat │ │ └── solution │ │ │ ├── _linked_duplicate_label.rst │ │ │ ├── _linked_enum.rst │ │ │ ├── _linked_enum_class.rst │ │ │ ├── _linked_missing_arg.rst │ │ │ ├── _linked_ref_enum.rst │ │ │ ├── _linked_ref_unenum_mathtitle.rst │ │ │ ├── _linked_ref_unenum_mathtitle2.rst │ │ │ ├── _linked_ref_unenum_notitle.rst │ │ │ ├── _linked_ref_unenum_title.rst │ │ │ ├── _linked_ref_wronglabel.rst │ │ │ ├── _linked_unenum_mathtitle.rst │ │ │ ├── _linked_unenum_mathtitle2.rst │ │ │ ├── _linked_unenum_notitle.rst │ │ │ ├── _linked_unenum_title.rst │ │ │ └── _linked_wrong_targetlabel.rst │ └── test-simplebook │ │ ├── Makefile │ │ ├── conf.py │ │ ├── exercise.rst │ │ ├── index.rst │ │ ├── make.bat │ │ └── solution.rst ├── conftest.py ├── test_build.py ├── test_duplicatelabel.py ├── test_exercise.py ├── test_exercise │ ├── _enum_duplicate_label.xml │ ├── _enum_mathtitle_label.html │ ├── _enum_mathtitle_label.xml │ ├── _enum_notitle_label.html │ ├── _enum_notitle_label.xml │ ├── _enum_title_class_label.html │ ├── _enum_title_class_label.xml │ ├── _enum_title_nolabel.html │ ├── _enum_title_nolabel.xml │ ├── _unenum_mathtitle_label.html │ ├── _unenum_mathtitle_label.xml │ ├── _unenum_notitle_label.html │ ├── _unenum_notitle_label.xml │ ├── _unenum_title_class_label.html │ ├── _unenum_title_class_label.xml │ ├── _unenum_title_nolabel.html │ └── _unenum_title_nolabel.xml ├── test_exercise_references.py ├── test_exercise_references │ ├── _enum_numref_mathtitle.html │ ├── _enum_numref_mathtitle.xml │ ├── _enum_numref_notitle.html │ ├── _enum_numref_notitle.xml │ ├── _enum_numref_placeholders.html │ ├── _enum_numref_placeholders.xml │ ├── _enum_numref_title.html │ ├── _enum_numref_title.xml │ ├── _enum_ref_mathtitle.html │ ├── _enum_ref_mathtitle.xml │ ├── _enum_ref_notitle.html │ ├── _enum_ref_notitle.xml │ ├── _enum_ref_title.html │ ├── _enum_ref_title.xml │ ├── _unenum_numref_mathtitle.html │ ├── _unenum_numref_mathtitle.xml │ ├── _unenum_numref_notitle.html │ ├── _unenum_numref_notitle.xml │ ├── _unenum_numref_title.html │ ├── _unenum_numref_title.xml │ ├── _unenum_ref_mathtitle.html │ ├── _unenum_ref_mathtitle.xml │ ├── _unenum_ref_notitle.html │ ├── _unenum_ref_notitle.xml │ ├── _unenum_ref_title.html │ └── _unenum_ref_title.xml ├── test_gateddirective.py ├── test_gateddirective │ ├── exercise-gated-0.html │ ├── exercise-gated-1.html │ ├── exercise-gated.xml │ ├── solution-exercise-0.sphinx4.html │ ├── solution-exercise-0.sphinx5.html │ ├── solution-exercise-0.sphinx7.html │ ├── solution-exercise-1.sphinx4.html │ ├── solution-exercise-1.sphinx5.html │ ├── solution-exercise-1.sphinx7.html │ ├── solution-exercise-gated-0.sphinx4.html │ ├── solution-exercise-gated-0.sphinx5.html │ ├── solution-exercise-gated-0.sphinx7.html │ ├── solution-exercise-gated-1.sphinx4.html │ ├── solution-exercise-gated-1.sphinx5.html │ ├── solution-exercise-gated-1.sphinx7.html │ ├── solution-exercise-gated.sphinx4.xml │ ├── solution-exercise-gated.sphinx5.xml │ ├── solution-exercise-gated.sphinx7.xml │ ├── solution-exercise.sphinx4.xml │ ├── solution-exercise.sphinx5.xml │ ├── solution-exercise.sphinx7.xml │ └── solution-exercise.xml ├── test_hiddendirective.py ├── test_hiddendirective │ ├── _enum_hidden.html │ ├── _enum_hidden.xml │ ├── _linked_enum_hidden.xml │ ├── _linked_unenum_hidden.xml │ ├── _unenum_hidden.html │ └── _unenum_hidden.xml ├── test_latex.py ├── test_latex │ ├── test_latex_build.sphinx4.tex │ ├── test_latex_build.sphinx5.tex │ └── test_latex_build.sphinx7.tex ├── test_solution.py ├── test_solution │ ├── _linked_duplicate_label.xml │ ├── _linked_enum.html │ ├── _linked_enum.xml │ ├── _linked_enum_class.html │ ├── _linked_enum_class.xml │ ├── _linked_missing_arg.xml │ ├── _linked_unenum_mathtitle.html │ ├── _linked_unenum_mathtitle.xml │ ├── _linked_unenum_mathtitle2.html │ ├── _linked_unenum_mathtitle2.xml │ ├── _linked_unenum_notitle.html │ ├── _linked_unenum_notitle.xml │ ├── _linked_unenum_title.html │ ├── _linked_unenum_title.xml │ ├── _linked_wrong_targetlabel.html │ └── _linked_wrong_targetlabel.xml ├── test_solution_references.py └── test_solution_references │ ├── _linked_ref_enum.html │ ├── _linked_ref_enum.xml │ ├── _linked_ref_unenum_mathtitle.html │ ├── _linked_ref_unenum_mathtitle.xml │ ├── _linked_ref_unenum_mathtitle2.html │ ├── _linked_ref_unenum_mathtitle2.xml │ ├── _linked_ref_unenum_notitle.html │ ├── _linked_ref_unenum_notitle.xml │ ├── _linked_ref_unenum_title.html │ ├── _linked_ref_unenum_title.xml │ └── _linked_ref_wronglabel.xml └── tox.ini /.flake8: -------------------------------------------------------------------------------- 1 | [flake8] 2 | max-line-length = 88 3 | ignore=E203,W503 4 | -------------------------------------------------------------------------------- /.github/workflows/ci.yml: -------------------------------------------------------------------------------- 1 | name: continuous-integration 2 | 3 | on: 4 | push: 5 | branches: [main] 6 | tags: 7 | - 'v*' 8 | pull_request: 9 | 10 | jobs: 11 | 12 | pre-commit: 13 | runs-on: ubuntu-latest 14 | steps: 15 | - uses: actions/checkout@v4 16 | - name: Set up Python 3.12 17 | uses: actions/setup-python@v4 18 | with: 19 | python-version: "3.12" 20 | - uses: pre-commit/action@v3.0.1 21 | 22 | tests: 23 | runs-on: ubuntu-latest 24 | strategy: 25 | matrix: 26 | python-version: ["3.11", "3.12"] 27 | steps: 28 | - uses: actions/checkout@v4 29 | - name: Set up Python ${{ matrix.python-version }} 30 | uses: actions/setup-python@v4 31 | with: 32 | python-version: ${{ matrix.python-version }} 33 | - name: Install dependencies 34 | run : | 35 | python -m pip install --upgrade pip 36 | pip install -e.[testing] 37 | - name: Run pytest 38 | run: | 39 | pytest --durations=10 --cov=sphinx_exercise --cov-report=xml --cov-report=term-missing 40 | - name: Create cov 41 | run: coverage xml 42 | - name: Upload to Codecov 43 | if: false && (matrix.python-version == '3.11') 44 | uses: codecov/codecov-action@v4 45 | with: 46 | name: sphinx-exercise-pytest-py3.11 47 | token: "${{ secrets.CODECOV_TOKEN }}" 48 | flags: pytests 49 | file: ./coverage.xml 50 | fail_ci_if_error: true 51 | 52 | docs: 53 | name: Documentation build 54 | runs-on: ubuntu-latest 55 | steps: 56 | - uses: actions/checkout@v4 57 | - name: Set up Python 3.11 58 | uses: actions/setup-python@v4 59 | with: 60 | python-version: "3.11" 61 | - name: Install dependencies 62 | run: | 63 | python -m pip install --upgrade pip 64 | pip install -e .[rtd] 65 | - name: Build docs 66 | run: | 67 | cd docs 68 | make clean 69 | make html 70 | 71 | publish: 72 | name: Publish to PyPi 73 | needs: [pre-commit, tests, docs] 74 | if: github.event_name == 'push' && startsWith(github.event.ref, 'refs/tags') 75 | runs-on: ubuntu-latest 76 | steps: 77 | - name: Checkout source 78 | uses: actions/checkout@v4 79 | - name: Set up Python 3.11 80 | uses: actions/setup-python@v4 81 | with: 82 | python-version: "3.11" 83 | - name: Build package 84 | run: | 85 | pip install wheel build 86 | python -m build 87 | - name: Publish 88 | uses: pypa/gh-action-pypi-publish@v1.3.1 89 | with: 90 | user: __token__ 91 | password: ${{ secrets.PYPI_KEY }} 92 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | docs/build/ 2 | __pycache__ 3 | *.egg-info/ 4 | *.pyc 5 | .DS_Store 6 | .vscode/ 7 | build/ 8 | dist/ 9 | 10 | # Unit test / coverage reports 11 | 12 | .coverage 13 | coverage.* 14 | coverage.xml 15 | .tox/ 16 | .venv 17 | -------------------------------------------------------------------------------- /.pre-commit-config.yaml: -------------------------------------------------------------------------------- 1 | # Install pre-commit hooks via 2 | # pre-commit install 3 | 4 | exclude: > 5 | (?x)^( 6 | \.vscode/settings\.json| 7 | docs/source/conf\.py| 8 | tests/test_exercise/.*| 9 | tests/test_exercise_references/.*| 10 | tests/test_solution/.*| 11 | tests/test_solution_references/.*| 12 | tests/test_hiddendirective/.*| 13 | tests/test_gateddirective/.*| 14 | )$ 15 | 16 | repos: 17 | 18 | - repo: https://github.com/pre-commit/pre-commit-hooks 19 | rev: v4.3.0 20 | hooks: 21 | - id: check-yaml 22 | - id: end-of-file-fixer 23 | - id: trailing-whitespace 24 | 25 | - repo: https://github.com/astral-sh/ruff-pre-commit 26 | rev: v0.1.4 27 | hooks: 28 | - id: ruff 29 | args: ["--fix", "--show-fixes"] 30 | - id: ruff-format 31 | -------------------------------------------------------------------------------- /.readthedocs.yml: -------------------------------------------------------------------------------- 1 | # .readthedocs.yml 2 | # Read the Docs configuration file 3 | # See https://docs.readthedocs.io/en/stable/config-file/v2.html for details 4 | 5 | # Required 6 | version: 2 7 | 8 | # Build documentation in the docs/ directory with Sphinx 9 | sphinx: 10 | configuration: docs/source/conf.py 11 | 12 | python: 13 | version: 3.7 14 | install: 15 | - method: pip 16 | path: . 17 | extra_requirements: 18 | - rtd 19 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2020 ExecutableBookProject 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # sphinx-exercise 2 | 3 | [![Documentation Status][rtd-badge]][rtd-link] 4 | [![Github-CI][github-ci]][github-link] 5 | [![Coverage Status][codecov-badge]][codecov-link] 6 | 7 | **An exercise extension for Sphinx**. 8 | 9 | This package contains a [Sphinx](http://www.sphinx-doc.org/en/master/) extension 10 | for producing exercise and solution directives. 11 | 12 | 13 | ## Get started 14 | 15 | To get started with `sphinx-exercise`, first install it through `pip`: 16 | 17 | ``` 18 | pip install sphinx-exercise 19 | ``` 20 | 21 | then, add `sphinx_exercise` to your sphinx `extensions` in the `conf.py` 22 | 23 | ```python 24 | ... 25 | extensions = ["sphinx_exercise"] 26 | ... 27 | ``` 28 | 29 | 30 | ## Documentation 31 | 32 | See the [Sphinx Exercise documentation](https://ebp-sphinx-exercise.readthedocs.io/en/latest/) for more information. 33 | 34 | 35 | ## Contributing 36 | 37 | We welcome all contributions! See the [EBP Contributing Guide](https://executablebooks.org/en/latest/contributing.html) for general details, and below for guidance specific to sphinx-exercise. 38 | 39 | 40 | [rtd-badge]: https://readthedocs.org/projects/ebp-sphinx-exercise/badge/?version=latest 41 | [rtd-link]: https://ebp-sphinx-exercise.readthedocs.io/en/latest/?badge=latest 42 | [github-ci]: https://github.com/executablebooks/sphinx-exercise/workflows/continuous-integration/badge.svg?branch=master 43 | [github-link]: https://github.com/executablebooks/sphinx-exercise 44 | [codecov-badge]: https://codecov.io/gh/executablebooks/sphinx-exercise/branch/master/graph/badge.svg 45 | [codecov-link]: https://codecov.io/gh/executablebooks/sphinx-exercise 46 | -------------------------------------------------------------------------------- /codecov.yml: -------------------------------------------------------------------------------- 1 | coverage: 2 | status: 3 | project: 4 | default: 5 | target: 85% 6 | threshold: 0.5% 7 | patch: 8 | default: 9 | target: 80% 10 | threshold: 0.5% 11 | -------------------------------------------------------------------------------- /docs/Makefile: -------------------------------------------------------------------------------- 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 = source 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) 21 | -------------------------------------------------------------------------------- /docs/_static/custom.css: -------------------------------------------------------------------------------- 1 | /********************************************* 2 | * Change the color of orange named objects * 3 | *********************************************/ 4 | 5 | :root { 6 | --background-color: rgba(253, 126, 20, .3); 7 | --border-color: #fd7e14; 8 | } 9 | 10 | div.orange { 11 | background-color: var(--background-color); 12 | border-color: var(--border-color); 13 | } 14 | 15 | div.orange p.admonition-title { 16 | background-color: var(--background-color); 17 | } 18 | -------------------------------------------------------------------------------- /docs/make.bat: -------------------------------------------------------------------------------- 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=source 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 36 | -------------------------------------------------------------------------------- /docs/runtime.txt: -------------------------------------------------------------------------------- 1 | 3.11 2 | -------------------------------------------------------------------------------- /docs/source/conf.py: -------------------------------------------------------------------------------- 1 | # -- Project information ----------------------------------------------------- 2 | 3 | project = "sphinx-exercise" 4 | copyright = "2020-2021, Executable Book Developers" 5 | author = "Executable Book Developers" 6 | master_doc = "index" 7 | 8 | 9 | # -- General configuration --------------------------------------------------- 10 | 11 | # Add any Sphinx extension module names here, as strings. They can be 12 | # extensions coming with Sphinx (named "sphinx.ext.*") or your custom 13 | # ones. 14 | extensions = ["sphinx_exercise", "myst_nb", "sphinx_togglebutton"] 15 | 16 | # Add any paths that contain templates here, relative to this directory. 17 | templates_path = ["_templates"] 18 | 19 | # List of patterns, relative to source directory, that match files and 20 | # directories to ignore when looking for source files. 21 | # This pattern also affects html_static_path and html_extra_path. 22 | exclude_patterns = ["_build"] 23 | html_static_path = ["../_static"] 24 | html_css_files = ["custom.css"] 25 | 26 | # -- Options for HTML output ------------------------------------------------- 27 | 28 | # The theme to use for HTML and HTML Help pages. See the documentation for 29 | # a list of builtin themes. 30 | # 31 | html_theme = "sphinx_book_theme" 32 | 33 | 34 | # Add any paths that contain custom static files (such as style sheets) here, 35 | # relative to this directory. They are copied after the builtin static files, 36 | # so a file named "default.css" will overwrite the builtin "default.css". 37 | # html_static_path = ["_static"] 38 | 39 | html_theme_options = { 40 | "path_to_docs": "docs", 41 | "repository_url": "https://github.com/executablebooks/sphinx-exercise", 42 | "use_edit_page_button": True, 43 | "use_issues_button": True, 44 | "use_repository_button": True, 45 | } 46 | -------------------------------------------------------------------------------- /docs/source/developer-design.md: -------------------------------------------------------------------------------- 1 | # Design of the Package 2 | 3 | This page documents some design decisions that were made when building this 4 | `sphinx` extension. 5 | 6 | `sphinx-exercise` includes: 7 | 8 | 1. `directives` 9 | 2. `nodes` 10 | 3. `post_transforms` 11 | 4. integrations with `sphinx.env` 12 | 13 | ## Directives 14 | 15 | See [](syntax.md) for futher details on the available directives and options 16 | 17 | ## Nodes 18 | 19 | The nodes support the directives: 20 | 21 | 1. `exercise_node` 22 | 1. `exercise_enumerable_node` 23 | 1. `solution_node` 24 | 25 | as well as custom title infrastructure: 26 | 27 | 1. `exercise_title` 28 | 1. `exercise_subtitle` 29 | 1. `solution_title` 30 | 1. `solution_subtitle` 31 | 32 | and support for `:numref:` references to enumerated exercise nodes 33 | in the LaTeX context by resolving the node title numbering: 34 | 35 | 1. `exercise_latex_number_reference` 36 | 37 | The `title` and `reference` nodes are used internally by the 38 | `directives` and are then removed in `post_transforms` negating the need 39 | for any custom `translator` methods. The use 40 | of custom nodes allows for simpler detection of objects by this 41 | extension, rather than catering for additional items that may be added by other 42 | sphinx components. 43 | 44 | ## Post Transforms 45 | 46 | The `post_transforms` run in the following order: 47 | 48 | 1. UpdateReferencesToEnumerated (priority = 5, before `pending_xref` are resolved) 49 | 2. ResolveTitlesInExercises (priority = 20) 50 | 3. ResolveTitlesInSolutions (priority = 21) 51 | 4. ResolveLinkTextToSolutions (priority = 22) 52 | 53 | These `post_transforms` are setup to resolve in `Exercise` -> `Solution` -> `References` 54 | ordering. Any `:ref:` made to an enumerated `exercise` node are converted into `numref` 55 | references prior to `pending_xref` objects are resolved by `sphinx`. 56 | 57 | This is aligned with most use cases in a document. In the case of `solutions` 58 | if the target node (title) has not been resolved, this is checked and then resolved 59 | as required. 60 | 61 | **Design Decision:** It was decided to integrate with `:ref:` and `:numref:` roles 62 | to support both reference styles to `exercise` and `solution` directives. 63 | The `post_transforms` are required to make adjustments the the `sphinx` abstract 64 | syntax tree (AST) to support `:numref:` and the resolve `titles` 65 | in `exercise` and `solution` admonitions. This is required as components of 66 | `numref` are resolved at the `translator` phase for `html` and is activated 67 | essentially by default for LaTeX but leaves the numbering to the `LaTeX` 68 | builder such as `pdflatex`. 69 | 70 | ## Additional Notes 71 | 72 | ### Package Registry `sphinx.env.sphinx_exercise_registry` 73 | 74 | This package includes a registry of all `exercise` and `solution` 75 | nodes that are parsed. 76 | 77 | This registry includes nodes referenced by their `label`: 78 | 79 | ```python 80 | self.env.sphinx_exercise_registry[label] = { 81 | "type": self.name, 82 | "docname": self.env.docname, 83 | "node": node, 84 | } 85 | ``` 86 | 87 | and records the `type`, `docname` where the node is parsed, and 88 | the `node` object. 89 | -------------------------------------------------------------------------------- /docs/source/developer.md: -------------------------------------------------------------------------------- 1 | # Developers 2 | 3 | Development of this package follows the following conventions and styles. 4 | 5 | Design notes and considerations can be found in [](developer-design.md) 6 | 7 | ## Install 8 | 9 | To install the package in `develop` mode: 10 | 11 | ```shell 12 | cd sphinx-exercise 13 | pip install -e . 14 | ``` 15 | 16 | ## Testing 17 | 18 | For code tests, `sphinx-exercise` uses [pytest](https://docs.pytest.org/). 19 | 20 | Run the tests with the following command: 21 | 22 | ```shell 23 | >> cd sphinx-exercise 24 | >> pip install -e .[testing] 25 | >> pytest 26 | ``` 27 | 28 | To run the tests in multiple isolated environments, you can also run [tox](https://tox.readthedocs.io/) 29 | 30 | ```shell 31 | >> cd sphinx-exercise 32 | >> tox 33 | ``` 34 | 35 | To test the build of documentation run 36 | 37 | ```shell 38 | >> cd sphinx-exercise 39 | >> tox docs-update 40 | ``` 41 | 42 | or 43 | 44 | ```shell 45 | >> cd sphinx-exercise/docs 46 | >> make clean 47 | >> make html 48 | ``` 49 | 50 | ## Unit Testing 51 | 52 | We use [pytest](https://docs.pytest.org/en/latest/) for testing, [pytest-regression](https://pytest-regressions.readthedocs.io/en/latest/) to regenerate expected outcomes of test and [pytest-cov](https://pytest-cov.readthedocs.io/en/latest/) for checking coverage. 53 | 54 | To run tests with coverage and an html coverage report: 55 | 56 | ```bash 57 | pytest -v --cov=sphinx_exercise --cov-report=html 58 | ``` 59 | 60 | ## Writing Tests 61 | 62 | The module `sphinx.testing` is used to run sphinx builds for tests, in a temporary directory. 63 | 64 | If creating a new source folder for test files, folder name should start with `test-`. 65 | Your folder should reside inside the `tests/books` directory, which has been set as the root directory for tests. 66 | 67 | The tests should start with: 68 | 69 | ```python 70 | @pytest.mark.sphinx('html', testroot="mybook") 71 | ``` 72 | In the above declaration, `html` builder is used. And `mybook` is the source folder which was created with the name `test-mybook` inside `tests/books` folder. 73 | 74 | Sphinx Application API is available as a parameter to all the test functions: 75 | 76 | ```python 77 | @pytest.mark.sphinx('html', testroot="mybook") 78 | def mytest(app): 79 | ``` 80 | -------------------------------------------------------------------------------- /docs/source/img/gated-directive-example.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/executablebooks/sphinx-exercise/a098092db826e45b808d2ce0409f987382d0d038/docs/source/img/gated-directive-example.png -------------------------------------------------------------------------------- /docs/source/index.md: -------------------------------------------------------------------------------- 1 | # sphinx-exercise 2 | 3 | ```{toctree} 4 | :hidden: 5 | 6 | install 7 | syntax 8 | developer 9 | developer-design 10 | ``` 11 | 12 | 13 | [![Documentation Status][rtd-badge]][rtd-link] 14 | [![Github-CI][github-ci]][github-link] 15 | [![Coverage Status][codecov-badge]][codecov-link] 16 | 17 | **An exercise extension for Sphinx**. 18 | 19 | This package contains a [Sphinx](http://www.sphinx-doc.org/en/master/) extension 20 | for producing exercise and solution directives, for html and pdf outputs. 21 | 22 | **Features**: 23 | 24 | The **exercise** directive is: 25 | 26 | 1. automatically numbered 27 | 2. supports options such as `class`, `label`, `nonumber`, and `hidden` 28 | 3. can be referenced through `ref` and `numref` roles 29 | 30 | The **solution** directive 31 | 32 | 1. supports options such as `class`, `label`, and `hidden` 33 | 2. can be referenced through `ref` role 34 | 35 | (getting-started)= 36 | ## Getting Started 37 | 38 | To get started with `sphinx-exercise`, first install it through `pip`: 39 | 40 | ```bash 41 | pip install sphinx-exercise 42 | ``` 43 | 44 | ### Jupyter-Book Project 45 | 46 | Add `sphinx_exercise` to your [extra_extensions](https://jupyterbook.org/advanced/sphinx.html#custom-sphinx-extensions) config in `_config.yml` 47 | 48 | ```yaml 49 | sphinx: 50 | extra_extensions: 51 | - sphinx_exercise 52 | ``` 53 | 54 | you may then use `jb build ` and the extension will be used by your `Jupyter Book` project. 55 | 56 | ### Sphinx Project 57 | 58 | Add `sphinx_exercise` to your sphinx `extensions` in the `conf.py` 59 | 60 | ```python 61 | ... 62 | extensions = ["sphinx_exercise"] 63 | ... 64 | ``` 65 | 66 | you may then build using `make html` and the extension will be used by your `Sphinx` project. 67 | 68 | 69 | 70 | [rtd-badge]: https://readthedocs.org/projects/ebp-sphinx-exercise/badge/?version=latest 71 | [rtd-link]: https://ebp-sphinx-exercise.readthedocs.io/en/latest/?badge=latest 72 | [github-ci]: https://github.com/executablebooks/sphinx-exercise/workflows/continuous-integration/badge.svg?branch=master 73 | [github-link]: https://github.com/executablebooks/sphinx-exercise 74 | [codecov-badge]: https://codecov.io/gh/executablebooks/sphinx-exercise/branch/master/graph/badge.svg 75 | [codecov-link]: https://codecov.io/gh/executablebooks/sphinx-exercise 76 | -------------------------------------------------------------------------------- /docs/source/install.md: -------------------------------------------------------------------------------- 1 | # Installation 2 | 3 | The **recommended** method of installation for most users is via `pip` as detailed 4 | in {ref}`getting-started`. 5 | 6 | You can also install directly from the repository to get the latest `development` version 7 | 8 | ## Latest Version 9 | 10 | You can clone the repository: 11 | 12 | ```bash 13 | git clone https://github.com/executablebooks/sphinx-exercise 14 | ``` 15 | 16 | then run: 17 | 18 | ```bash 19 | python setup.py install 20 | ``` 21 | -------------------------------------------------------------------------------- /pyproject.toml: -------------------------------------------------------------------------------- 1 | [build-system] 2 | requires = ["hatchling"] 3 | build-backend = "hatchling.build" 4 | 5 | [project] 6 | name = "sphinx-exercise" 7 | dynamic = ["version"] 8 | description = "A Sphinx extension for producing exercises and solutions." 9 | readme = "README.md" 10 | license = { file = "LICENSE" } 11 | requires-python = ">=3.9" 12 | authors = [ 13 | { name = "QuantEcon", email = "admin@quantecon.org" }, 14 | ] 15 | classifiers = [ 16 | "Development Status :: 4 - Beta", 17 | "Environment :: Plugins", 18 | "Environment :: Web Environment", 19 | "Framework :: Sphinx :: Extension", 20 | "Intended Audience :: Developers", 21 | "License :: OSI Approved :: MIT License", 22 | "Natural Language :: English", 23 | "Operating System :: OS Independent", 24 | "Programming Language :: Python", 25 | "Programming Language :: Python :: 3.9", 26 | "Programming Language :: Python :: 3.10", 27 | "Programming Language :: Python :: 3.11", 28 | "Programming Language :: Python :: 3.12", 29 | "Topic :: Documentation", 30 | "Topic :: Documentation :: Sphinx", 31 | "Topic :: Software Development :: Documentation", 32 | "Topic :: Text Processing", 33 | "Topic :: Utilities", 34 | ] 35 | dependencies = [ 36 | "sphinx-book-theme", 37 | "sphinx>=5", 38 | ] 39 | 40 | [project.optional-dependencies] 41 | all = [ 42 | "sphinx-exercise[code_style]", 43 | "sphinx-exercise[rtd]", 44 | "sphinx-exercise[testing]" 45 | ] 46 | code_style = [ 47 | "black", 48 | "flake8<3.8.0,>=3.7.0", 49 | "pre-commit", 50 | ] 51 | rtd = [ 52 | "myst-nb~=1.0.0", 53 | "sphinx-book-theme", 54 | "sphinx_togglebutton", 55 | "sphinx>=5,<8", 56 | ] 57 | testing = [ 58 | "beautifulsoup4", 59 | "coverage", 60 | "matplotlib==3.8.*", 61 | "myst-nb~=1.0.0", 62 | "pytest-cov", 63 | "pytest-regressions", 64 | "pytest~=8.0.0", 65 | "sphinx>=5,<8", 66 | "texsoup", 67 | "defusedxml", # Required by sphinx-testing 68 | ] 69 | 70 | [project.urls] 71 | Homepage = "https://github.com/executablebooks/sphinx-exercise" 72 | Source = "https://github.com/executablebooks/sphinx-exercise" 73 | Tracker = "https://github.com/executablebooks/sphinx-exercise/issues" 74 | 75 | [tool.hatch.version] 76 | path = "sphinx_exercise/__init__.py" 77 | -------------------------------------------------------------------------------- /pytest.ini: -------------------------------------------------------------------------------- 1 | [pytest] 2 | testpaths = tests/ 3 | markers = 4 | sphinx: set parameters for the sphinx `app` fixture (see ipypublish/sphinx/tests/conftest.py) 5 | -------------------------------------------------------------------------------- /sphinx_exercise/_compat.py: -------------------------------------------------------------------------------- 1 | from docutils.nodes import Element 2 | from typing import Iterator 3 | 4 | 5 | def findall(node: Element, *args, **kwargs) -> Iterator[Element]: 6 | # findall replaces traverse in docutils v0.18 7 | # note a difference is that findall is an iterator 8 | impl = getattr(node, "findall", node.traverse) 9 | return iter(impl(*args, **kwargs)) 10 | -------------------------------------------------------------------------------- /sphinx_exercise/assets/html/exercise.css: -------------------------------------------------------------------------------- 1 | /********************************************* 2 | * Variables * 3 | *********************************************/ 4 | :root { 5 | --note-title-color: rgba(68,138,255,.1); 6 | --note-border-color: #007bff; 7 | --grey-border-color: #ccc; 8 | } 9 | 10 | /********************************************* 11 | * Exercise * 12 | *********************************************/ 13 | div.exercise { 14 | border-color: var(--note-border-color); 15 | background-color: var(--note-title-color); 16 | } 17 | 18 | div.exercise p.admonition-title { 19 | background-color: var(--note-title-color); 20 | } 21 | 22 | /* Remove content box */ 23 | div.exercise p.admonition-title::after { 24 | content: "\f303"; 25 | } 26 | 27 | /********************************************* 28 | * Solution * 29 | *********************************************/ 30 | div.solution{ 31 | border-color: var(--grey-border-color); 32 | background-color: none; 33 | } 34 | 35 | div.solution p.admonition-title { 36 | background-color: transparent; 37 | text-decoration: none; 38 | } 39 | 40 | /* Remove content box */ 41 | div.solution p.admonition-title::after { 42 | content: none; 43 | } 44 | -------------------------------------------------------------------------------- /sphinx_exercise/latex.py: -------------------------------------------------------------------------------- 1 | # Support for LaTeX Markup 2 | 3 | 4 | class LaTeXMarkup(object): 5 | CR = "\n" 6 | 7 | def visit_admonition(self): 8 | # latex_admonition_start 9 | return self.CR + "\\begin{sphinxadmonition}{note}" 10 | 11 | def depart_admonition(self): 12 | # latex_admonition_end 13 | return "\\end{sphinxadmonition}" + self.CR 14 | -------------------------------------------------------------------------------- /sphinx_exercise/nodes.py: -------------------------------------------------------------------------------- 1 | """ 2 | sphinx_exercise.nodes 3 | ~~~~~~~~~~~~~~~~~~~~~ 4 | 5 | Sphinx Exercise Nodes 6 | 7 | :copyright: Copyright 2020-2021 by the Executable Books team, see AUTHORS 8 | :licences: see LICENSE for details 9 | """ 10 | 11 | from sphinx.util import logging 12 | from docutils.nodes import Node 13 | from docutils import nodes as docutil_nodes 14 | from sphinx import addnodes as sphinx_nodes 15 | from sphinx.writers.latex import LaTeXTranslator 16 | from .latex import LaTeXMarkup 17 | 18 | logger = logging.getLogger(__name__) 19 | LaTeX = LaTeXMarkup() 20 | 21 | 22 | # Nodes 23 | 24 | 25 | class exercise_node(docutil_nodes.Admonition, docutil_nodes.Element): 26 | gated = False 27 | 28 | 29 | class exercise_enumerable_node(docutil_nodes.Admonition, docutil_nodes.Element): 30 | gated = False 31 | resolved_title = False 32 | 33 | 34 | class exercise_end_node(docutil_nodes.Admonition, docutil_nodes.Element): 35 | pass 36 | 37 | 38 | class solution_node(docutil_nodes.Admonition, docutil_nodes.Element): 39 | resolved_title = False 40 | 41 | 42 | class solution_start_node(docutil_nodes.Admonition, docutil_nodes.Element): 43 | resolved_title = False 44 | 45 | 46 | class solution_end_node(docutil_nodes.Admonition, docutil_nodes.Element): 47 | resolved_title = False # TODO: is this required? 48 | 49 | 50 | class exercise_title(docutil_nodes.title): 51 | def default_title(self): 52 | title_text = self.children[0].astext() 53 | if title_text == "Exercise" or title_text == "Exercise %s": 54 | return True 55 | else: 56 | return False 57 | 58 | 59 | class exercise_subtitle(docutil_nodes.subtitle): 60 | pass 61 | 62 | 63 | class solution_title(docutil_nodes.title): 64 | def default_title(self): 65 | title_text = self.children[0].astext() 66 | if title_text == "Solution to": 67 | return True 68 | else: 69 | return False 70 | 71 | 72 | class solution_subtitle(docutil_nodes.subtitle): 73 | pass 74 | 75 | 76 | class exercise_latex_number_reference(sphinx_nodes.number_reference): 77 | pass 78 | 79 | 80 | # Test Node Functions 81 | 82 | 83 | def is_exercise_node(node): 84 | return isinstance(node, exercise_node) or isinstance(node, exercise_enumerable_node) 85 | 86 | 87 | def is_exercise_enumerable_node(node): 88 | return isinstance(node, exercise_enumerable_node) 89 | 90 | 91 | def is_solution_node(node): 92 | return isinstance(node, solution_node) 93 | 94 | 95 | def is_extension_node(node): 96 | return ( 97 | is_exercise_node(node) 98 | or is_exercise_enumerable_node(node) 99 | or is_solution_node(node) 100 | ) 101 | 102 | 103 | # Visit and Depart Functions 104 | 105 | 106 | def visit_exercise_node(self, node: Node) -> None: 107 | if isinstance(self, LaTeXTranslator): 108 | label = ( 109 | "\\phantomsection \\label{" + f"exercise:{node.attributes['label']}" + "}" 110 | ) # TODO: Check this resolves. 111 | self.body.append(label) 112 | self.body.append(LaTeX.visit_admonition()) 113 | else: 114 | self.body.append(self.starttag(node, "div", CLASS="admonition")) 115 | self.body.append("\n") 116 | 117 | 118 | def depart_exercise_node(self, node: Node) -> None: 119 | if isinstance(self, LaTeXTranslator): 120 | self.body.append(LaTeX.depart_admonition()) 121 | else: 122 | self.body.append("") 123 | 124 | 125 | def visit_exercise_enumerable_node(self, node: Node) -> None: 126 | """ 127 | LaTeX Reference Structure is exercise:{label} and resolved by 128 | exercise_latex_number_reference nodes (see below) 129 | """ 130 | if isinstance(self, LaTeXTranslator): 131 | label = ( 132 | "\\phantomsection \\label{" + f"exercise:{node.attributes['label']}" + "}\n" 133 | ) 134 | self.body.append(label) 135 | self.body.append(LaTeX.visit_admonition()) 136 | else: 137 | self.body.append(self.starttag(node, "div", CLASS="admonition")) 138 | self.body.append("\n") 139 | 140 | 141 | def depart_exercise_enumerable_node(self, node: Node) -> None: 142 | if isinstance(self, LaTeXTranslator): 143 | self.body.append(LaTeX.depart_admonition()) 144 | else: 145 | self.body.append("") 146 | self.body.append("\n") 147 | 148 | 149 | def visit_solution_node(self, node: Node) -> None: 150 | """ 151 | Reference Structure is {docname}:{label} and resolved by Sphinx 152 | """ 153 | if isinstance(self, LaTeXTranslator): 154 | target_label = node.attributes["label"] 155 | target_node = self.builder.env.sphinx_exercise_registry[target_label] 156 | docname = target_node.get("docname") 157 | label = ( 158 | "\\phantomsection \\label{" 159 | + f"{docname}:{node.attributes['label']}" 160 | + "}\n" 161 | ) 162 | self.body.append(label) 163 | self.body.append(LaTeX.visit_admonition()) 164 | else: 165 | self.body.append(self.starttag(node, "div", CLASS="admonition")) 166 | self.body.append("\n") 167 | 168 | 169 | def depart_solution_node(self, node: Node) -> None: 170 | if isinstance(self, LaTeXTranslator): 171 | self.body.append(LaTeX.depart_admonition()) 172 | else: 173 | self.body.append("") 174 | self.body.append("\n") 175 | 176 | 177 | def visit_exercise_latex_number_reference(self, node): 178 | id = node.get("refid") 179 | text = node.astext() 180 | hyperref = r"\hyperref[exercise:%s]{%s}" % (id, text) 181 | self.body.append(hyperref) 182 | raise docutil_nodes.SkipNode 183 | 184 | 185 | def depart_exercise_latex_number_reference(self, node): 186 | pass 187 | -------------------------------------------------------------------------------- /sphinx_exercise/utils.py: -------------------------------------------------------------------------------- 1 | # Utility functions 2 | 3 | from sphinx.writers.latex import LaTeXTranslator 4 | 5 | 6 | def find_parent(env, node, parent_tag): 7 | """Find the nearest parent node with the given tagname.""" 8 | 9 | while True: 10 | node = node.parent 11 | if node is None: 12 | return None 13 | # parent should be a document in toc 14 | if ( 15 | "docname" in node.attributes 16 | and env.titles[node.attributes["docname"]].astext().lower() 17 | in node.attributes["names"] 18 | ): 19 | return node.attributes["docname"] 20 | 21 | 22 | def get_node_number(self, node, typ) -> str: 23 | """Get the number for the directive node for HTML.""" 24 | 25 | ids = node.attributes.get("ids", [])[0] 26 | if isinstance(self, LaTeXTranslator): 27 | docname = find_parent(self.builder.env, node, "section") 28 | else: 29 | docname = node.attributes.get("docname", "") 30 | # Latex does not have builder.fignumbers 31 | fignumbers = self.builder.env.toc_fignumbers.get(docname, {}) 32 | number = fignumbers.get(typ, {}).get(ids, ()) 33 | return ".".join(map(str, number)) 34 | -------------------------------------------------------------------------------- /tests/books/test-duplicatelabel/Makefile: -------------------------------------------------------------------------------- 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) 21 | -------------------------------------------------------------------------------- /tests/books/test-duplicatelabel/conf.py: -------------------------------------------------------------------------------- 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'] 52 | -------------------------------------------------------------------------------- /tests/books/test-duplicatelabel/index.rst: -------------------------------------------------------------------------------- 1 | index 2 | ===== 3 | 4 | .. exercise:: Test exercise directive 5 | :label: label-1 6 | 7 | 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. 8 | 9 | 10 | .. exercise:: 11 | :label: label-1 12 | 13 | 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. 14 | 15 | 16 | .. solution:: label-1 17 | :label: label-2 18 | 19 | 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. 20 | 21 | 22 | .. solution:: label-1 23 | :label: label-2 24 | 25 | 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. 26 | -------------------------------------------------------------------------------- /tests/books/test-duplicatelabel/make.bat: -------------------------------------------------------------------------------- 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 36 | -------------------------------------------------------------------------------- /tests/books/test-gateddirective/Makefile: -------------------------------------------------------------------------------- 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) 21 | -------------------------------------------------------------------------------- /tests/books/test-gateddirective/conf.py: -------------------------------------------------------------------------------- 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" 21 | copyright = "2020-2021, Executable Book Developers" 22 | author = "Executable Book 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 | "build", 40 | "_build", 41 | "exercise_errors_[1,2,3]*", 42 | "solution_errors_[1,2,3]*", 43 | ] 44 | 45 | 46 | # -- Options for HTML output ------------------------------------------------- 47 | 48 | # The theme to use for HTML and HTML Help pages. See the documentation for 49 | # a list of builtin themes. 50 | # 51 | html_theme = "sphinx_book_theme" 52 | 53 | # Add any paths that contain custom static files (such as style sheets) here, 54 | # relative to this directory. They are copied after the builtin static files, 55 | # so a file named "default.css" will overwrite the builtin "default.css". 56 | # html_static_path = ['_static'] 57 | -------------------------------------------------------------------------------- /tests/books/test-gateddirective/exercise-gated.md: -------------------------------------------------------------------------------- 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 | # Gated Exercises 13 | 14 | Some Gated reference exercises 15 | 16 | ```{exercise-start} 17 | :label: gated-exercise-1 18 | ``` 19 | 20 | Replicate this figure using matplotlib 21 | 22 | ```{figure} sphx_glr_cohere_001_2_0x.png 23 | ``` 24 | 25 | ```{exercise-end} 26 | ``` 27 | 28 | and another version with a title embedded 29 | 30 | 31 | ```{exercise-start} Replicate Matplotlib Plot 32 | :label: gated-exercise-2 33 | ``` 34 | 35 | ```{figure} sphx_glr_cohere_001_2_0x.png 36 | ``` 37 | 38 | ```{exercise-end} 39 | ``` 40 | -------------------------------------------------------------------------------- /tests/books/test-gateddirective/exercise.md: -------------------------------------------------------------------------------- 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 | # Non-Gated Exercises 13 | 14 | Some reference exercises 15 | 16 | ````{exercise} 17 | :label: exercise-1 18 | 19 | Replicate this figure using matplotlib 20 | 21 | ```{figure} sphx_glr_cohere_001_2_0x.png 22 | ``` 23 | ```` 24 | 25 | and another version with a title embedded 26 | 27 | ````{exercise} Replicate Matplotlib Plot 28 | :label: exercise-2 29 | 30 | ```{figure} sphx_glr_cohere_001_2_0x.png 31 | ``` 32 | ```` 33 | -------------------------------------------------------------------------------- /tests/books/test-gateddirective/exercise_errors_1.md: -------------------------------------------------------------------------------- 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 | ``` 28 | -------------------------------------------------------------------------------- /tests/books/test-gateddirective/exercise_errors_2.md: -------------------------------------------------------------------------------- 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 | ``` 25 | -------------------------------------------------------------------------------- /tests/books/test-gateddirective/exercise_errors_3.md: -------------------------------------------------------------------------------- 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 | ``` 27 | -------------------------------------------------------------------------------- /tests/books/test-gateddirective/index.md: -------------------------------------------------------------------------------- 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 | # Gated Directives 13 | 14 | ```{toctree} 15 | :hidden: true 16 | :maxdepth: 1 17 | 18 | exercise 19 | solution-exercise 20 | exercise-gated 21 | solution-exercise-gated 22 | ``` 23 | -------------------------------------------------------------------------------- /tests/books/test-gateddirective/make.bat: -------------------------------------------------------------------------------- 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 36 | -------------------------------------------------------------------------------- /tests/books/test-gateddirective/solution-exercise-gated.md: -------------------------------------------------------------------------------- 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 | # Gated Solutions to exercise-gated.md 13 | 14 | A solution using the gated directive 15 | 16 | ```{solution-start} gated-exercise-1 17 | :label: gated-exercise-solution-1 18 | ``` 19 | 20 | This is a solution to Gated Exercise 1 21 | 22 | ```{code-cell} python3 23 | import numpy as np 24 | import matplotlib.pyplot as plt 25 | 26 | # Fixing random state for reproducibility 27 | np.random.seed(19680801) 28 | 29 | dt = 0.01 30 | t = np.arange(0, 30, dt) 31 | nse1 = np.random.randn(len(t)) # white noise 1 32 | nse2 = np.random.randn(len(t)) # white noise 2 33 | 34 | # Two signals with a coherent part at 10Hz and a random part 35 | s1 = np.sin(2 * np.pi * 10 * t) + nse1 36 | s2 = np.sin(2 * np.pi * 10 * t) + nse2 37 | 38 | fig, axs = plt.subplots(2, 1) 39 | axs[0].plot(t, s1, t, s2) 40 | axs[0].set_xlim(0, 2) 41 | axs[0].set_xlabel('time') 42 | axs[0].set_ylabel('s1 and s2') 43 | axs[0].grid(True) 44 | 45 | cxy, f = axs[1].cohere(s1, s2, 256, 1. / dt) 46 | axs[1].set_ylabel('coherence') 47 | 48 | fig.tight_layout() 49 | plt.show() 50 | ``` 51 | 52 | With some follow up text to the solution 53 | 54 | ```{solution-end} 55 | ``` 56 | 57 | and then a solution to {ref}`gated-exercise-2` 58 | 59 | A solution using the gated directive 60 | 61 | ```{solution-start} gated-exercise-2 62 | :label: gated-exercise-solution-2 63 | ``` 64 | 65 | This is a solution to Gated Exercise 2 66 | 67 | ```{code-cell} python3 68 | import numpy as np 69 | import matplotlib.pyplot as plt 70 | 71 | # Fixing random state for reproducibility 72 | np.random.seed(19680801) 73 | 74 | dt = 0.01 75 | t = np.arange(0, 30, dt) 76 | nse1 = np.random.randn(len(t)) # white noise 1 77 | nse2 = np.random.randn(len(t)) # white noise 2 78 | 79 | # Two signals with a coherent part at 10Hz and a random part 80 | s1 = np.sin(2 * np.pi * 10 * t) + nse1 81 | s2 = np.sin(2 * np.pi * 10 * t) + nse2 82 | 83 | fig, axs = plt.subplots(2, 1) 84 | axs[0].plot(t, s1, t, s2) 85 | axs[0].set_xlim(0, 2) 86 | axs[0].set_xlabel('time') 87 | axs[0].set_ylabel('s1 and s2') 88 | axs[0].grid(True) 89 | 90 | cxy, f = axs[1].cohere(s1, s2, 256, 1. / dt) 91 | axs[1].set_ylabel('coherence') 92 | 93 | fig.tight_layout() 94 | plt.show() 95 | ``` 96 | 97 | With some follow up text to the solution 98 | 99 | ```{solution-end} 100 | ``` 101 | 102 | ## References to Solutions 103 | 104 | This is a reference to {ref}`gated-exercise-solution-1` 105 | -------------------------------------------------------------------------------- /tests/books/test-gateddirective/solution-exercise.md: -------------------------------------------------------------------------------- 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 | # Gated Solutions to exercise.md 13 | 14 | A solution using the gated directive 15 | 16 | ```{solution-start} exercise-1 17 | :label: solution-gated-1 18 | ``` 19 | 20 | This is a solution to Non-Gated Exercise 1 21 | 22 | ```{code-cell} python3 23 | import numpy as np 24 | import matplotlib.pyplot as plt 25 | 26 | # Fixing random state for reproducibility 27 | np.random.seed(19680801) 28 | 29 | dt = 0.01 30 | t = np.arange(0, 30, dt) 31 | nse1 = np.random.randn(len(t)) # white noise 1 32 | nse2 = np.random.randn(len(t)) # white noise 2 33 | 34 | # Two signals with a coherent part at 10Hz and a random part 35 | s1 = np.sin(2 * np.pi * 10 * t) + nse1 36 | s2 = np.sin(2 * np.pi * 10 * t) + nse2 37 | 38 | fig, axs = plt.subplots(2, 1) 39 | axs[0].plot(t, s1, t, s2) 40 | axs[0].set_xlim(0, 2) 41 | axs[0].set_xlabel('time') 42 | axs[0].set_ylabel('s1 and s2') 43 | axs[0].grid(True) 44 | 45 | cxy, f = axs[1].cohere(s1, s2, 256, 1. / dt) 46 | axs[1].set_ylabel('coherence') 47 | 48 | fig.tight_layout() 49 | plt.show() 50 | ``` 51 | 52 | With some follow up text to the solution 53 | 54 | ```{solution-end} 55 | ``` 56 | 57 | and a solution to {ref}`exercise-2` 58 | 59 | ```{solution-start} exercise-2 60 | :label: solution-gated-2 61 | ``` 62 | 63 | This is a solution to Non-Gated Exercise 1 64 | 65 | ```{code-cell} python3 66 | import numpy as np 67 | import matplotlib.pyplot as plt 68 | 69 | # Fixing random state for reproducibility 70 | np.random.seed(19680801) 71 | 72 | dt = 0.01 73 | t = np.arange(0, 30, dt) 74 | nse1 = np.random.randn(len(t)) # white noise 1 75 | nse2 = np.random.randn(len(t)) # white noise 2 76 | 77 | # Two signals with a coherent part at 10Hz and a random part 78 | s1 = np.sin(2 * np.pi * 10 * t) + nse1 79 | s2 = np.sin(2 * np.pi * 10 * t) + nse2 80 | 81 | fig, axs = plt.subplots(2, 1) 82 | axs[0].plot(t, s1, t, s2) 83 | axs[0].set_xlim(0, 2) 84 | axs[0].set_xlabel('time') 85 | axs[0].set_ylabel('s1 and s2') 86 | axs[0].grid(True) 87 | 88 | cxy, f = axs[1].cohere(s1, s2, 256, 1. / dt) 89 | axs[1].set_ylabel('coherence') 90 | 91 | fig.tight_layout() 92 | plt.show() 93 | ``` 94 | 95 | With some follow up text to the solution 96 | 97 | ```{solution-end} 98 | ``` 99 | 100 | ## References 101 | 102 | This is a reference to {ref}`solution-gated-1` 103 | 104 | This is a reference to {ref}`solution-gated-2` 105 | -------------------------------------------------------------------------------- /tests/books/test-gateddirective/solution_errors_1.md: -------------------------------------------------------------------------------- 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 | # Solution Errors 1 13 | 14 | Some malformed directives 15 | 16 | ## Missing `-end` directive 17 | 18 | A solution using the gated directive 19 | 20 | ```{solution-start} exercise-1 21 | :label: solution-gated-1 22 | ``` 23 | 24 | This is a solution to Exercise 1 25 | 26 | ```{code-cell} python3 27 | import numpy as np 28 | import matplotlib.pyplot as plt 29 | 30 | # Fixing random state for reproducibility 31 | np.random.seed(19680801) 32 | 33 | dt = 0.01 34 | t = np.arange(0, 30, dt) 35 | nse1 = np.random.randn(len(t)) # white noise 1 36 | nse2 = np.random.randn(len(t)) # white noise 2 37 | 38 | # Two signals with a coherent part at 10Hz and a random part 39 | s1 = np.sin(2 * np.pi * 10 * t) + nse1 40 | s2 = np.sin(2 * np.pi * 10 * t) + nse2 41 | 42 | fig, axs = plt.subplots(2, 1) 43 | axs[0].plot(t, s1, t, s2) 44 | axs[0].set_xlim(0, 2) 45 | axs[0].set_xlabel('time') 46 | axs[0].set_ylabel('s1 and s2') 47 | axs[0].grid(True) 48 | 49 | cxy, f = axs[1].cohere(s1, s2, 256, 1. / dt) 50 | axs[1].set_ylabel('coherence') 51 | 52 | fig.tight_layout() 53 | plt.show() 54 | ``` 55 | 56 | With some follow up text to the solution 57 | -------------------------------------------------------------------------------- /tests/books/test-gateddirective/solution_errors_2.md: -------------------------------------------------------------------------------- 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 | # Solution Errors 2 13 | 14 | Some malformed directives 15 | 16 | ## Missing `-start` directive 17 | 18 | A solution using the gated directive 19 | 20 | This is a solution to Exercise 1 21 | 22 | ```{code-cell} python3 23 | import numpy as np 24 | import matplotlib.pyplot as plt 25 | 26 | # Fixing random state for reproducibility 27 | np.random.seed(19680801) 28 | 29 | dt = 0.01 30 | t = np.arange(0, 30, dt) 31 | nse1 = np.random.randn(len(t)) # white noise 1 32 | nse2 = np.random.randn(len(t)) # white noise 2 33 | 34 | # Two signals with a coherent part at 10Hz and a random part 35 | s1 = np.sin(2 * np.pi * 10 * t) + nse1 36 | s2 = np.sin(2 * np.pi * 10 * t) + nse2 37 | 38 | fig, axs = plt.subplots(2, 1) 39 | axs[0].plot(t, s1, t, s2) 40 | axs[0].set_xlim(0, 2) 41 | axs[0].set_xlabel('time') 42 | axs[0].set_ylabel('s1 and s2') 43 | axs[0].grid(True) 44 | 45 | cxy, f = axs[1].cohere(s1, s2, 256, 1. / dt) 46 | axs[1].set_ylabel('coherence') 47 | 48 | fig.tight_layout() 49 | plt.show() 50 | ``` 51 | 52 | With some follow up text to the solution 53 | 54 | ```{solution-end} 55 | ``` 56 | -------------------------------------------------------------------------------- /tests/books/test-gateddirective/solution_errors_3.md: -------------------------------------------------------------------------------- 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 | # Solution Errors 3 13 | 14 | ## Incorrect Nesting of Gated Directives 15 | 16 | ```{solution-start} solution1 17 | ``` 18 | 19 | ```{solution-start} solution2 20 | ``` 21 | 22 | ```{solution-end} 23 | ``` 24 | 25 | ```{solution-end} 26 | ``` 27 | -------------------------------------------------------------------------------- /tests/books/test-gateddirective/sphx_glr_cohere_001_2_0x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/executablebooks/sphinx-exercise/a098092db826e45b808d2ce0409f987382d0d038/tests/books/test-gateddirective/sphx_glr_cohere_001_2_0x.png -------------------------------------------------------------------------------- /tests/books/test-hiddendirectives/Makefile: -------------------------------------------------------------------------------- 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) 21 | -------------------------------------------------------------------------------- /tests/books/test-hiddendirectives/_enum_duplicatelabel_hidden.rst: -------------------------------------------------------------------------------- 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. 9 | -------------------------------------------------------------------------------- /tests/books/test-hiddendirectives/_enum_hidden.rst: -------------------------------------------------------------------------------- 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. 9 | -------------------------------------------------------------------------------- /tests/books/test-hiddendirectives/_linked_enum_hidden.rst: -------------------------------------------------------------------------------- 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. 10 | -------------------------------------------------------------------------------- /tests/books/test-hiddendirectives/_linked_unenum_hidden.rst: -------------------------------------------------------------------------------- 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. 10 | -------------------------------------------------------------------------------- /tests/books/test-hiddendirectives/_unenum_hidden.rst: -------------------------------------------------------------------------------- 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. 11 | -------------------------------------------------------------------------------- /tests/books/test-hiddendirectives/conf.py: -------------------------------------------------------------------------------- 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'] 52 | -------------------------------------------------------------------------------- /tests/books/test-hiddendirectives/index.rst: -------------------------------------------------------------------------------- 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 11 | -------------------------------------------------------------------------------- /tests/books/test-hiddendirectives/make.bat: -------------------------------------------------------------------------------- 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 36 | -------------------------------------------------------------------------------- /tests/books/test-mybook/Makefile: -------------------------------------------------------------------------------- 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) 21 | -------------------------------------------------------------------------------- /tests/books/test-mybook/conf.py: -------------------------------------------------------------------------------- 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'] 52 | -------------------------------------------------------------------------------- /tests/books/test-mybook/exercise/_enum_duplicate_label.rst: -------------------------------------------------------------------------------- 1 | _enum_duplicate_label 2 | ===================== 3 | 4 | .. exercise:: duplicate directive 1 5 | :label: dup 6 | 7 | Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. 8 | 9 | 10 | .. exercise:: duplicate directive 2 11 | :label: dup 12 | 13 | Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. 14 | -------------------------------------------------------------------------------- /tests/books/test-mybook/exercise/_enum_mathtitle_label.rst: -------------------------------------------------------------------------------- 1 | _enum_mathtitle_label 2 | ===================== 3 | 4 | .. exercise:: Test :math:`\mathbb{R}` 5 | :label: test-exc-label-math 6 | 7 | Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. 8 | -------------------------------------------------------------------------------- /tests/books/test-mybook/exercise/_enum_notitle_label.rst: -------------------------------------------------------------------------------- 1 | _enum_notitle_label 2 | =================== 3 | 4 | .. exercise:: 5 | :label: text-exc-notitle 6 | 7 | Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. 8 | -------------------------------------------------------------------------------- /tests/books/test-mybook/exercise/_enum_numref_mathtitle.rst: -------------------------------------------------------------------------------- 1 | _enum_numref_mathtitle 2 | ====================== 3 | 4 | This is a reference :numref:`test-exc-label-math`. 5 | 6 | This is a second reference :numref:`some text %s `. 7 | 8 | This is a third reference :numref:`some text {number} `. 9 | 10 | This is a fourth reference :numref:`some text {name} `. 11 | -------------------------------------------------------------------------------- /tests/books/test-mybook/exercise/_enum_numref_notitle.rst: -------------------------------------------------------------------------------- 1 | _enum_numref_notitle 2 | ==================== 3 | 4 | This is a reference :numref:`text-exc-notitle`. 5 | 6 | This is a second reference :numref:`some text %s `. 7 | 8 | This is a third reference :numref:`some text {number} `. 9 | 10 | This is a fourth reference :numref:`some text {name} `. 11 | -------------------------------------------------------------------------------- /tests/books/test-mybook/exercise/_enum_numref_placeholders.rst: -------------------------------------------------------------------------------- 1 | _enum_numref_placeholders 2 | ========================= 3 | 4 | 5 | This reference does not include math :numref:`some {number} text %s test {name} `. 6 | 7 | This reference does not include math :numref:`some {number} text %s test `. 8 | 9 | This reference does not include math :numref:`some {name} text %s test `. 10 | 11 | This reference does not include math :numref:`some {name} text {number} test `. 12 | 13 | This reference does not include math :numref:`some %s text test `. 14 | 15 | 16 | 17 | This reference includes math :numref:`some {number} text %s test {name} `. 18 | 19 | This reference includes math :numref:`some {number} text %s test `. 20 | 21 | This reference includes math :numref:`some {name} text %s test `. 22 | 23 | This reference includes math :numref:`some {name} text {number} test `. 24 | 25 | This reference includes math :numref:`some %s text test `. 26 | -------------------------------------------------------------------------------- /tests/books/test-mybook/exercise/_enum_numref_title.rst: -------------------------------------------------------------------------------- 1 | _enum_numref_title 2 | ================== 3 | 4 | This is a reference :numref:`test-exc-label`. 5 | 6 | This is a second reference :numref:`some text %s `. 7 | 8 | This is a third reference :numref:`some text {number} `. 9 | 10 | This is a fourth reference :numref:`some text {name} `. 11 | -------------------------------------------------------------------------------- /tests/books/test-mybook/exercise/_enum_ref_mathtitle.rst: -------------------------------------------------------------------------------- 1 | _enum_ref_mathtitle 2 | =================== 3 | 4 | This is a reference :ref:`test-exc-label-math`. 5 | 6 | This is a second reference :ref:`some text `. 7 | -------------------------------------------------------------------------------- /tests/books/test-mybook/exercise/_enum_ref_notitle.rst: -------------------------------------------------------------------------------- 1 | _enum_ref_notitle 2 | ================= 3 | 4 | This is a reference :ref:`text-exc-notitle`. 5 | 6 | This is a second reference :ref:`some text `. 7 | -------------------------------------------------------------------------------- /tests/books/test-mybook/exercise/_enum_ref_title.rst: -------------------------------------------------------------------------------- 1 | _enum_ref_title 2 | =============== 3 | 4 | This is a reference :ref:`test-exc-label`. 5 | 6 | This is a second reference :ref:`some text `. 7 | -------------------------------------------------------------------------------- /tests/books/test-mybook/exercise/_enum_title_class_label.rst: -------------------------------------------------------------------------------- 1 | _enum_title_class_label 2 | ======================= 3 | 4 | .. exercise:: Test exercise directive 5 | :class: test-exc 6 | :label: test-exc-label 7 | 8 | Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. 9 | -------------------------------------------------------------------------------- /tests/books/test-mybook/exercise/_enum_title_nolabel.rst: -------------------------------------------------------------------------------- 1 | _enum_title_nolabel 2 | =================== 3 | 4 | .. exercise:: Test exercise directive 5 | 6 | Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. 7 | -------------------------------------------------------------------------------- /tests/books/test-mybook/exercise/_unenum_mathtitle_label.rst: -------------------------------------------------------------------------------- 1 | _unenum_mathtitle_label 2 | ======================= 3 | 4 | .. exercise:: Test :math:`\mathbb{R}` 5 | :label: unen-exc-label-math 6 | :nonumber: 7 | 8 | Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. 9 | -------------------------------------------------------------------------------- /tests/books/test-mybook/exercise/_unenum_notitle_label.rst: -------------------------------------------------------------------------------- 1 | _unenum_notitle_label 2 | ===================== 3 | 4 | .. exercise:: 5 | :label: unen-exc-notitle 6 | :nonumber: 7 | 8 | Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. 9 | -------------------------------------------------------------------------------- /tests/books/test-mybook/exercise/_unenum_numref_mathtitle.rst: -------------------------------------------------------------------------------- 1 | _unenum_numref_mathtitle 2 | ======================== 3 | 4 | This is a reference :numref:`unen-exc-label-math`. 5 | 6 | This is a second reference :numref:`some text %s `. 7 | 8 | This is a third reference :numref:`some text {number} `. 9 | 10 | This is a fourth reference :numref:`some text {name} `. 11 | -------------------------------------------------------------------------------- /tests/books/test-mybook/exercise/_unenum_numref_notitle.rst: -------------------------------------------------------------------------------- 1 | _unenum_numref_notitle 2 | ====================== 3 | 4 | This is a reference :numref:`unen-exc-notitle`. 5 | 6 | This is a second reference :numref:`some text %s `. 7 | 8 | This is a third reference :numref:`some text {number} `. 9 | 10 | This is a fourth reference :numref:`some text {name} `. 11 | -------------------------------------------------------------------------------- /tests/books/test-mybook/exercise/_unenum_numref_title.rst: -------------------------------------------------------------------------------- 1 | _unenum_numref_title 2 | ==================== 3 | 4 | This is a reference :numref:`unen-exc-label`. 5 | 6 | This is a second reference :numref:`some text %s `. 7 | 8 | This is a third reference :numref:`some text {number} `. 9 | 10 | This is a fourth reference :numref:`some text {name} `. 11 | -------------------------------------------------------------------------------- /tests/books/test-mybook/exercise/_unenum_ref_mathtitle.rst: -------------------------------------------------------------------------------- 1 | _unenum_ref_mathtitle 2 | ===================== 3 | 4 | This is a reference :ref:`unen-exc-label-math`. 5 | 6 | This is a second reference :ref:`some text `. 7 | -------------------------------------------------------------------------------- /tests/books/test-mybook/exercise/_unenum_ref_notitle.rst: -------------------------------------------------------------------------------- 1 | _unenum_ref_notitle 2 | =================== 3 | 4 | This is a reference :ref:`unen-exc-notitle`. 5 | 6 | This is a second reference :ref:`some text `. 7 | -------------------------------------------------------------------------------- /tests/books/test-mybook/exercise/_unenum_ref_title.rst: -------------------------------------------------------------------------------- 1 | _unenum_ref_title 2 | ================= 3 | 4 | This is a reference :ref:`unen-exc-label`. 5 | 6 | This is a second reference :ref:`some text `. 7 | -------------------------------------------------------------------------------- /tests/books/test-mybook/exercise/_unenum_title_class_label.rst: -------------------------------------------------------------------------------- 1 | _unenum_title_class_label 2 | ========================= 3 | 4 | .. exercise:: Test exercise directive 5 | :class: unen-exc 6 | :label: unen-exc-label 7 | :nonumber: 8 | 9 | Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. 10 | -------------------------------------------------------------------------------- /tests/books/test-mybook/exercise/_unenum_title_nolabel.rst: -------------------------------------------------------------------------------- 1 | _unenum_title_nolabel 2 | ===================== 3 | 4 | .. exercise:: Test exercise directive 5 | :nonumber: 6 | 7 | Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. 8 | -------------------------------------------------------------------------------- /tests/books/test-mybook/index.rst: -------------------------------------------------------------------------------- 1 | A Test Program! 2 | =============== 3 | 4 | .. toctree:: 5 | :maxdepth: 1 6 | :hidden: 7 | 8 | exercise/_enum_mathtitle_label 9 | exercise/_enum_notitle_label 10 | exercise/_enum_title_class_label 11 | exercise/_enum_title_nolabel 12 | exercise/_enum_ref_notitle 13 | exercise/_enum_ref_title 14 | exercise/_enum_ref_mathtitle 15 | exercise/_enum_numref_notitle 16 | exercise/_enum_numref_title 17 | exercise/_enum_numref_mathtitle 18 | 19 | exercise/_unenum_mathtitle_label 20 | exercise/_unenum_notitle_label 21 | exercise/_unenum_title_class_label 22 | exercise/_unenum_title_nolabel 23 | exercise/_unenum_ref_notitle 24 | exercise/_unenum_ref_title 25 | exercise/_unenum_ref_mathtitle 26 | exercise/_unenum_numref_notitle 27 | exercise/_unenum_numref_title 28 | exercise/_unenum_numref_mathtitle 29 | exercise/_enum_numref_placeholders 30 | 31 | exercise/_enum_duplicate_label 32 | 33 | solution/_linked_enum 34 | solution/_linked_enum_class 35 | solution/_linked_missing_arg 36 | solution/_linked_unenum_mathtitle 37 | solution/_linked_unenum_mathtitle2 38 | solution/_linked_unenum_notitle 39 | solution/_linked_unenum_title 40 | solution/_linked_wrong_targetlabel 41 | 42 | solution/_linked_ref_unenum_notitle 43 | solution/_linked_ref_unenum_title 44 | solution/_linked_ref_unenum_mathtitle 45 | solution/_linked_ref_unenum_mathtitle2 46 | solution/_linked_ref_enum 47 | 48 | solution/_linked_ref_wronglabel 49 | solution/_linked_duplicate_label 50 | -------------------------------------------------------------------------------- /tests/books/test-mybook/make.bat: -------------------------------------------------------------------------------- 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 36 | -------------------------------------------------------------------------------- /tests/books/test-mybook/solution/_linked_duplicate_label.rst: -------------------------------------------------------------------------------- 1 | _linked_duplicate_label 2 | ======================= 3 | 4 | 5 | .. solution:: ex-nonumber-notitle 6 | :label: sol-duplicate-label 7 | 8 | Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. 9 | 10 | .. solution:: ex-nonumber-notitle 11 | :label: sol-duplicate-label 12 | 13 | Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. 14 | -------------------------------------------------------------------------------- /tests/books/test-mybook/solution/_linked_enum.rst: -------------------------------------------------------------------------------- 1 | _linked_enum 2 | ============ 3 | 4 | 5 | .. exercise:: This is a title 6 | :label: ex-number 7 | 8 | Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. 9 | 10 | 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. 11 | 12 | Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. 13 | 14 | 15 | .. solution:: ex-number 16 | :label: sol-number 17 | 18 | Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. 19 | 20 | .. math:: 21 | 22 | P_t(x, y) = \mathbb 1\{x = y\} + t Q(x, y) + o(t) 23 | 24 | Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. 25 | 26 | .. math:: 27 | :label: ex-math 28 | 29 | P_t(x, y) = \mathbb 1\{x = y\} + t Q(x, y) + o(t) 30 | -------------------------------------------------------------------------------- /tests/books/test-mybook/solution/_linked_enum_class.rst: -------------------------------------------------------------------------------- 1 | _linked_enum_class 2 | ================== 3 | 4 | .. solution:: ex-number 5 | :label: solution-label 6 | :class: test-solution 7 | 8 | Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. 9 | -------------------------------------------------------------------------------- /tests/books/test-mybook/solution/_linked_missing_arg.rst: -------------------------------------------------------------------------------- 1 | _linked_missing_arg 2 | =================== 3 | 4 | .. solution:: 5 | 6 | Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. 7 | -------------------------------------------------------------------------------- /tests/books/test-mybook/solution/_linked_ref_enum.rst: -------------------------------------------------------------------------------- 1 | _linked_ref_enum 2 | ================ 3 | 4 | 5 | referencing: :ref:`sol-number`. 6 | 7 | referencing: :ref:`simple solution with number `. 8 | -------------------------------------------------------------------------------- /tests/books/test-mybook/solution/_linked_ref_unenum_mathtitle.rst: -------------------------------------------------------------------------------- 1 | _linked_ref_unenum_mathtitle 2 | ============================ 3 | 4 | 5 | referencing: :ref:`sol-nonumber-title-math`. 6 | 7 | referencing: :ref:`exercise with nonumber but with inline math title `. 8 | -------------------------------------------------------------------------------- /tests/books/test-mybook/solution/_linked_ref_unenum_mathtitle2.rst: -------------------------------------------------------------------------------- 1 | _linked_ref_unenum_mathtitle2 2 | ============================= 3 | 4 | 5 | referencing: :ref:`sol-nonumber-title-math2`. 6 | 7 | referencing: :ref:`exercise with nonumber but with inline math title ex2 `. 8 | -------------------------------------------------------------------------------- /tests/books/test-mybook/solution/_linked_ref_unenum_notitle.rst: -------------------------------------------------------------------------------- 1 | _linked_ref_unenum_notitle 2 | ========================== 3 | 4 | 5 | referencing: :ref:`sol-nonumber-notitle`. 6 | 7 | referencing: :ref:`ex with nonumber and notitle `. 8 | -------------------------------------------------------------------------------- /tests/books/test-mybook/solution/_linked_ref_unenum_title.rst: -------------------------------------------------------------------------------- 1 | _linked_ref_unenum_title 2 | ======================== 3 | 4 | 5 | referencing: :ref:`sol-nonumber-title`. 6 | 7 | referencing: :ref:`exercise with nonumber but with title `. 8 | -------------------------------------------------------------------------------- /tests/books/test-mybook/solution/_linked_ref_wronglabel.rst: -------------------------------------------------------------------------------- 1 | _linked_ref_wronglabel 2 | ====================== 3 | 4 | 5 | referencing: :ref:`foobar`. 6 | -------------------------------------------------------------------------------- /tests/books/test-mybook/solution/_linked_unenum_mathtitle.rst: -------------------------------------------------------------------------------- 1 | _linked_unenum_mathtitle 2 | ======================== 3 | 4 | 5 | .. exercise:: This is a title :math:`\mathbb{R}` 6 | :label: ex-nonumber-title-math 7 | :nonumber: 8 | 9 | Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. 10 | 11 | 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. 12 | 13 | Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. 14 | 15 | 16 | .. solution:: ex-nonumber-title-math 17 | :label: sol-nonumber-title-math 18 | 19 | Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. 20 | -------------------------------------------------------------------------------- /tests/books/test-mybook/solution/_linked_unenum_mathtitle2.rst: -------------------------------------------------------------------------------- 1 | _linked_unenum_mathtitle2 2 | ========================= 3 | 4 | 5 | .. exercise:: This is a title :math:`P_t(x, y) = \mathbb 1\{x = y\} + t Q(x, y) + o(t)` 6 | :label: ex-nonumber-title-math2 7 | :nonumber: 8 | 9 | Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. 10 | 11 | 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. 12 | 13 | Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. 14 | 15 | 16 | .. solution:: ex-nonumber-title-math2 17 | :label: sol-nonumber-title-math2 18 | 19 | Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. 20 | -------------------------------------------------------------------------------- /tests/books/test-mybook/solution/_linked_unenum_notitle.rst: -------------------------------------------------------------------------------- 1 | _linked_unenum_notitle 2 | ====================== 3 | 4 | 5 | .. exercise:: 6 | :label: ex-nonumber-notitle 7 | :nonumber: 8 | 9 | Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. 10 | 11 | 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. 12 | 13 | Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. 14 | 15 | 16 | .. solution:: ex-nonumber-notitle 17 | :label: sol-nonumber-notitle 18 | 19 | Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. 20 | -------------------------------------------------------------------------------- /tests/books/test-mybook/solution/_linked_unenum_title.rst: -------------------------------------------------------------------------------- 1 | _linked_unenum_title 2 | ==================== 3 | 4 | 5 | .. exercise:: This is a title 6 | :label: ex-nonumber-title 7 | :nonumber: 8 | 9 | Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. 10 | 11 | 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. 12 | 13 | Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. 14 | 15 | 16 | .. solution:: ex-nonumber-title 17 | :label: sol-nonumber-title 18 | 19 | Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. 20 | -------------------------------------------------------------------------------- /tests/books/test-mybook/solution/_linked_wrong_targetlabel.rst: -------------------------------------------------------------------------------- 1 | _linked_wrong_targetlabel 2 | ========================= 3 | 4 | .. solution:: wrong-ex-label 5 | 6 | Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. 7 | -------------------------------------------------------------------------------- /tests/books/test-simplebook/Makefile: -------------------------------------------------------------------------------- 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) 21 | -------------------------------------------------------------------------------- /tests/books/test-simplebook/conf.py: -------------------------------------------------------------------------------- 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 = "sphinx_book_theme" 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'] 52 | -------------------------------------------------------------------------------- /tests/books/test-simplebook/exercise.rst: -------------------------------------------------------------------------------- 1 | Exercise 2 | ======== 3 | 4 | A collection of exercise directives 5 | 6 | .. exercise:: :math:`n!` factorial 7 | :label: exercise-1 8 | 9 | Exercise 1 about :math:`n!` factorial 10 | 11 | .. exercise:: :math:`n!` factorial 12 | :label: exercise-2 13 | :nonumber: 14 | 15 | Exercise 2 about :math:`n!` factorial 16 | 17 | .. exercise:: 18 | :label: exercise-3 19 | 20 | Exercise 3 Content with Number 21 | 22 | .. exercise:: 23 | :label: exercise-4 24 | :nonumber: 25 | 26 | Exercise 4 Content with no Number 27 | 28 | References 29 | ---------- 30 | 31 | Standard References 32 | ~~~~~~~~~~~~~~~~~~~ 33 | 34 | This is a link to :ref:`exercise-no-title` 35 | 36 | This is a link to :ref:`exercise-1` 37 | 38 | This is a link to :ref:`exercise-2` 39 | 40 | This ia another link with custom text :ref:`Exercise 3 Custom Text` 41 | 42 | This ia another link with custom text :ref:`Exercise 4 Custom Text` 43 | 44 | Numbered References 45 | ~~~~~~~~~~~~~~~~~~~ 46 | 47 | This is a numbered reference to :numref:`exercise-1` 48 | 49 | This is a numbered reference to :numref:`exercise-2` and should be broken as exercise 2 is not an 50 | enumerated exercise node. 51 | 52 | This is a numbered reference to :numref:`exercise-3` 53 | 54 | This is a numbered reference with custom text to :numref:`Custom Text with a Number {number}` 55 | 56 | This is a numbered reference to :numref:`exercise-4` and should be broken as exercise 2 is not an 57 | enumerated exercise node. 58 | 59 | This is a numbered reference with custom text to :numref:`Custom Text with a Number {number}` and should be broken as exercise 2 is not an 60 | enumerated exercise node. 61 | -------------------------------------------------------------------------------- /tests/books/test-simplebook/index.rst: -------------------------------------------------------------------------------- 1 | A Test Program! 2 | =============== 3 | 4 | .. toctree:: 5 | :maxdepth: 1 6 | :hidden: 7 | 8 | exercise 9 | solution 10 | -------------------------------------------------------------------------------- /tests/books/test-simplebook/make.bat: -------------------------------------------------------------------------------- 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 36 | -------------------------------------------------------------------------------- /tests/books/test-simplebook/solution.rst: -------------------------------------------------------------------------------- 1 | Solution 2 | ======== 3 | 4 | A collection of solution directives 5 | 6 | .. solution:: exercise-1 7 | :label: solution-1 8 | 9 | This is a solution to exercise 1 10 | 11 | .. solution:: exercise-2 12 | :label: solution-2 13 | 14 | This is a solution to exercise 2 15 | 16 | .. solution:: exercise-3 17 | :label: solution-3 18 | 19 | This is a solution to exercise 3 20 | 21 | .. solution:: exercise-4 22 | :label: solution-4 23 | 24 | This is a solution to exercise 4 25 | 26 | 27 | References 28 | ---------- 29 | 30 | Standard References 31 | ~~~~~~~~~~~~~~~~~~~ 32 | 33 | This is a link to :ref:`solution-1` 34 | 35 | This is a link to :ref:`solution-2` 36 | 37 | This is a link to :ref:`solution-3` 38 | 39 | This is a link to :ref:`solution-4` 40 | 41 | This ia another link to a different :ref:`custom label text to solution-1 ` 42 | 43 | Numbered References 44 | ~~~~~~~~~~~~~~~~~~~ 45 | 46 | Solution nodes are not enumerated nodes so these won't work 47 | 48 | This is a link to :numref:`solution-1` 49 | -------------------------------------------------------------------------------- /tests/conftest.py: -------------------------------------------------------------------------------- 1 | import shutil 2 | import pytest 3 | import packaging.version 4 | import sphinx 5 | import re 6 | 7 | from pathlib import Path 8 | 9 | pytest_plugins = "sphinx.testing.fixtures" 10 | 11 | 12 | if packaging.version.Version(sphinx.__version__) < packaging.version.Version("7.2.0"): 13 | 14 | @pytest.fixture 15 | def rootdir(tmpdir): 16 | from sphinx.testing.path import path 17 | 18 | src = path(__file__).parent.absolute() / "books" 19 | dst = tmpdir.join("books") 20 | shutil.copytree(src, dst) 21 | yield path(dst) 22 | shutil.rmtree(dst) 23 | 24 | else: 25 | 26 | @pytest.fixture 27 | def rootdir(tmp_path): 28 | src = Path(__file__).parent.absolute() / "books" 29 | dst = tmp_path / "books" 30 | shutil.copytree(src, dst) 31 | yield dst 32 | shutil.rmtree(dst) 33 | 34 | 35 | @pytest.fixture 36 | def warnings(): 37 | def read(app): 38 | return app._warning.getvalue().strip() 39 | 40 | return read 41 | 42 | 43 | @pytest.fixture 44 | def get_sphinx_app_doctree(file_regression): 45 | def read( 46 | app, 47 | docname="index", 48 | resolve=False, 49 | regress=False, 50 | flatten_outdir=False, 51 | sphinx_version=False, 52 | ): 53 | if resolve: 54 | doctree = app.env.get_and_resolve_doctree(docname, app.builder) 55 | extension = ".resolved.xml" 56 | else: 57 | doctree = app.env.get_doctree(docname) 58 | extension = ".xml" 59 | 60 | if sphinx_version: 61 | extension = sphinx_version + extension 62 | 63 | # convert absolute filenames 64 | findall = getattr(doctree, "findall", doctree.traverse) 65 | for node in findall(lambda n: "source" in n): 66 | node["source"] = Path(node["source"]).name 67 | 68 | if flatten_outdir: 69 | docname = docname.split("/")[-1] 70 | 71 | if regress: 72 | file_regression.check( 73 | doctree.pformat(), basename=docname, extension=extension 74 | ) 75 | 76 | return doctree 77 | 78 | return read 79 | 80 | 81 | # comparison files will need updating 82 | # alternatively the resolution of https://github.com/ESSS/pytest-regressions/issues/32 83 | @pytest.fixture() 84 | def file_regression(file_regression): 85 | return FileRegression(file_regression) 86 | 87 | 88 | class FileRegression: 89 | ignores = () 90 | changes = ( 91 | # TODO: Remove when support for Sphinx<=6 is dropped, 92 | (re.escape(" translation_progress=\"{'total': 0, 'translated': 0}\""), ""), 93 | # TODO: Remove when support for Sphinx<7.2 is dropped, 94 | (r"original_uri=\"[^\"]*\"\s", ""), 95 | # TODO: Remove when support for Sphinx<7.2 is dropped 96 | ("Link to", "Permalink to"), 97 | ) 98 | 99 | def __init__(self, file_regression): 100 | self.file_regression = file_regression 101 | 102 | def check(self, data, **kwargs): 103 | return self.file_regression.check(self._strip_ignores(data), **kwargs) 104 | 105 | def _strip_ignores(self, data): 106 | for src, dst in self.changes: 107 | data = re.sub(src, dst, data) 108 | return data 109 | -------------------------------------------------------------------------------- /tests/test_build.py: -------------------------------------------------------------------------------- 1 | import pytest 2 | import shutil 3 | 4 | 5 | @pytest.mark.sphinx("html", testroot="mybook") 6 | def test_build(app): 7 | """Test building the book template and a few test configs.""" 8 | app.build() 9 | assert (app.outdir / "index.html").exists() 10 | assert (app.outdir / "exercise").exists() 11 | assert (app.outdir / "solution").exists() 12 | 13 | 14 | @pytest.mark.sphinx("html", testroot="mybook") 15 | @pytest.mark.parametrize( 16 | "wmsg", 17 | [ 18 | "_unenum_numref_mathtitle.rst:4: WARNING: undefined label: unen-exc-label-math", 19 | "_unenum_numref_mathtitle.rst:6: WARNING: undefined label: unen-exc-label-math", 20 | "_unenum_numref_mathtitle.rst:8: WARNING: undefined label: unen-exc-label-math", 21 | "_unenum_numref_mathtitle.rst:10: WARNING: undefined label: unen-exc-label-math", # noqa: E501 22 | "_unenum_numref_notitle.rst:4: WARNING: undefined label: unen-exc-notitle", 23 | "_unenum_numref_notitle.rst:6: WARNING: undefined label: unen-exc-notitle", 24 | "_unenum_numref_notitle.rst:8: WARNING: undefined label: unen-exc-notitle", 25 | "_unenum_numref_notitle.rst:10: WARNING: undefined label: unen-exc-notitle", 26 | "_unenum_numref_title.rst:4: WARNING: undefined label: unen-exc-label", 27 | "_unenum_numref_title.rst:6: WARNING: undefined label: unen-exc-label", 28 | "_unenum_numref_title.rst:8: WARNING: undefined label: unen-exc-label", 29 | "_unenum_numref_title.rst:10: WARNING: undefined label: unen-exc-label", 30 | "_linked_ref_wronglabel.rst:5: WARNING: undefined label: foobar", 31 | "_linked_unenum_title.rst: WARNING: undefined label: wrong-ex-label", 32 | "_enum_duplicate_label.rst: WARNING: duplicate label: dup;", 33 | "_linked_duplicate_label.rst: WARNING: duplicate label: sol-duplicate-label;", 34 | ], 35 | ) 36 | def test_warnings(app, warnings, wmsg): 37 | build_path = app.srcdir.joinpath("_build") 38 | shutil.rmtree(build_path) 39 | app.build() 40 | assert wmsg in warnings(app).replace("'", "") 41 | -------------------------------------------------------------------------------- /tests/test_duplicatelabel.py: -------------------------------------------------------------------------------- 1 | import pytest 2 | import shutil 3 | 4 | 5 | @pytest.mark.sphinx("html", testroot="duplicatelabel") 6 | def test_duplicates(app, warnings): 7 | build_path = app.srcdir.joinpath("_build") 8 | shutil.rmtree(build_path) 9 | app.build() 10 | 11 | assert "WARNING: duplicate label: label-1;" in warnings(app) 12 | assert "WARNING: duplicate label: label-2;" in warnings(app) 13 | -------------------------------------------------------------------------------- /tests/test_exercise.py: -------------------------------------------------------------------------------- 1 | from bs4 import BeautifulSoup 2 | import pytest 3 | 4 | 5 | @pytest.mark.sphinx("html", testroot="mybook") 6 | @pytest.mark.parametrize( 7 | "idir", 8 | [ 9 | "_enum_mathtitle_label.html", 10 | "_enum_notitle_label.html", 11 | "_enum_title_class_label.html", 12 | "_enum_title_nolabel.html", 13 | "_unenum_mathtitle_label.html", 14 | "_unenum_notitle_label.html", 15 | "_unenum_title_class_label.html", 16 | "_unenum_title_nolabel.html", 17 | ], 18 | ) 19 | def test_exercise(app, idir, file_regression): 20 | """Test exercise directive markup.""" 21 | app.build() 22 | path_exc_directive = app.outdir / "exercise" / idir 23 | assert path_exc_directive.exists() 24 | 25 | # get content markup 26 | soup = BeautifulSoup(path_exc_directive.read_text(encoding="utf8"), "html.parser") 27 | excs = soup.select("div.exercise")[0] 28 | file_regression.check(str(excs), basename=idir.split(".")[0], extension=".html") 29 | 30 | 31 | @pytest.mark.sphinx("html", testroot="mybook") 32 | @pytest.mark.parametrize( 33 | "docname", 34 | [ 35 | "_enum_duplicate_label", 36 | "_enum_mathtitle_label", 37 | "_enum_notitle_label", 38 | "_enum_title_class_label", 39 | "_enum_title_nolabel", 40 | "_unenum_mathtitle_label", 41 | "_unenum_notitle_label", 42 | "_unenum_title_class_label", 43 | "_unenum_title_nolabel", 44 | ], 45 | ) 46 | def test_exercise_doctree(app, docname, file_regression, get_sphinx_app_doctree): 47 | app.build() 48 | docname = "exercise" + "/" + docname 49 | get_sphinx_app_doctree( 50 | app, 51 | docname, 52 | resolve=False, 53 | regress=True, 54 | flatten_outdir=True, # noqa: E501 flatten files "solution/ -> .xml" for convenience 55 | ) 56 | -------------------------------------------------------------------------------- /tests/test_exercise/_enum_duplicate_label.xml: -------------------------------------------------------------------------------- 1 | 2 |
3 | 4 | _enum_duplicate_label 5 | <exercise_enumerable_node classes="exercise" docname="exercise/_enum_duplicate_label" hidden="False" ids="dup" label="dup" names="dup" serial_number="0" title="Exercise" type="exercise"> 6 | <exercise_title> 7 | Exercise 8 | <exercise_subtitle> 9 | duplicate directive 1 10 | <section ids="exercise-content"> 11 | <paragraph> 12 | Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. 13 | -------------------------------------------------------------------------------- /tests/test_exercise/_enum_mathtitle_label.html: -------------------------------------------------------------------------------- 1 | <div class="exercise admonition" id="test-exc-label-math"> 2 | <p class="admonition-title"><span class="caption-number">Exercise 1 </span> (Test <span class="math notranslate nohighlight">\(\mathbb{R}\)</span>)</p> 3 | <section id="exercise-content"> 4 | <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</p> 5 | </section> 6 | </div> -------------------------------------------------------------------------------- /tests/test_exercise/_enum_mathtitle_label.xml: -------------------------------------------------------------------------------- 1 | <document source="_enum_mathtitle_label.rst"> 2 | <section ids="enum-mathtitle-label" names="_enum_mathtitle_label"> 3 | <title> 4 | _enum_mathtitle_label 5 | <exercise_enumerable_node classes="exercise" docname="exercise/_enum_mathtitle_label" hidden="False" ids="test-exc-label-math" label="test-exc-label-math" names="test-exc-label-math" serial_number="0" title="Exercise" type="exercise"> 6 | <exercise_title> 7 | Exercise 8 | <exercise_subtitle> 9 | Test 10 | <math> 11 | \mathbb{R} 12 | <section ids="exercise-content"> 13 | <paragraph> 14 | Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. 15 | -------------------------------------------------------------------------------- /tests/test_exercise/_enum_notitle_label.html: -------------------------------------------------------------------------------- 1 | <div class="exercise admonition" id="text-exc-notitle"> 2 | <p class="admonition-title"><span class="caption-number">Exercise 2 </span></p> 3 | <section id="exercise-content"> 4 | <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</p> 5 | </section> 6 | </div> -------------------------------------------------------------------------------- /tests/test_exercise/_enum_notitle_label.xml: -------------------------------------------------------------------------------- 1 | <document source="_enum_notitle_label.rst"> 2 | <section ids="enum-notitle-label" names="_enum_notitle_label"> 3 | <title> 4 | _enum_notitle_label 5 | <exercise_enumerable_node classes="exercise" docname="exercise/_enum_notitle_label" hidden="False" ids="text-exc-notitle" label="text-exc-notitle" names="text-exc-notitle" serial_number="0" title="Exercise" type="exercise"> 6 | <exercise_title> 7 | Exercise 8 | <section ids="exercise-content"> 9 | <paragraph> 10 | Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. 11 | -------------------------------------------------------------------------------- /tests/test_exercise/_enum_title_class_label.html: -------------------------------------------------------------------------------- 1 | <div class="exercise test-exc admonition" id="test-exc-label"> 2 | <p class="admonition-title"><span class="caption-number">Exercise 3 </span> (Test exercise directive)</p> 3 | <section id="exercise-content"> 4 | <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</p> 5 | </section> 6 | </div> -------------------------------------------------------------------------------- /tests/test_exercise/_enum_title_class_label.xml: -------------------------------------------------------------------------------- 1 | <document source="_enum_title_class_label.rst"> 2 | <section ids="enum-title-class-label" names="_enum_title_class_label"> 3 | <title> 4 | _enum_title_class_label 5 | <exercise_enumerable_node classes="exercise test-exc" docname="exercise/_enum_title_class_label" hidden="False" ids="test-exc-label" label="test-exc-label" names="test-exc-label" serial_number="0" title="Exercise" type="exercise"> 6 | <exercise_title> 7 | Exercise 8 | <exercise_subtitle> 9 | Test exercise directive 10 | <section ids="exercise-content"> 11 | <paragraph> 12 | Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. 13 | -------------------------------------------------------------------------------- /tests/test_exercise/_enum_title_nolabel.html: -------------------------------------------------------------------------------- 1 | <div class="exercise admonition" id="exercise/_enum_title_nolabel-exercise-0"> 2 | <p class="admonition-title"><span class="caption-number">Exercise 4 </span> (Test exercise directive)</p> 3 | <section id="exercise-content"> 4 | <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</p> 5 | </section> 6 | </div> -------------------------------------------------------------------------------- /tests/test_exercise/_enum_title_nolabel.xml: -------------------------------------------------------------------------------- 1 | <document source="_enum_title_nolabel.rst"> 2 | <section ids="enum-title-nolabel" names="_enum_title_nolabel"> 3 | <title> 4 | _enum_title_nolabel 5 | <exercise_enumerable_node classes="exercise" docname="exercise/_enum_title_nolabel" hidden="False" ids="exercise/_enum_title_nolabel-exercise-0" label="exercise/_enum_title_nolabel-exercise-0" names="exercise/_enum_title_nolabel-exercise-0" serial_number="0" title="Exercise" type="exercise"> 6 | <exercise_title> 7 | Exercise 8 | <exercise_subtitle> 9 | Test exercise directive 10 | <section ids="exercise-content"> 11 | <paragraph> 12 | Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. 13 | -------------------------------------------------------------------------------- /tests/test_exercise/_unenum_mathtitle_label.html: -------------------------------------------------------------------------------- 1 | <div class="exercise admonition" id="unen-exc-label-math"> 2 | <p class="admonition-title">Exercise (Test <span class="math notranslate nohighlight">\(\mathbb{R}\)</span>)</p> 3 | <section id="exercise-content"> 4 | <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</p> 5 | </section> 6 | </div> -------------------------------------------------------------------------------- /tests/test_exercise/_unenum_mathtitle_label.xml: -------------------------------------------------------------------------------- 1 | <document source="_unenum_mathtitle_label.rst"> 2 | <section ids="unenum-mathtitle-label" names="_unenum_mathtitle_label"> 3 | <title> 4 | _unenum_mathtitle_label 5 | <exercise_node classes="exercise" docname="exercise/_unenum_mathtitle_label" hidden="False" ids="unen-exc-label-math" label="unen-exc-label-math" names="unen-exc-label-math" serial_number="0" title="Exercise" type="exercise"> 6 | <exercise_title> 7 | Exercise 8 | <exercise_subtitle> 9 | Test 10 | <math> 11 | \mathbb{R} 12 | <section ids="exercise-content"> 13 | <paragraph> 14 | Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. 15 | -------------------------------------------------------------------------------- /tests/test_exercise/_unenum_notitle_label.html: -------------------------------------------------------------------------------- 1 | <div class="exercise admonition" id="unen-exc-notitle"> 2 | <p class="admonition-title">Exercise</p> 3 | <section id="exercise-content"> 4 | <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</p> 5 | </section> 6 | </div> -------------------------------------------------------------------------------- /tests/test_exercise/_unenum_notitle_label.xml: -------------------------------------------------------------------------------- 1 | <document source="_unenum_notitle_label.rst"> 2 | <section ids="unenum-notitle-label" names="_unenum_notitle_label"> 3 | <title> 4 | _unenum_notitle_label 5 | <exercise_node classes="exercise" docname="exercise/_unenum_notitle_label" hidden="False" ids="unen-exc-notitle" label="unen-exc-notitle" names="unen-exc-notitle" serial_number="0" title="Exercise" type="exercise"> 6 | <exercise_title> 7 | Exercise 8 | <section ids="exercise-content"> 9 | <paragraph> 10 | Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. 11 | -------------------------------------------------------------------------------- /tests/test_exercise/_unenum_title_class_label.html: -------------------------------------------------------------------------------- 1 | <div class="exercise unen-exc admonition" id="unen-exc-label"> 2 | <p class="admonition-title">Exercise (Test exercise directive)</p> 3 | <section id="exercise-content"> 4 | <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</p> 5 | </section> 6 | </div> -------------------------------------------------------------------------------- /tests/test_exercise/_unenum_title_class_label.xml: -------------------------------------------------------------------------------- 1 | <document source="_unenum_title_class_label.rst"> 2 | <section ids="unenum-title-class-label" names="_unenum_title_class_label"> 3 | <title> 4 | _unenum_title_class_label 5 | <exercise_node classes="exercise unen-exc" docname="exercise/_unenum_title_class_label" hidden="False" ids="unen-exc-label" label="unen-exc-label" names="unen-exc-label" serial_number="0" title="Exercise" type="exercise"> 6 | <exercise_title> 7 | Exercise 8 | <exercise_subtitle> 9 | Test exercise directive 10 | <section ids="exercise-content"> 11 | <paragraph> 12 | Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. 13 | -------------------------------------------------------------------------------- /tests/test_exercise/_unenum_title_nolabel.html: -------------------------------------------------------------------------------- 1 | <div class="exercise admonition" id="exercise/_unenum_title_nolabel-exercise-0"> 2 | <p class="admonition-title">Exercise (Test exercise directive)</p> 3 | <section id="exercise-content"> 4 | <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</p> 5 | </section> 6 | </div> -------------------------------------------------------------------------------- /tests/test_exercise/_unenum_title_nolabel.xml: -------------------------------------------------------------------------------- 1 | <document source="_unenum_title_nolabel.rst"> 2 | <section ids="unenum-title-nolabel" names="_unenum_title_nolabel"> 3 | <title> 4 | _unenum_title_nolabel 5 | <exercise_node classes="exercise" docname="exercise/_unenum_title_nolabel" hidden="False" ids="exercise/_unenum_title_nolabel-exercise-0" label="exercise/_unenum_title_nolabel-exercise-0" names="exercise/_unenum_title_nolabel-exercise-0" serial_number="0" title="Exercise" type="exercise"> 6 | <exercise_title> 7 | Exercise 8 | <exercise_subtitle> 9 | Test exercise directive 10 | <section ids="exercise-content"> 11 | <paragraph> 12 | Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. 13 | -------------------------------------------------------------------------------- /tests/test_exercise_references.py: -------------------------------------------------------------------------------- 1 | from bs4 import BeautifulSoup 2 | import pytest 3 | 4 | 5 | @pytest.mark.sphinx("html", testroot="mybook") 6 | @pytest.mark.parametrize( 7 | "idir", 8 | [ 9 | "_enum_ref_mathtitle.html", 10 | "_enum_ref_notitle.html", 11 | "_enum_ref_title.html", 12 | "_enum_numref_mathtitle.html", 13 | "_enum_numref_notitle.html", 14 | "_enum_numref_title.html", 15 | "_unenum_ref_mathtitle.html", 16 | "_unenum_ref_notitle.html", 17 | "_unenum_ref_title.html", 18 | "_unenum_numref_mathtitle.html", 19 | "_unenum_numref_notitle.html", 20 | "_unenum_numref_title.html", 21 | "_enum_numref_placeholders.html", 22 | ], 23 | ) 24 | def test_reference(app, idir, file_regression): 25 | """Test exercise ref and numref role markup.""" 26 | app.builder.build_all() 27 | path_exc_directive = app.outdir / "exercise" / idir 28 | assert path_exc_directive.exists() 29 | # get content markup 30 | soup = BeautifulSoup(path_exc_directive.read_text(encoding="utf8"), "html.parser") 31 | 32 | excs = "" 33 | all_refs = soup.select("p") 34 | for ref in all_refs: 35 | excs += f"{ref}\n" 36 | 37 | file_regression.check( 38 | str(excs[:-1]), basename=idir.split(".")[0], extension=".html" 39 | ) 40 | 41 | 42 | @pytest.mark.sphinx("html", testroot="mybook") 43 | @pytest.mark.parametrize( 44 | "docname", 45 | [ 46 | "_enum_numref_mathtitle", 47 | "_enum_numref_notitle", 48 | "_enum_numref_placeholders", 49 | "_enum_numref_title", 50 | "_enum_ref_mathtitle", 51 | "_enum_ref_notitle", 52 | "_enum_ref_title", 53 | "_unenum_numref_mathtitle", 54 | "_unenum_numref_notitle", 55 | "_unenum_numref_title", 56 | "_unenum_ref_mathtitle", 57 | "_unenum_ref_notitle", 58 | "_unenum_ref_title", 59 | ], 60 | ) 61 | def test_exercise_doctree(app, docname, file_regression, get_sphinx_app_doctree): 62 | app.build() 63 | docname = "exercise" + "/" + docname 64 | get_sphinx_app_doctree( 65 | app, 66 | docname, 67 | resolve=False, 68 | regress=True, 69 | flatten_outdir=True, # noqa: E501 flatten files "solution/<file> -> <file>.xml" for convenience 70 | ) 71 | -------------------------------------------------------------------------------- /tests/test_exercise_references/_enum_numref_mathtitle.html: -------------------------------------------------------------------------------- 1 | <p>This is a reference <a class="reference internal" href="_enum_mathtitle_label.html#test-exc-label-math"><span class="std std-numref">Exercise 1</span></a>.</p> 2 | <p>This is a second reference <a class="reference internal" href="_enum_mathtitle_label.html#test-exc-label-math"><span class="std std-numref">some text 1</span></a>.</p> 3 | <p>This is a third reference <a class="reference internal" href="_enum_mathtitle_label.html#test-exc-label-math"><span class="std std-numref">some text 1</span></a>.</p> 4 | <p>This is a fourth reference <a class="reference internal" href="_enum_mathtitle_label.html#test-exc-label-math"><span class="std std-numref">some text Exercise</span></a>.</p> -------------------------------------------------------------------------------- /tests/test_exercise_references/_enum_numref_mathtitle.xml: -------------------------------------------------------------------------------- 1 | <document source="_enum_numref_mathtitle.rst"> 2 | <section ids="enum-numref-mathtitle" names="_enum_numref_mathtitle"> 3 | <title> 4 | _enum_numref_mathtitle 5 | <paragraph> 6 | This is a reference 7 | <pending_xref refdoc="exercise/_enum_numref_mathtitle" refdomain="std" refexplicit="False" reftarget="test-exc-label-math" reftype="numref" refwarn="True"> 8 | <literal classes="xref std std-numref"> 9 | test-exc-label-math 10 | . 11 | <paragraph> 12 | This is a second reference 13 | <pending_xref refdoc="exercise/_enum_numref_mathtitle" refdomain="std" refexplicit="True" reftarget="test-exc-label-math" reftype="numref" refwarn="True"> 14 | <literal classes="xref std std-numref"> 15 | some text %s 16 | . 17 | <paragraph> 18 | This is a third reference 19 | <pending_xref refdoc="exercise/_enum_numref_mathtitle" refdomain="std" refexplicit="True" reftarget="test-exc-label-math" reftype="numref" refwarn="True"> 20 | <literal classes="xref std std-numref"> 21 | some text {number} 22 | . 23 | <paragraph> 24 | This is a fourth reference 25 | <pending_xref refdoc="exercise/_enum_numref_mathtitle" refdomain="std" refexplicit="True" reftarget="test-exc-label-math" reftype="numref" refwarn="True"> 26 | <literal classes="xref std std-numref"> 27 | some text {name} 28 | . 29 | -------------------------------------------------------------------------------- /tests/test_exercise_references/_enum_numref_notitle.html: -------------------------------------------------------------------------------- 1 | <p>This is a reference <a class="reference internal" href="_enum_notitle_label.html#text-exc-notitle"><span class="std std-numref">Exercise 2</span></a>.</p> 2 | <p>This is a second reference <a class="reference internal" href="_enum_notitle_label.html#text-exc-notitle"><span class="std std-numref">some text 2</span></a>.</p> 3 | <p>This is a third reference <a class="reference internal" href="_enum_notitle_label.html#text-exc-notitle"><span class="std std-numref">some text 2</span></a>.</p> 4 | <p>This is a fourth reference <a class="reference internal" href="_enum_notitle_label.html#text-exc-notitle"><span class="std std-numref">some text Exercise</span></a>.</p> -------------------------------------------------------------------------------- /tests/test_exercise_references/_enum_numref_notitle.xml: -------------------------------------------------------------------------------- 1 | <document source="_enum_numref_notitle.rst"> 2 | <section ids="enum-numref-notitle" names="_enum_numref_notitle"> 3 | <title> 4 | _enum_numref_notitle 5 | <paragraph> 6 | This is a reference 7 | <pending_xref refdoc="exercise/_enum_numref_notitle" refdomain="std" refexplicit="False" reftarget="text-exc-notitle" reftype="numref" refwarn="True"> 8 | <literal classes="xref std std-numref"> 9 | text-exc-notitle 10 | . 11 | <paragraph> 12 | This is a second reference 13 | <pending_xref refdoc="exercise/_enum_numref_notitle" refdomain="std" refexplicit="True" reftarget="text-exc-notitle" reftype="numref" refwarn="True"> 14 | <literal classes="xref std std-numref"> 15 | some text %s 16 | . 17 | <paragraph> 18 | This is a third reference 19 | <pending_xref refdoc="exercise/_enum_numref_notitle" refdomain="std" refexplicit="True" reftarget="text-exc-notitle" reftype="numref" refwarn="True"> 20 | <literal classes="xref std std-numref"> 21 | some text {number} 22 | . 23 | <paragraph> 24 | This is a fourth reference 25 | <pending_xref refdoc="exercise/_enum_numref_notitle" refdomain="std" refexplicit="True" reftarget="text-exc-notitle" reftype="numref" refwarn="True"> 26 | <literal classes="xref std std-numref"> 27 | some text {name} 28 | . 29 | -------------------------------------------------------------------------------- /tests/test_exercise_references/_enum_numref_placeholders.html: -------------------------------------------------------------------------------- 1 | <p>This reference does not include math <a class="reference internal" href="_enum_title_class_label.html#test-exc-label"><span class="std std-numref">some 3 text %s test Exercise</span></a>.</p> 2 | <p>This reference does not include math <a class="reference internal" href="_enum_title_class_label.html#test-exc-label"><span class="std std-numref">some 3 text %s test</span></a>.</p> 3 | <p>This reference does not include math <a class="reference internal" href="_enum_title_class_label.html#test-exc-label"><span class="std std-numref">some Exercise text %s test</span></a>.</p> 4 | <p>This reference does not include math <a class="reference internal" href="_enum_title_class_label.html#test-exc-label"><span class="std std-numref">some Exercise text 3 test</span></a>.</p> 5 | <p>This reference does not include math <a class="reference internal" href="_enum_title_class_label.html#test-exc-label"><span class="std std-numref">some 3 text test</span></a>.</p> 6 | <p>This reference includes math <a class="reference internal" href="_enum_mathtitle_label.html#test-exc-label-math"><span class="std std-numref">some 1 text %s test Exercise</span></a>.</p> 7 | <p>This reference includes math <a class="reference internal" href="_enum_mathtitle_label.html#test-exc-label-math"><span class="std std-numref">some 1 text %s test</span></a>.</p> 8 | <p>This reference includes math <a class="reference internal" href="_enum_mathtitle_label.html#test-exc-label-math"><span class="std std-numref">some Exercise text %s test</span></a>.</p> 9 | <p>This reference includes math <a class="reference internal" href="_enum_mathtitle_label.html#test-exc-label-math"><span class="std std-numref">some Exercise text 1 test</span></a>.</p> 10 | <p>This reference includes math <a class="reference internal" href="_enum_mathtitle_label.html#test-exc-label-math"><span class="std std-numref">some 1 text test</span></a>.</p> -------------------------------------------------------------------------------- /tests/test_exercise_references/_enum_numref_placeholders.xml: -------------------------------------------------------------------------------- 1 | <document source="_enum_numref_placeholders.rst"> 2 | <section ids="enum-numref-placeholders" names="_enum_numref_placeholders"> 3 | <title> 4 | _enum_numref_placeholders 5 | <paragraph> 6 | This reference does not include math 7 | <pending_xref refdoc="exercise/_enum_numref_placeholders" refdomain="std" refexplicit="True" reftarget="test-exc-label" reftype="numref" refwarn="True"> 8 | <literal classes="xref std std-numref"> 9 | some {number} text %s test {name} 10 | . 11 | <paragraph> 12 | This reference does not include math 13 | <pending_xref refdoc="exercise/_enum_numref_placeholders" refdomain="std" refexplicit="True" reftarget="test-exc-label" reftype="numref" refwarn="True"> 14 | <literal classes="xref std std-numref"> 15 | some {number} text %s test 16 | . 17 | <paragraph> 18 | This reference does not include math 19 | <pending_xref refdoc="exercise/_enum_numref_placeholders" refdomain="std" refexplicit="True" reftarget="test-exc-label" reftype="numref" refwarn="True"> 20 | <literal classes="xref std std-numref"> 21 | some {name} text %s test 22 | . 23 | <paragraph> 24 | This reference does not include math 25 | <pending_xref refdoc="exercise/_enum_numref_placeholders" refdomain="std" refexplicit="True" reftarget="test-exc-label" reftype="numref" refwarn="True"> 26 | <literal classes="xref std std-numref"> 27 | some {name} text {number} test 28 | . 29 | <paragraph> 30 | This reference does not include math 31 | <pending_xref refdoc="exercise/_enum_numref_placeholders" refdomain="std" refexplicit="True" reftarget="test-exc-label" reftype="numref" refwarn="True"> 32 | <literal classes="xref std std-numref"> 33 | some %s text test 34 | . 35 | <paragraph> 36 | This reference includes math 37 | <pending_xref refdoc="exercise/_enum_numref_placeholders" refdomain="std" refexplicit="True" reftarget="test-exc-label-math" reftype="numref" refwarn="True"> 38 | <literal classes="xref std std-numref"> 39 | some {number} text %s test {name} 40 | . 41 | <paragraph> 42 | This reference includes math 43 | <pending_xref refdoc="exercise/_enum_numref_placeholders" refdomain="std" refexplicit="True" reftarget="test-exc-label-math" reftype="numref" refwarn="True"> 44 | <literal classes="xref std std-numref"> 45 | some {number} text %s test 46 | . 47 | <paragraph> 48 | This reference includes math 49 | <pending_xref refdoc="exercise/_enum_numref_placeholders" refdomain="std" refexplicit="True" reftarget="test-exc-label-math" reftype="numref" refwarn="True"> 50 | <literal classes="xref std std-numref"> 51 | some {name} text %s test 52 | . 53 | <paragraph> 54 | This reference includes math 55 | <pending_xref refdoc="exercise/_enum_numref_placeholders" refdomain="std" refexplicit="True" reftarget="test-exc-label-math" reftype="numref" refwarn="True"> 56 | <literal classes="xref std std-numref"> 57 | some {name} text {number} test 58 | . 59 | <paragraph> 60 | This reference includes math 61 | <pending_xref refdoc="exercise/_enum_numref_placeholders" refdomain="std" refexplicit="True" reftarget="test-exc-label-math" reftype="numref" refwarn="True"> 62 | <literal classes="xref std std-numref"> 63 | some %s text test 64 | . 65 | -------------------------------------------------------------------------------- /tests/test_exercise_references/_enum_numref_title.html: -------------------------------------------------------------------------------- 1 | <p>This is a reference <a class="reference internal" href="_enum_title_class_label.html#test-exc-label"><span class="std std-numref">Exercise 3</span></a>.</p> 2 | <p>This is a second reference <a class="reference internal" href="_enum_title_class_label.html#test-exc-label"><span class="std std-numref">some text 3</span></a>.</p> 3 | <p>This is a third reference <a class="reference internal" href="_enum_title_class_label.html#test-exc-label"><span class="std std-numref">some text 3</span></a>.</p> 4 | <p>This is a fourth reference <a class="reference internal" href="_enum_title_class_label.html#test-exc-label"><span class="std std-numref">some text Exercise</span></a>.</p> -------------------------------------------------------------------------------- /tests/test_exercise_references/_enum_numref_title.xml: -------------------------------------------------------------------------------- 1 | <document source="_enum_numref_title.rst"> 2 | <section ids="enum-numref-title" names="_enum_numref_title"> 3 | <title> 4 | _enum_numref_title 5 | <paragraph> 6 | This is a reference 7 | <pending_xref refdoc="exercise/_enum_numref_title" refdomain="std" refexplicit="False" reftarget="test-exc-label" reftype="numref" refwarn="True"> 8 | <literal classes="xref std std-numref"> 9 | test-exc-label 10 | . 11 | <paragraph> 12 | This is a second reference 13 | <pending_xref refdoc="exercise/_enum_numref_title" refdomain="std" refexplicit="True" reftarget="test-exc-label" reftype="numref" refwarn="True"> 14 | <literal classes="xref std std-numref"> 15 | some text %s 16 | . 17 | <paragraph> 18 | This is a third reference 19 | <pending_xref refdoc="exercise/_enum_numref_title" refdomain="std" refexplicit="True" reftarget="test-exc-label" reftype="numref" refwarn="True"> 20 | <literal classes="xref std std-numref"> 21 | some text {number} 22 | . 23 | <paragraph> 24 | This is a fourth reference 25 | <pending_xref refdoc="exercise/_enum_numref_title" refdomain="std" refexplicit="True" reftarget="test-exc-label" reftype="numref" refwarn="True"> 26 | <literal classes="xref std std-numref"> 27 | some text {name} 28 | . 29 | -------------------------------------------------------------------------------- /tests/test_exercise_references/_enum_ref_mathtitle.html: -------------------------------------------------------------------------------- 1 | <p>This is a reference <a class="reference internal" href="_enum_mathtitle_label.html#test-exc-label-math"><span class="std std-numref">Exercise 1</span></a>.</p> 2 | <p>This is a second reference <a class="reference internal" href="_enum_mathtitle_label.html#test-exc-label-math"><span class="std std-ref">some text</span></a>.</p> -------------------------------------------------------------------------------- /tests/test_exercise_references/_enum_ref_mathtitle.xml: -------------------------------------------------------------------------------- 1 | <document source="_enum_ref_mathtitle.rst"> 2 | <section ids="enum-ref-mathtitle" names="_enum_ref_mathtitle"> 3 | <title> 4 | _enum_ref_mathtitle 5 | <paragraph> 6 | This is a reference 7 | <pending_xref refdoc="exercise/_enum_ref_mathtitle" refdomain="std" refexplicit="False" reftarget="test-exc-label-math" reftype="ref" refwarn="True"> 8 | <inline classes="xref std std-ref"> 9 | test-exc-label-math 10 | . 11 | <paragraph> 12 | This is a second reference 13 | <pending_xref refdoc="exercise/_enum_ref_mathtitle" refdomain="std" refexplicit="True" reftarget="test-exc-label-math" reftype="ref" refwarn="True"> 14 | <inline classes="xref std std-ref"> 15 | some text 16 | . 17 | -------------------------------------------------------------------------------- /tests/test_exercise_references/_enum_ref_notitle.html: -------------------------------------------------------------------------------- 1 | <p>This is a reference <a class="reference internal" href="_enum_notitle_label.html#text-exc-notitle"><span class="std std-numref">Exercise 2</span></a>.</p> 2 | <p>This is a second reference <a class="reference internal" href="_enum_notitle_label.html#text-exc-notitle"><span class="std std-ref">some text</span></a>.</p> -------------------------------------------------------------------------------- /tests/test_exercise_references/_enum_ref_notitle.xml: -------------------------------------------------------------------------------- 1 | <document source="_enum_ref_notitle.rst"> 2 | <section ids="enum-ref-notitle" names="_enum_ref_notitle"> 3 | <title> 4 | _enum_ref_notitle 5 | <paragraph> 6 | This is a reference 7 | <pending_xref refdoc="exercise/_enum_ref_notitle" refdomain="std" refexplicit="False" reftarget="text-exc-notitle" reftype="ref" refwarn="True"> 8 | <inline classes="xref std std-ref"> 9 | text-exc-notitle 10 | . 11 | <paragraph> 12 | This is a second reference 13 | <pending_xref refdoc="exercise/_enum_ref_notitle" refdomain="std" refexplicit="True" reftarget="text-exc-notitle" reftype="ref" refwarn="True"> 14 | <inline classes="xref std std-ref"> 15 | some text 16 | . 17 | -------------------------------------------------------------------------------- /tests/test_exercise_references/_enum_ref_title.html: -------------------------------------------------------------------------------- 1 | <p>This is a reference <a class="reference internal" href="_enum_title_class_label.html#test-exc-label"><span class="std std-numref">Exercise 3</span></a>.</p> 2 | <p>This is a second reference <a class="reference internal" href="_enum_title_class_label.html#test-exc-label"><span class="std std-ref">some text</span></a>.</p> -------------------------------------------------------------------------------- /tests/test_exercise_references/_enum_ref_title.xml: -------------------------------------------------------------------------------- 1 | <document source="_enum_ref_title.rst"> 2 | <section ids="enum-ref-title" names="_enum_ref_title"> 3 | <title> 4 | _enum_ref_title 5 | <paragraph> 6 | This is a reference 7 | <pending_xref refdoc="exercise/_enum_ref_title" refdomain="std" refexplicit="False" reftarget="test-exc-label" reftype="ref" refwarn="True"> 8 | <inline classes="xref std std-ref"> 9 | test-exc-label 10 | . 11 | <paragraph> 12 | This is a second reference 13 | <pending_xref refdoc="exercise/_enum_ref_title" refdomain="std" refexplicit="True" reftarget="test-exc-label" reftype="ref" refwarn="True"> 14 | <inline classes="xref std std-ref"> 15 | some text 16 | . 17 | -------------------------------------------------------------------------------- /tests/test_exercise_references/_unenum_numref_mathtitle.html: -------------------------------------------------------------------------------- 1 | <p>This is a reference <code class="xref std std-numref docutils literal notranslate"><span class="pre">unen-exc-label-math</span></code>.</p> 2 | <p>This is a second reference <code class="xref std std-numref docutils literal notranslate"><span class="pre">some</span> <span class="pre">text</span> <span class="pre">%s</span></code>.</p> 3 | <p>This is a third reference <code class="xref std std-numref docutils literal notranslate"><span class="pre">some</span> <span class="pre">text</span> <span class="pre">{number}</span></code>.</p> 4 | <p>This is a fourth reference <code class="xref std std-numref docutils literal notranslate"><span class="pre">some</span> <span class="pre">text</span> <span class="pre">{name}</span></code>.</p> -------------------------------------------------------------------------------- /tests/test_exercise_references/_unenum_numref_mathtitle.xml: -------------------------------------------------------------------------------- 1 | <document source="_unenum_numref_mathtitle.rst"> 2 | <section ids="unenum-numref-mathtitle" names="_unenum_numref_mathtitle"> 3 | <title> 4 | _unenum_numref_mathtitle 5 | <paragraph> 6 | This is a reference 7 | <pending_xref refdoc="exercise/_unenum_numref_mathtitle" refdomain="std" refexplicit="False" reftarget="unen-exc-label-math" reftype="numref" refwarn="True"> 8 | <literal classes="xref std std-numref"> 9 | unen-exc-label-math 10 | . 11 | <paragraph> 12 | This is a second reference 13 | <pending_xref refdoc="exercise/_unenum_numref_mathtitle" refdomain="std" refexplicit="True" reftarget="unen-exc-label-math" reftype="numref" refwarn="True"> 14 | <literal classes="xref std std-numref"> 15 | some text %s 16 | . 17 | <paragraph> 18 | This is a third reference 19 | <pending_xref refdoc="exercise/_unenum_numref_mathtitle" refdomain="std" refexplicit="True" reftarget="unen-exc-label-math" reftype="numref" refwarn="True"> 20 | <literal classes="xref std std-numref"> 21 | some text {number} 22 | . 23 | <paragraph> 24 | This is a fourth reference 25 | <pending_xref refdoc="exercise/_unenum_numref_mathtitle" refdomain="std" refexplicit="True" reftarget="unen-exc-label-math" reftype="numref" refwarn="True"> 26 | <literal classes="xref std std-numref"> 27 | some text {name} 28 | . 29 | -------------------------------------------------------------------------------- /tests/test_exercise_references/_unenum_numref_notitle.html: -------------------------------------------------------------------------------- 1 | <p>This is a reference <code class="xref std std-numref docutils literal notranslate"><span class="pre">unen-exc-notitle</span></code>.</p> 2 | <p>This is a second reference <code class="xref std std-numref docutils literal notranslate"><span class="pre">some</span> <span class="pre">text</span> <span class="pre">%s</span></code>.</p> 3 | <p>This is a third reference <code class="xref std std-numref docutils literal notranslate"><span class="pre">some</span> <span class="pre">text</span> <span class="pre">{number}</span></code>.</p> 4 | <p>This is a fourth reference <code class="xref std std-numref docutils literal notranslate"><span class="pre">some</span> <span class="pre">text</span> <span class="pre">{name}</span></code>.</p> -------------------------------------------------------------------------------- /tests/test_exercise_references/_unenum_numref_notitle.xml: -------------------------------------------------------------------------------- 1 | <document source="_unenum_numref_notitle.rst"> 2 | <section ids="unenum-numref-notitle" names="_unenum_numref_notitle"> 3 | <title> 4 | _unenum_numref_notitle 5 | <paragraph> 6 | This is a reference 7 | <pending_xref refdoc="exercise/_unenum_numref_notitle" refdomain="std" refexplicit="False" reftarget="unen-exc-notitle" reftype="numref" refwarn="True"> 8 | <literal classes="xref std std-numref"> 9 | unen-exc-notitle 10 | . 11 | <paragraph> 12 | This is a second reference 13 | <pending_xref refdoc="exercise/_unenum_numref_notitle" refdomain="std" refexplicit="True" reftarget="unen-exc-notitle" reftype="numref" refwarn="True"> 14 | <literal classes="xref std std-numref"> 15 | some text %s 16 | . 17 | <paragraph> 18 | This is a third reference 19 | <pending_xref refdoc="exercise/_unenum_numref_notitle" refdomain="std" refexplicit="True" reftarget="unen-exc-notitle" reftype="numref" refwarn="True"> 20 | <literal classes="xref std std-numref"> 21 | some text {number} 22 | . 23 | <paragraph> 24 | This is a fourth reference 25 | <pending_xref refdoc="exercise/_unenum_numref_notitle" refdomain="std" refexplicit="True" reftarget="unen-exc-notitle" reftype="numref" refwarn="True"> 26 | <literal classes="xref std std-numref"> 27 | some text {name} 28 | . 29 | -------------------------------------------------------------------------------- /tests/test_exercise_references/_unenum_numref_title.html: -------------------------------------------------------------------------------- 1 | <p>This is a reference <code class="xref std std-numref docutils literal notranslate"><span class="pre">unen-exc-label</span></code>.</p> 2 | <p>This is a second reference <code class="xref std std-numref docutils literal notranslate"><span class="pre">some</span> <span class="pre">text</span> <span class="pre">%s</span></code>.</p> 3 | <p>This is a third reference <code class="xref std std-numref docutils literal notranslate"><span class="pre">some</span> <span class="pre">text</span> <span class="pre">{number}</span></code>.</p> 4 | <p>This is a fourth reference <code class="xref std std-numref docutils literal notranslate"><span class="pre">some</span> <span class="pre">text</span> <span class="pre">{name}</span></code>.</p> -------------------------------------------------------------------------------- /tests/test_exercise_references/_unenum_numref_title.xml: -------------------------------------------------------------------------------- 1 | <document source="_unenum_numref_title.rst"> 2 | <section ids="unenum-numref-title" names="_unenum_numref_title"> 3 | <title> 4 | _unenum_numref_title 5 | <paragraph> 6 | This is a reference 7 | <pending_xref refdoc="exercise/_unenum_numref_title" refdomain="std" refexplicit="False" reftarget="unen-exc-label" reftype="numref" refwarn="True"> 8 | <literal classes="xref std std-numref"> 9 | unen-exc-label 10 | . 11 | <paragraph> 12 | This is a second reference 13 | <pending_xref refdoc="exercise/_unenum_numref_title" refdomain="std" refexplicit="True" reftarget="unen-exc-label" reftype="numref" refwarn="True"> 14 | <literal classes="xref std std-numref"> 15 | some text %s 16 | . 17 | <paragraph> 18 | This is a third reference 19 | <pending_xref refdoc="exercise/_unenum_numref_title" refdomain="std" refexplicit="True" reftarget="unen-exc-label" reftype="numref" refwarn="True"> 20 | <literal classes="xref std std-numref"> 21 | some text {number} 22 | . 23 | <paragraph> 24 | This is a fourth reference 25 | <pending_xref refdoc="exercise/_unenum_numref_title" refdomain="std" refexplicit="True" reftarget="unen-exc-label" reftype="numref" refwarn="True"> 26 | <literal classes="xref std std-numref"> 27 | some text {name} 28 | . 29 | -------------------------------------------------------------------------------- /tests/test_exercise_references/_unenum_ref_mathtitle.html: -------------------------------------------------------------------------------- 1 | <p>This is a reference <a class="reference internal" href="_unenum_mathtitle_label.html#unen-exc-label-math"><span class="std std-ref">Exercise</span></a>.</p> 2 | <p>This is a second reference <a class="reference internal" href="_unenum_mathtitle_label.html#unen-exc-label-math"><span class="std std-ref">some text</span></a>.</p> -------------------------------------------------------------------------------- /tests/test_exercise_references/_unenum_ref_mathtitle.xml: -------------------------------------------------------------------------------- 1 | <document source="_unenum_ref_mathtitle.rst"> 2 | <section ids="unenum-ref-mathtitle" names="_unenum_ref_mathtitle"> 3 | <title> 4 | _unenum_ref_mathtitle 5 | <paragraph> 6 | This is a reference 7 | <pending_xref refdoc="exercise/_unenum_ref_mathtitle" refdomain="std" refexplicit="False" reftarget="unen-exc-label-math" reftype="ref" refwarn="True"> 8 | <inline classes="xref std std-ref"> 9 | unen-exc-label-math 10 | . 11 | <paragraph> 12 | This is a second reference 13 | <pending_xref refdoc="exercise/_unenum_ref_mathtitle" refdomain="std" refexplicit="True" reftarget="unen-exc-label-math" reftype="ref" refwarn="True"> 14 | <inline classes="xref std std-ref"> 15 | some text 16 | . 17 | -------------------------------------------------------------------------------- /tests/test_exercise_references/_unenum_ref_notitle.html: -------------------------------------------------------------------------------- 1 | <p>This is a reference <a class="reference internal" href="_unenum_notitle_label.html#unen-exc-notitle"><span class="std std-ref">Exercise</span></a>.</p> 2 | <p>This is a second reference <a class="reference internal" href="_unenum_notitle_label.html#unen-exc-notitle"><span class="std std-ref">some text</span></a>.</p> -------------------------------------------------------------------------------- /tests/test_exercise_references/_unenum_ref_notitle.xml: -------------------------------------------------------------------------------- 1 | <document source="_unenum_ref_notitle.rst"> 2 | <section ids="unenum-ref-notitle" names="_unenum_ref_notitle"> 3 | <title> 4 | _unenum_ref_notitle 5 | <paragraph> 6 | This is a reference 7 | <pending_xref refdoc="exercise/_unenum_ref_notitle" refdomain="std" refexplicit="False" reftarget="unen-exc-notitle" reftype="ref" refwarn="True"> 8 | <inline classes="xref std std-ref"> 9 | unen-exc-notitle 10 | . 11 | <paragraph> 12 | This is a second reference 13 | <pending_xref refdoc="exercise/_unenum_ref_notitle" refdomain="std" refexplicit="True" reftarget="unen-exc-notitle" reftype="ref" refwarn="True"> 14 | <inline classes="xref std std-ref"> 15 | some text 16 | . 17 | -------------------------------------------------------------------------------- /tests/test_exercise_references/_unenum_ref_title.html: -------------------------------------------------------------------------------- 1 | <p>This is a reference <a class="reference internal" href="_unenum_title_class_label.html#unen-exc-label"><span class="std std-ref">Exercise</span></a>.</p> 2 | <p>This is a second reference <a class="reference internal" href="_unenum_title_class_label.html#unen-exc-label"><span class="std std-ref">some text</span></a>.</p> -------------------------------------------------------------------------------- /tests/test_exercise_references/_unenum_ref_title.xml: -------------------------------------------------------------------------------- 1 | <document source="_unenum_ref_title.rst"> 2 | <section ids="unenum-ref-title" names="_unenum_ref_title"> 3 | <title> 4 | _unenum_ref_title 5 | <paragraph> 6 | This is a reference 7 | <pending_xref refdoc="exercise/_unenum_ref_title" refdomain="std" refexplicit="False" reftarget="unen-exc-label" reftype="ref" refwarn="True"> 8 | <inline classes="xref std std-ref"> 9 | unen-exc-label 10 | . 11 | <paragraph> 12 | This is a second reference 13 | <pending_xref refdoc="exercise/_unenum_ref_title" refdomain="std" refexplicit="True" reftarget="unen-exc-label" reftype="ref" refwarn="True"> 14 | <inline classes="xref std std-ref"> 15 | some text 16 | . 17 | -------------------------------------------------------------------------------- /tests/test_gateddirective/exercise-gated-0.html: -------------------------------------------------------------------------------- 1 | <div class="exercise admonition" id="gated-exercise-1"> 2 | <p class="admonition-title"><span class="caption-number">Exercise 3 </span></p> 3 | <section id="exercise-content"> 4 | <p>Replicate this figure using matplotlib</p> 5 | <figure class="align-default"> 6 | <img alt="_images/sphx_glr_cohere_001_2_0x.png" src="_images/sphx_glr_cohere_001_2_0x.png"/> 7 | </figure> 8 | </section> 9 | </div> -------------------------------------------------------------------------------- /tests/test_gateddirective/exercise-gated-1.html: -------------------------------------------------------------------------------- 1 | <div class="exercise admonition" id="gated-exercise-2"> 2 | <p class="admonition-title"><span class="caption-number">Exercise 4 </span> (Replicate Matplotlib Plot)</p> 3 | <section id="exercise-content"> 4 | <figure class="align-default"> 5 | <img alt="_images/sphx_glr_cohere_001_2_0x.png" src="_images/sphx_glr_cohere_001_2_0x.png"/> 6 | </figure> 7 | </section> 8 | </div> -------------------------------------------------------------------------------- /tests/test_gateddirective/exercise-gated.xml: -------------------------------------------------------------------------------- 1 | <document source="exercise-gated.md"> 2 | <section ids="gated-exercises" names="gated\ exercises"> 3 | <title> 4 | Gated Exercises 5 | <paragraph> 6 | Some Gated reference exercises 7 | <exercise_enumerable_node classes="exercise" docname="exercise-gated" hidden="False" ids="gated-exercise-1" label="gated-exercise-1" names="gated-exercise-1" serial_number="0" title="Exercise" type="exercise"> 8 | <exercise_title> 9 | Exercise 10 | <section ids="exercise-content"> 11 | <paragraph> 12 | Replicate this figure using matplotlib 13 | <figure> 14 | <image candidates="{'*': 'sphx_glr_cohere_001_2_0x.png'}" uri="sphx_glr_cohere_001_2_0x.png"> 15 | <paragraph> 16 | and another version with a title embedded 17 | <exercise_enumerable_node classes="exercise" docname="exercise-gated" hidden="False" ids="gated-exercise-2" label="gated-exercise-2" names="gated-exercise-2" serial_number="1" title="Exercise" type="exercise"> 18 | <exercise_title> 19 | Exercise 20 | <exercise_subtitle> 21 | Replicate Matplotlib Plot 22 | <section ids="exercise-content"> 23 | <figure> 24 | <image candidates="{'*': 'sphx_glr_cohere_001_2_0x.png'}" uri="sphx_glr_cohere_001_2_0x.png"> 25 | -------------------------------------------------------------------------------- /tests/test_gateddirective/solution-exercise-0.sphinx4.html: -------------------------------------------------------------------------------- 1 | <div class="solution admonition" id="solution-gated-1"> 2 | <p class="admonition-title">Solution to<a class="reference internal" href="exercise.html#exercise-1"> Exercise 1</a></p> 3 | <section id="solution-content"> 4 | <p>This is a solution to Non-Gated Exercise 1</p> 5 | <div class="cell docutils container"> 6 | <div class="cell_input docutils container"> 7 | <div class="highlight-ipython3 notranslate"><div class="highlight"><pre><span></span><span class="kn">import</span> <span class="nn">numpy</span> <span class="k">as</span> <span class="nn">np</span> 8 | <span class="kn">import</span> <span class="nn">matplotlib.pyplot</span> <span class="k">as</span> <span class="nn">plt</span> 9 | 10 | <span class="c1"># Fixing random state for reproducibility</span> 11 | <span class="n">np</span><span class="o">.</span><span class="n">random</span><span class="o">.</span><span class="n">seed</span><span class="p">(</span><span class="mi">19680801</span><span class="p">)</span> 12 | 13 | <span class="n">dt</span> <span class="o">=</span> <span class="mf">0.01</span> 14 | <span class="n">t</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">arange</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="mi">30</span><span class="p">,</span> <span class="n">dt</span><span class="p">)</span> 15 | <span class="n">nse1</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">random</span><span class="o">.</span><span class="n">randn</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="n">t</span><span class="p">))</span> <span class="c1"># white noise 1</span> 16 | <span class="n">nse2</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">random</span><span class="o">.</span><span class="n">randn</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="n">t</span><span class="p">))</span> <span class="c1"># white noise 2</span> 17 | 18 | <span class="c1"># Two signals with a coherent part at 10Hz and a random part</span> 19 | <span class="n">s1</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">sin</span><span class="p">(</span><span class="mi">2</span> <span class="o">*</span> <span class="n">np</span><span class="o">.</span><span class="n">pi</span> <span class="o">*</span> <span class="mi">10</span> <span class="o">*</span> <span class="n">t</span><span class="p">)</span> <span class="o">+</span> <span class="n">nse1</span> 20 | <span class="n">s2</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">sin</span><span class="p">(</span><span class="mi">2</span> <span class="o">*</span> <span class="n">np</span><span class="o">.</span><span class="n">pi</span> <span class="o">*</span> <span class="mi">10</span> <span class="o">*</span> <span class="n">t</span><span class="p">)</span> <span class="o">+</span> <span class="n">nse2</span> 21 | 22 | <span class="n">fig</span><span class="p">,</span> <span class="n">axs</span> <span class="o">=</span> <span class="n">plt</span><span class="o">.</span><span class="n">subplots</span><span class="p">(</span><span class="mi">2</span><span class="p">,</span> <span class="mi">1</span><span class="p">)</span> 23 | <span class="n">axs</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">.</span><span class="n">plot</span><span class="p">(</span><span class="n">t</span><span class="p">,</span> <span class="n">s1</span><span class="p">,</span> <span class="n">t</span><span class="p">,</span> <span class="n">s2</span><span class="p">)</span> 24 | <span class="n">axs</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">.</span><span class="n">set_xlim</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="mi">2</span><span class="p">)</span> 25 | <span class="n">axs</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">.</span><span class="n">set_xlabel</span><span class="p">(</span><span class="s1">'time'</span><span class="p">)</span> 26 | <span class="n">axs</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">.</span><span class="n">set_ylabel</span><span class="p">(</span><span class="s1">'s1 and s2'</span><span class="p">)</span> 27 | <span class="n">axs</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">.</span><span class="n">grid</span><span class="p">(</span><span class="kc">True</span><span class="p">)</span> 28 | 29 | <span class="n">cxy</span><span class="p">,</span> <span class="n">f</span> <span class="o">=</span> <span class="n">axs</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span><span class="o">.</span><span class="n">cohere</span><span class="p">(</span><span class="n">s1</span><span class="p">,</span> <span class="n">s2</span><span class="p">,</span> <span class="mi">256</span><span class="p">,</span> <span class="mf">1.</span> <span class="o">/</span> <span class="n">dt</span><span class="p">)</span> 30 | <span class="n">axs</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span><span class="o">.</span><span class="n">set_ylabel</span><span class="p">(</span><span class="s1">'coherence'</span><span class="p">)</span> 31 | 32 | <span class="n">fig</span><span class="o">.</span><span class="n">tight_layout</span><span class="p">()</span> 33 | <span class="n">plt</span><span class="o">.</span><span class="n">show</span><span class="p">()</span> 34 | </pre></div> 35 | </div> 36 | </div> 37 | <div class="cell_output docutils container"> 38 | <img alt="_images/fb8cd74f4c4564e8c76c8e3e5366246d555d3f09e311806843cf85f1e0bca298.png" src="_images/fb8cd74f4c4564e8c76c8e3e5366246d555d3f09e311806843cf85f1e0bca298.png"/> 39 | </div> 40 | </div> 41 | <p>With some follow up text to the solution</p> 42 | </section> 43 | </div> -------------------------------------------------------------------------------- /tests/test_gateddirective/solution-exercise-0.sphinx5.html: -------------------------------------------------------------------------------- 1 | <div class="solution admonition" id="solution-gated-1"> 2 | <p class="admonition-title">Solution to<a class="reference internal" href="exercise.html#exercise-1"> Exercise 1</a></p> 3 | <section id="solution-content"> 4 | <p>This is a solution to Non-Gated Exercise 1</p> 5 | <div class="cell docutils container"> 6 | <div class="cell_input docutils container"> 7 | <div class="highlight-ipython3 notranslate"><div class="highlight"><pre><span></span><span class="kn">import</span> <span class="nn">numpy</span> <span class="k">as</span> <span class="nn">np</span> 8 | <span class="kn">import</span> <span class="nn">matplotlib.pyplot</span> <span class="k">as</span> <span class="nn">plt</span> 9 | 10 | <span class="c1"># Fixing random state for reproducibility</span> 11 | <span class="n">np</span><span class="o">.</span><span class="n">random</span><span class="o">.</span><span class="n">seed</span><span class="p">(</span><span class="mi">19680801</span><span class="p">)</span> 12 | 13 | <span class="n">dt</span> <span class="o">=</span> <span class="mf">0.01</span> 14 | <span class="n">t</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">arange</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="mi">30</span><span class="p">,</span> <span class="n">dt</span><span class="p">)</span> 15 | <span class="n">nse1</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">random</span><span class="o">.</span><span class="n">randn</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="n">t</span><span class="p">))</span> <span class="c1"># white noise 1</span> 16 | <span class="n">nse2</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">random</span><span class="o">.</span><span class="n">randn</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="n">t</span><span class="p">))</span> <span class="c1"># white noise 2</span> 17 | 18 | <span class="c1"># Two signals with a coherent part at 10Hz and a random part</span> 19 | <span class="n">s1</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">sin</span><span class="p">(</span><span class="mi">2</span> <span class="o">*</span> <span class="n">np</span><span class="o">.</span><span class="n">pi</span> <span class="o">*</span> <span class="mi">10</span> <span class="o">*</span> <span class="n">t</span><span class="p">)</span> <span class="o">+</span> <span class="n">nse1</span> 20 | <span class="n">s2</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">sin</span><span class="p">(</span><span class="mi">2</span> <span class="o">*</span> <span class="n">np</span><span class="o">.</span><span class="n">pi</span> <span class="o">*</span> <span class="mi">10</span> <span class="o">*</span> <span class="n">t</span><span class="p">)</span> <span class="o">+</span> <span class="n">nse2</span> 21 | 22 | <span class="n">fig</span><span class="p">,</span> <span class="n">axs</span> <span class="o">=</span> <span class="n">plt</span><span class="o">.</span><span class="n">subplots</span><span class="p">(</span><span class="mi">2</span><span class="p">,</span> <span class="mi">1</span><span class="p">)</span> 23 | <span class="n">axs</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">.</span><span class="n">plot</span><span class="p">(</span><span class="n">t</span><span class="p">,</span> <span class="n">s1</span><span class="p">,</span> <span class="n">t</span><span class="p">,</span> <span class="n">s2</span><span class="p">)</span> 24 | <span class="n">axs</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">.</span><span class="n">set_xlim</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="mi">2</span><span class="p">)</span> 25 | <span class="n">axs</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">.</span><span class="n">set_xlabel</span><span class="p">(</span><span class="s1">'time'</span><span class="p">)</span> 26 | <span class="n">axs</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">.</span><span class="n">set_ylabel</span><span class="p">(</span><span class="s1">'s1 and s2'</span><span class="p">)</span> 27 | <span class="n">axs</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">.</span><span class="n">grid</span><span class="p">(</span><span class="kc">True</span><span class="p">)</span> 28 | 29 | <span class="n">cxy</span><span class="p">,</span> <span class="n">f</span> <span class="o">=</span> <span class="n">axs</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span><span class="o">.</span><span class="n">cohere</span><span class="p">(</span><span class="n">s1</span><span class="p">,</span> <span class="n">s2</span><span class="p">,</span> <span class="mi">256</span><span class="p">,</span> <span class="mf">1.</span> <span class="o">/</span> <span class="n">dt</span><span class="p">)</span> 30 | <span class="n">axs</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span><span class="o">.</span><span class="n">set_ylabel</span><span class="p">(</span><span class="s1">'coherence'</span><span class="p">)</span> 31 | 32 | <span class="n">fig</span><span class="o">.</span><span class="n">tight_layout</span><span class="p">()</span> 33 | <span class="n">plt</span><span class="o">.</span><span class="n">show</span><span class="p">()</span> 34 | </pre></div> 35 | </div> 36 | </div> 37 | <div class="cell_output docutils container"> 38 | <img alt="_images/59d5daa1f6a4a408595ce4674d8b8d720ff4281f9aaec5eedeabe6520af704f2.png" src="_images/59d5daa1f6a4a408595ce4674d8b8d720ff4281f9aaec5eedeabe6520af704f2.png"/> 39 | </div> 40 | </div> 41 | <p>With some follow up text to the solution</p> 42 | </section> 43 | </div> -------------------------------------------------------------------------------- /tests/test_gateddirective/solution-exercise-0.sphinx7.html: -------------------------------------------------------------------------------- 1 | <div class="solution admonition" id="solution-gated-1"> 2 | <p class="admonition-title">Solution to<a class="reference internal" href="exercise.html#exercise-1"> Exercise 1</a></p> 3 | <section id="solution-content"> 4 | <p>This is a solution to Non-Gated Exercise 1</p> 5 | <div class="cell docutils container"> 6 | <div class="cell_input docutils container"> 7 | <div class="highlight-ipython3 notranslate"><div class="highlight"><pre><span></span><span class="kn">import</span> <span class="nn">numpy</span> <span class="k">as</span> <span class="nn">np</span> 8 | <span class="kn">import</span> <span class="nn">matplotlib.pyplot</span> <span class="k">as</span> <span class="nn">plt</span> 9 | 10 | <span class="c1"># Fixing random state for reproducibility</span> 11 | <span class="n">np</span><span class="o">.</span><span class="n">random</span><span class="o">.</span><span class="n">seed</span><span class="p">(</span><span class="mi">19680801</span><span class="p">)</span> 12 | 13 | <span class="n">dt</span> <span class="o">=</span> <span class="mf">0.01</span> 14 | <span class="n">t</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">arange</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="mi">30</span><span class="p">,</span> <span class="n">dt</span><span class="p">)</span> 15 | <span class="n">nse1</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">random</span><span class="o">.</span><span class="n">randn</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="n">t</span><span class="p">))</span> <span class="c1"># white noise 1</span> 16 | <span class="n">nse2</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">random</span><span class="o">.</span><span class="n">randn</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="n">t</span><span class="p">))</span> <span class="c1"># white noise 2</span> 17 | 18 | <span class="c1"># Two signals with a coherent part at 10Hz and a random part</span> 19 | <span class="n">s1</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">sin</span><span class="p">(</span><span class="mi">2</span> <span class="o">*</span> <span class="n">np</span><span class="o">.</span><span class="n">pi</span> <span class="o">*</span> <span class="mi">10</span> <span class="o">*</span> <span class="n">t</span><span class="p">)</span> <span class="o">+</span> <span class="n">nse1</span> 20 | <span class="n">s2</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">sin</span><span class="p">(</span><span class="mi">2</span> <span class="o">*</span> <span class="n">np</span><span class="o">.</span><span class="n">pi</span> <span class="o">*</span> <span class="mi">10</span> <span class="o">*</span> <span class="n">t</span><span class="p">)</span> <span class="o">+</span> <span class="n">nse2</span> 21 | 22 | <span class="n">fig</span><span class="p">,</span> <span class="n">axs</span> <span class="o">=</span> <span class="n">plt</span><span class="o">.</span><span class="n">subplots</span><span class="p">(</span><span class="mi">2</span><span class="p">,</span> <span class="mi">1</span><span class="p">)</span> 23 | <span class="n">axs</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">.</span><span class="n">plot</span><span class="p">(</span><span class="n">t</span><span class="p">,</span> <span class="n">s1</span><span class="p">,</span> <span class="n">t</span><span class="p">,</span> <span class="n">s2</span><span class="p">)</span> 24 | <span class="n">axs</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">.</span><span class="n">set_xlim</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="mi">2</span><span class="p">)</span> 25 | <span class="n">axs</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">.</span><span class="n">set_xlabel</span><span class="p">(</span><span class="s1">'time'</span><span class="p">)</span> 26 | <span class="n">axs</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">.</span><span class="n">set_ylabel</span><span class="p">(</span><span class="s1">'s1 and s2'</span><span class="p">)</span> 27 | <span class="n">axs</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">.</span><span class="n">grid</span><span class="p">(</span><span class="kc">True</span><span class="p">)</span> 28 | 29 | <span class="n">cxy</span><span class="p">,</span> <span class="n">f</span> <span class="o">=</span> <span class="n">axs</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span><span class="o">.</span><span class="n">cohere</span><span class="p">(</span><span class="n">s1</span><span class="p">,</span> <span class="n">s2</span><span class="p">,</span> <span class="mi">256</span><span class="p">,</span> <span class="mf">1.</span> <span class="o">/</span> <span class="n">dt</span><span class="p">)</span> 30 | <span class="n">axs</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span><span class="o">.</span><span class="n">set_ylabel</span><span class="p">(</span><span class="s1">'coherence'</span><span class="p">)</span> 31 | 32 | <span class="n">fig</span><span class="o">.</span><span class="n">tight_layout</span><span class="p">()</span> 33 | <span class="n">plt</span><span class="o">.</span><span class="n">show</span><span class="p">()</span> 34 | </pre></div> 35 | </div> 36 | </div> 37 | <div class="cell_output docutils container"> 38 | <img alt="_images/e54e180c35e94dd0df219d42c2477d4c5763db55da00a21803bd9ce8f9859cb2.png" src="_images/e54e180c35e94dd0df219d42c2477d4c5763db55da00a21803bd9ce8f9859cb2.png"/> 39 | </div> 40 | </div> 41 | <p>With some follow up text to the solution</p> 42 | </section> 43 | </div> -------------------------------------------------------------------------------- /tests/test_hiddendirective.py: -------------------------------------------------------------------------------- 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 | "docname", 41 | [ 42 | "_enum_hidden", 43 | "_unenum_hidden", 44 | ], 45 | ) 46 | def test_hidden_exercise_doctree(app, docname, file_regression, get_sphinx_app_doctree): 47 | app.build() 48 | get_sphinx_app_doctree( 49 | app, 50 | docname, 51 | resolve=False, 52 | regress=True, 53 | ) 54 | 55 | 56 | @pytest.mark.sphinx("html", testroot="hiddendirectives") 57 | @pytest.mark.parametrize( 58 | "idir", 59 | [ 60 | "_linked_enum_hidden.html", 61 | "_linked_unenum_hidden.html", 62 | ], 63 | ) 64 | def test_hidden_solution(app, idir, file_regression): 65 | """Test exercise directive markup.""" 66 | app.build() 67 | path_to_directive = app.outdir / idir 68 | assert path_to_directive.exists() 69 | 70 | # get content markup 71 | soup = BeautifulSoup(path_to_directive.read_text(encoding="utf8"), "html.parser") 72 | solution = soup.select("div.solution") 73 | assert len(solution) == 0 74 | 75 | 76 | @pytest.mark.sphinx("html", testroot="hiddendirectives") 77 | @pytest.mark.parametrize( 78 | "docname", 79 | [ 80 | "_linked_enum_hidden", 81 | "_linked_unenum_hidden", 82 | ], 83 | ) 84 | def test_hidden_solution_doctree(app, docname, file_regression, get_sphinx_app_doctree): 85 | app.build() 86 | get_sphinx_app_doctree( 87 | app, 88 | docname, 89 | resolve=False, 90 | regress=True, 91 | ) 92 | -------------------------------------------------------------------------------- /tests/test_hiddendirective/_enum_hidden.html: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/executablebooks/sphinx-exercise/a098092db826e45b808d2ce0409f987382d0d038/tests/test_hiddendirective/_enum_hidden.html -------------------------------------------------------------------------------- /tests/test_hiddendirective/_enum_hidden.xml: -------------------------------------------------------------------------------- 1 | <document source="_enum_hidden.rst"> 2 | <section ids="enum-hidden" names="_enum_hidden"> 3 | <title> 4 | _enum_hidden 5 | -------------------------------------------------------------------------------- /tests/test_hiddendirective/_linked_enum_hidden.xml: -------------------------------------------------------------------------------- 1 | <document source="_linked_enum_hidden.rst"> 2 | <section ids="linked-enum-hidden" names="_linked_enum_hidden"> 3 | <title> 4 | _linked_enum_hidden 5 | -------------------------------------------------------------------------------- /tests/test_hiddendirective/_linked_unenum_hidden.xml: -------------------------------------------------------------------------------- 1 | <document source="_linked_unenum_hidden.rst"> 2 | <section ids="linked-unenum-hidden" names="_linked_unenum_hidden"> 3 | <title> 4 | _linked_unenum_hidden 5 | -------------------------------------------------------------------------------- /tests/test_hiddendirective/_unenum_hidden.html: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/executablebooks/sphinx-exercise/a098092db826e45b808d2ce0409f987382d0d038/tests/test_hiddendirective/_unenum_hidden.html -------------------------------------------------------------------------------- /tests/test_hiddendirective/_unenum_hidden.xml: -------------------------------------------------------------------------------- 1 | <document source="_unenum_hidden.rst"> 2 | <section ids="unenum-hidden" names="_unenum_hidden"> 3 | <title> 4 | _unenum_hidden 5 | -------------------------------------------------------------------------------- /tests/test_latex.py: -------------------------------------------------------------------------------- 1 | from TexSoup import TexSoup 2 | import pytest 3 | import sphinx 4 | 5 | SPHINX_VERSION = f".sphinx{sphinx.version_info[0]}" 6 | 7 | 8 | @pytest.mark.sphinx("latex", testroot="simplebook") 9 | def test_latex_build(app, file_regression): 10 | app.build() 11 | path_exer_directive = app.outdir / "sphinx-exercisetest.tex" 12 | assert path_exer_directive.exists() 13 | 14 | # get content markup 15 | file_content = TexSoup(path_exer_directive.read_text(encoding="utf8")) 16 | file_regression.check( 17 | str(file_content.document), extension=f"{SPHINX_VERSION}.tex", encoding="utf8" 18 | ) 19 | -------------------------------------------------------------------------------- /tests/test_latex/test_latex_build.sphinx4.tex: -------------------------------------------------------------------------------- 1 | \begin{document} 2 | 3 | \pagestyle{empty} 4 | \sphinxmaketitle 5 | \pagestyle{plain} 6 | \sphinxtableofcontents 7 | \pagestyle{normal} 8 | \phantomsection\label{\detokenize{index::doc}} 9 | 10 | 11 | \sphinxstepscope 12 | 13 | 14 | \chapter{Exercise} 15 | \label{\detokenize{exercise:exercise}}\label{\detokenize{exercise::doc}} 16 | \sphinxAtStartPar 17 | A collection of exercise directives 18 | \phantomsection \label{exercise:exercise-1} 19 | 20 | \begin{sphinxadmonition}{note}{Exercise 1 (\protect\(n!\protect\) factorial)} 21 | 22 | 23 | 24 | \sphinxAtStartPar 25 | Exercise 1 about \(n!\) factorial 26 | \end{sphinxadmonition} 27 | \phantomsection \label{exercise:exercise-2} 28 | \begin{sphinxadmonition}{note}{Exercise (\protect\(n!\protect\) factorial)} 29 | 30 | 31 | 32 | \sphinxAtStartPar 33 | Exercise 2 about \(n!\) factorial 34 | \end{sphinxadmonition} 35 | \phantomsection \label{exercise:exercise-3} 36 | 37 | \begin{sphinxadmonition}{note}{Exercise 2} 38 | 39 | 40 | 41 | \sphinxAtStartPar 42 | Exercise 3 Content with Number 43 | \end{sphinxadmonition} 44 | \phantomsection \label{exercise:exercise-4} 45 | \begin{sphinxadmonition}{note}{Exercise} 46 | 47 | 48 | 49 | \sphinxAtStartPar 50 | Exercise 4 Content with no Number 51 | \end{sphinxadmonition} 52 | 53 | 54 | \section{References} 55 | \label{\detokenize{exercise:references}} 56 | 57 | \subsection{Standard References} 58 | \label{\detokenize{exercise:standard-references}} 59 | \sphinxAtStartPar 60 | This is a link to \DUrole{xref,std,std-ref}{exercise\sphinxhyphen{}no\sphinxhyphen{}title} 61 | 62 | \sphinxAtStartPar 63 | This is a link to \hyperref[exercise:exercise-1]{Exercise 1} 64 | 65 | \sphinxAtStartPar 66 | This is a link to {\hyperref[\detokenize{exercise:exercise-2}]{\sphinxcrossref{\DUrole{std,std-ref}{Exercise}}}} 67 | 68 | \sphinxAtStartPar 69 | This ia another link with custom text \hyperref[exercise:exercise-3]{Exercise 3 Custom Text} 70 | 71 | \sphinxAtStartPar 72 | This ia another link with custom text {\hyperref[\detokenize{exercise:exercise-4}]{\sphinxcrossref{\DUrole{std,std-ref}{Exercise 4 Custom Text}}}} 73 | 74 | 75 | \subsection{Numbered References} 76 | \label{\detokenize{exercise:numbered-references}} 77 | \sphinxAtStartPar 78 | This is a numbered reference to \hyperref[exercise:exercise-1]{Exercise 1} 79 | 80 | \sphinxAtStartPar 81 | This is a numbered reference to \sphinxcode{\sphinxupquote{exercise\sphinxhyphen{}2}} and should be broken as exercise 2 is not an 82 | enumerated exercise node. 83 | 84 | \sphinxAtStartPar 85 | This is a numbered reference to \hyperref[exercise:exercise-3]{Exercise 2} 86 | 87 | \sphinxAtStartPar 88 | This is a numbered reference with custom text to \hyperref[exercise:exercise-3]{Custom Text with a Number 2} 89 | 90 | \sphinxAtStartPar 91 | This is a numbered reference to \sphinxcode{\sphinxupquote{exercise\sphinxhyphen{}4}} and should be broken as exercise 2 is not an 92 | enumerated exercise node. 93 | 94 | \sphinxAtStartPar 95 | This is a numbered reference with custom text to \sphinxcode{\sphinxupquote{Custom Text with a Number \{number\}}} and should be broken as exercise 2 is not an 96 | enumerated exercise node. 97 | 98 | \sphinxstepscope 99 | 100 | 101 | \chapter{Solution} 102 | \label{\detokenize{solution:solution}}\label{\detokenize{solution::doc}} 103 | \sphinxAtStartPar 104 | A collection of solution directives 105 | \phantomsection \label{solution:solution-1} 106 | 107 | \begin{sphinxadmonition}{note}{Solution to Exercise 1 (\protect\(n!\protect\) factorial)} 108 | 109 | 110 | 111 | \sphinxAtStartPar 112 | This is a solution to exercise 1 113 | \end{sphinxadmonition} 114 | \phantomsection \label{solution:solution-2} 115 | 116 | \begin{sphinxadmonition}{note}{Solution to Exercise (\protect\(n!\protect\) factorial)} 117 | 118 | 119 | 120 | \sphinxAtStartPar 121 | This is a solution to exercise 2 122 | \end{sphinxadmonition} 123 | \phantomsection \label{solution:solution-3} 124 | 125 | \begin{sphinxadmonition}{note}{Solution to Exercise 2} 126 | 127 | 128 | 129 | \sphinxAtStartPar 130 | This is a solution to exercise 3 131 | \end{sphinxadmonition} 132 | \phantomsection \label{solution:solution-4} 133 | 134 | \begin{sphinxadmonition}{note}{Solution to Exercise} 135 | 136 | 137 | 138 | \sphinxAtStartPar 139 | This is a solution to exercise 4 140 | \end{sphinxadmonition} 141 | 142 | 143 | \section{References} 144 | \label{\detokenize{solution:references}} 145 | 146 | \subsection{Standard References} 147 | \label{\detokenize{solution:standard-references}} 148 | \sphinxAtStartPar 149 | This is a link to {\hyperref[\detokenize{solution:solution-1}]{\sphinxcrossref{\DUrole{std,std-ref}{Solution to Exercise 1 (n! factorial)}}}} 150 | 151 | \sphinxAtStartPar 152 | This is a link to {\hyperref[\detokenize{solution:solution-2}]{\sphinxcrossref{\DUrole{std,std-ref}{Solution to Exercise (n! factorial)}}}} 153 | 154 | \sphinxAtStartPar 155 | This is a link to {\hyperref[\detokenize{solution:solution-3}]{\sphinxcrossref{\DUrole{std,std-ref}{Solution to Exercise 2}}}} 156 | 157 | \sphinxAtStartPar 158 | This is a link to {\hyperref[\detokenize{solution:solution-4}]{\sphinxcrossref{\DUrole{std,std-ref}{Solution to Exercise}}}} 159 | 160 | \sphinxAtStartPar 161 | This ia another link to a different {\hyperref[\detokenize{solution:solution-1}]{\sphinxcrossref{\DUrole{std,std-ref}{Solution to Exercise 1 (n! factorial)}}}} 162 | 163 | 164 | \subsection{Numbered References} 165 | \label{\detokenize{solution:numbered-references}} 166 | \sphinxAtStartPar 167 | Solution nodes are not enumerated nodes so these won’t work 168 | 169 | \sphinxAtStartPar 170 | This is a link to \sphinxcode{\sphinxupquote{solution\sphinxhyphen{}1}} 171 | 172 | 173 | 174 | \renewcommand{\indexname}{Index} 175 | \printindex 176 | \end{document} 177 | -------------------------------------------------------------------------------- /tests/test_latex/test_latex_build.sphinx5.tex: -------------------------------------------------------------------------------- 1 | \begin{document} 2 | 3 | \ifdefined\shorthandoff 4 | \ifnum\catcode`\=\string=\active\shorthandoff{=}\fi 5 | \ifnum\catcode`\"=\active\shorthandoff{"}\fi 6 | \fi 7 | 8 | \pagestyle{empty} 9 | \sphinxmaketitle 10 | \pagestyle{plain} 11 | \sphinxtableofcontents 12 | \pagestyle{normal} 13 | \phantomsection\label{\detokenize{index::doc}} 14 | 15 | 16 | \sphinxstepscope 17 | 18 | 19 | \chapter{Exercise} 20 | \label{\detokenize{exercise:exercise}}\label{\detokenize{exercise::doc}} 21 | \sphinxAtStartPar 22 | A collection of exercise directives 23 | \phantomsection \label{exercise:exercise-1} 24 | 25 | \begin{sphinxadmonition}{note}{Exercise 1 (\protect\(n!\protect\) factorial)} 26 | 27 | 28 | 29 | \sphinxAtStartPar 30 | Exercise 1 about \(n!\) factorial 31 | \end{sphinxadmonition} 32 | \phantomsection \label{exercise:exercise-2} 33 | \begin{sphinxadmonition}{note}{Exercise (\protect\(n!\protect\) factorial)} 34 | 35 | 36 | 37 | \sphinxAtStartPar 38 | Exercise 2 about \(n!\) factorial 39 | \end{sphinxadmonition} 40 | \phantomsection \label{exercise:exercise-3} 41 | 42 | \begin{sphinxadmonition}{note}{Exercise 2} 43 | 44 | 45 | 46 | \sphinxAtStartPar 47 | Exercise 3 Content with Number 48 | \end{sphinxadmonition} 49 | \phantomsection \label{exercise:exercise-4} 50 | \begin{sphinxadmonition}{note}{Exercise} 51 | 52 | 53 | 54 | \sphinxAtStartPar 55 | Exercise 4 Content with no Number 56 | \end{sphinxadmonition} 57 | 58 | 59 | \section{References} 60 | \label{\detokenize{exercise:references}} 61 | 62 | \subsection{Standard References} 63 | \label{\detokenize{exercise:standard-references}} 64 | \sphinxAtStartPar 65 | This is a link to \DUrole{xref,std,std-ref}{exercise\sphinxhyphen{}no\sphinxhyphen{}title} 66 | 67 | \sphinxAtStartPar 68 | This is a link to \hyperref[exercise:exercise-1]{Exercise 1} 69 | 70 | \sphinxAtStartPar 71 | This is a link to {\hyperref[\detokenize{exercise:exercise-2}]{\sphinxcrossref{\DUrole{std,std-ref}{Exercise}}}} 72 | 73 | \sphinxAtStartPar 74 | This ia another link with custom text \hyperref[exercise:exercise-3]{Exercise 3 Custom Text} 75 | 76 | \sphinxAtStartPar 77 | This ia another link with custom text {\hyperref[\detokenize{exercise:exercise-4}]{\sphinxcrossref{\DUrole{std,std-ref}{Exercise 4 Custom Text}}}} 78 | 79 | 80 | \subsection{Numbered References} 81 | \label{\detokenize{exercise:numbered-references}} 82 | \sphinxAtStartPar 83 | This is a numbered reference to \hyperref[exercise:exercise-1]{Exercise 1} 84 | 85 | \sphinxAtStartPar 86 | This is a numbered reference to \sphinxcode{\sphinxupquote{exercise\sphinxhyphen{}2}} and should be broken as exercise 2 is not an 87 | enumerated exercise node. 88 | 89 | \sphinxAtStartPar 90 | This is a numbered reference to \hyperref[exercise:exercise-3]{Exercise 2} 91 | 92 | \sphinxAtStartPar 93 | This is a numbered reference with custom text to \hyperref[exercise:exercise-3]{Custom Text with a Number 2} 94 | 95 | \sphinxAtStartPar 96 | This is a numbered reference to \sphinxcode{\sphinxupquote{exercise\sphinxhyphen{}4}} and should be broken as exercise 2 is not an 97 | enumerated exercise node. 98 | 99 | \sphinxAtStartPar 100 | This is a numbered reference with custom text to \sphinxcode{\sphinxupquote{Custom Text with a Number \{number\}}} and should be broken as exercise 2 is not an 101 | enumerated exercise node. 102 | 103 | \sphinxstepscope 104 | 105 | 106 | \chapter{Solution} 107 | \label{\detokenize{solution:solution}}\label{\detokenize{solution::doc}} 108 | \sphinxAtStartPar 109 | A collection of solution directives 110 | \phantomsection \label{solution:solution-1} 111 | 112 | \begin{sphinxadmonition}{note}{Solution to Exercise 1 (\protect\(n!\protect\) factorial)} 113 | 114 | 115 | 116 | \sphinxAtStartPar 117 | This is a solution to exercise 1 118 | \end{sphinxadmonition} 119 | \phantomsection \label{solution:solution-2} 120 | 121 | \begin{sphinxadmonition}{note}{Solution to Exercise (\protect\(n!\protect\) factorial)} 122 | 123 | 124 | 125 | \sphinxAtStartPar 126 | This is a solution to exercise 2 127 | \end{sphinxadmonition} 128 | \phantomsection \label{solution:solution-3} 129 | 130 | \begin{sphinxadmonition}{note}{Solution to Exercise 2} 131 | 132 | 133 | 134 | \sphinxAtStartPar 135 | This is a solution to exercise 3 136 | \end{sphinxadmonition} 137 | \phantomsection \label{solution:solution-4} 138 | 139 | \begin{sphinxadmonition}{note}{Solution to Exercise} 140 | 141 | 142 | 143 | \sphinxAtStartPar 144 | This is a solution to exercise 4 145 | \end{sphinxadmonition} 146 | 147 | 148 | \section{References} 149 | \label{\detokenize{solution:references}} 150 | 151 | \subsection{Standard References} 152 | \label{\detokenize{solution:standard-references}} 153 | \sphinxAtStartPar 154 | This is a link to {\hyperref[\detokenize{solution:solution-1}]{\sphinxcrossref{\DUrole{std,std-ref}{Solution to Exercise 1 (n! factorial)}}}} 155 | 156 | \sphinxAtStartPar 157 | This is a link to {\hyperref[\detokenize{solution:solution-2}]{\sphinxcrossref{\DUrole{std,std-ref}{Solution to Exercise (n! factorial)}}}} 158 | 159 | \sphinxAtStartPar 160 | This is a link to {\hyperref[\detokenize{solution:solution-3}]{\sphinxcrossref{\DUrole{std,std-ref}{Solution to Exercise 2}}}} 161 | 162 | \sphinxAtStartPar 163 | This is a link to {\hyperref[\detokenize{solution:solution-4}]{\sphinxcrossref{\DUrole{std,std-ref}{Solution to Exercise}}}} 164 | 165 | \sphinxAtStartPar 166 | This ia another link to a different {\hyperref[\detokenize{solution:solution-1}]{\sphinxcrossref{\DUrole{std,std-ref}{Solution to Exercise 1 (n! factorial)}}}} 167 | 168 | 169 | \subsection{Numbered References} 170 | \label{\detokenize{solution:numbered-references}} 171 | \sphinxAtStartPar 172 | Solution nodes are not enumerated nodes so these won’t work 173 | 174 | \sphinxAtStartPar 175 | This is a link to \sphinxcode{\sphinxupquote{solution\sphinxhyphen{}1}} 176 | 177 | 178 | 179 | \renewcommand{\indexname}{Index} 180 | \printindex 181 | \end{document} 182 | -------------------------------------------------------------------------------- /tests/test_latex/test_latex_build.sphinx7.tex: -------------------------------------------------------------------------------- 1 | \begin{document} 2 | 3 | \ifdefined\shorthandoff 4 | \ifnum\catcode`\=\string=\active\shorthandoff{=}\fi 5 | \ifnum\catcode`\"=\active\shorthandoff{"}\fi 6 | \fi 7 | 8 | \pagestyle{empty} 9 | \sphinxmaketitle 10 | \pagestyle{plain} 11 | \sphinxtableofcontents 12 | \pagestyle{normal} 13 | \phantomsection\label{\detokenize{index::doc}} 14 | 15 | 16 | \sphinxstepscope 17 | 18 | 19 | \chapter{Exercise} 20 | \label{\detokenize{exercise:exercise}}\label{\detokenize{exercise::doc}} 21 | \sphinxAtStartPar 22 | A collection of exercise directives 23 | \phantomsection \label{exercise:exercise-1} 24 | 25 | \begin{sphinxadmonition}{note}{Exercise 1 (\protect\(n!\protect\) factorial)} 26 | 27 | 28 | 29 | \sphinxAtStartPar 30 | Exercise 1 about \(n!\) factorial 31 | \end{sphinxadmonition} 32 | \phantomsection \label{exercise:exercise-2} 33 | \begin{sphinxadmonition}{note}{Exercise (\protect\(n!\protect\) factorial)} 34 | 35 | 36 | 37 | \sphinxAtStartPar 38 | Exercise 2 about \(n!\) factorial 39 | \end{sphinxadmonition} 40 | \phantomsection \label{exercise:exercise-3} 41 | 42 | \begin{sphinxadmonition}{note}{Exercise 2} 43 | 44 | 45 | 46 | \sphinxAtStartPar 47 | Exercise 3 Content with Number 48 | \end{sphinxadmonition} 49 | \phantomsection \label{exercise:exercise-4} 50 | \begin{sphinxadmonition}{note}{Exercise} 51 | 52 | 53 | 54 | \sphinxAtStartPar 55 | Exercise 4 Content with no Number 56 | \end{sphinxadmonition} 57 | 58 | 59 | \section{References} 60 | \label{\detokenize{exercise:references}} 61 | 62 | \subsection{Standard References} 63 | \label{\detokenize{exercise:standard-references}} 64 | \sphinxAtStartPar 65 | This is a link to \DUrole{xref,std,std-ref}{exercise\sphinxhyphen{}no\sphinxhyphen{}title} 66 | 67 | \sphinxAtStartPar 68 | This is a link to \hyperref[exercise:exercise-1]{Exercise 1} 69 | 70 | \sphinxAtStartPar 71 | This is a link to {\hyperref[\detokenize{exercise:exercise-2}]{\sphinxcrossref{\DUrole{std,std-ref}{Exercise}}}} 72 | 73 | \sphinxAtStartPar 74 | This ia another link with custom text \hyperref[exercise:exercise-3]{Exercise 3 Custom Text} 75 | 76 | \sphinxAtStartPar 77 | This ia another link with custom text {\hyperref[\detokenize{exercise:exercise-4}]{\sphinxcrossref{\DUrole{std,std-ref}{Exercise 4 Custom Text}}}} 78 | 79 | 80 | \subsection{Numbered References} 81 | \label{\detokenize{exercise:numbered-references}} 82 | \sphinxAtStartPar 83 | This is a numbered reference to \hyperref[exercise:exercise-1]{Exercise 1} 84 | 85 | \sphinxAtStartPar 86 | This is a numbered reference to \sphinxcode{\sphinxupquote{exercise\sphinxhyphen{}2}} and should be broken as exercise 2 is not an 87 | enumerated exercise node. 88 | 89 | \sphinxAtStartPar 90 | This is a numbered reference to \hyperref[exercise:exercise-3]{Exercise 2} 91 | 92 | \sphinxAtStartPar 93 | This is a numbered reference with custom text to \hyperref[exercise:exercise-3]{Custom Text with a Number 2} 94 | 95 | \sphinxAtStartPar 96 | This is a numbered reference to \sphinxcode{\sphinxupquote{exercise\sphinxhyphen{}4}} and should be broken as exercise 2 is not an 97 | enumerated exercise node. 98 | 99 | \sphinxAtStartPar 100 | This is a numbered reference with custom text to \sphinxcode{\sphinxupquote{Custom Text with a Number \{number\}}} and should be broken as exercise 2 is not an 101 | enumerated exercise node. 102 | 103 | \sphinxstepscope 104 | 105 | 106 | \chapter{Solution} 107 | \label{\detokenize{solution:solution}}\label{\detokenize{solution::doc}} 108 | \sphinxAtStartPar 109 | A collection of solution directives 110 | \phantomsection \label{solution:solution-1} 111 | 112 | \begin{sphinxadmonition}{note}{Solution to Exercise 1 (\protect\(n!\protect\) factorial)} 113 | 114 | 115 | 116 | \sphinxAtStartPar 117 | This is a solution to exercise 1 118 | \end{sphinxadmonition} 119 | \phantomsection \label{solution:solution-2} 120 | 121 | \begin{sphinxadmonition}{note}{Solution to Exercise (\protect\(n!\protect\) factorial)} 122 | 123 | 124 | 125 | \sphinxAtStartPar 126 | This is a solution to exercise 2 127 | \end{sphinxadmonition} 128 | \phantomsection \label{solution:solution-3} 129 | 130 | \begin{sphinxadmonition}{note}{Solution to Exercise 2} 131 | 132 | 133 | 134 | \sphinxAtStartPar 135 | This is a solution to exercise 3 136 | \end{sphinxadmonition} 137 | \phantomsection \label{solution:solution-4} 138 | 139 | \begin{sphinxadmonition}{note}{Solution to Exercise} 140 | 141 | 142 | 143 | \sphinxAtStartPar 144 | This is a solution to exercise 4 145 | \end{sphinxadmonition} 146 | 147 | 148 | \section{References} 149 | \label{\detokenize{solution:references}} 150 | 151 | \subsection{Standard References} 152 | \label{\detokenize{solution:standard-references}} 153 | \sphinxAtStartPar 154 | This is a link to {\hyperref[\detokenize{solution:solution-1}]{\sphinxcrossref{\DUrole{std,std-ref}{Solution to Exercise 1 (n! factorial)}}}} 155 | 156 | \sphinxAtStartPar 157 | This is a link to {\hyperref[\detokenize{solution:solution-2}]{\sphinxcrossref{\DUrole{std,std-ref}{Solution to Exercise (n! factorial)}}}} 158 | 159 | \sphinxAtStartPar 160 | This is a link to {\hyperref[\detokenize{solution:solution-3}]{\sphinxcrossref{\DUrole{std,std-ref}{Solution to Exercise 2}}}} 161 | 162 | \sphinxAtStartPar 163 | This is a link to {\hyperref[\detokenize{solution:solution-4}]{\sphinxcrossref{\DUrole{std,std-ref}{Solution to Exercise}}}} 164 | 165 | \sphinxAtStartPar 166 | This ia another link to a different {\hyperref[\detokenize{solution:solution-1}]{\sphinxcrossref{\DUrole{std,std-ref}{Solution to Exercise 1 (n! factorial)}}}} 167 | 168 | 169 | \subsection{Numbered References} 170 | \label{\detokenize{solution:numbered-references}} 171 | \sphinxAtStartPar 172 | Solution nodes are not enumerated nodes so these won’t work 173 | 174 | \sphinxAtStartPar 175 | This is a link to \sphinxcode{\sphinxupquote{solution\sphinxhyphen{}1}} 176 | 177 | 178 | 179 | \renewcommand{\indexname}{Index} 180 | \printindex 181 | \end{document} 182 | -------------------------------------------------------------------------------- /tests/test_solution.py: -------------------------------------------------------------------------------- 1 | from bs4 import BeautifulSoup 2 | import pytest 3 | 4 | 5 | @pytest.mark.sphinx("html", testroot="mybook") 6 | @pytest.mark.parametrize( 7 | "idir", 8 | [ 9 | "_linked_enum.html", 10 | "_linked_enum_class.html", 11 | "_linked_unenum_mathtitle.html", 12 | "_linked_unenum_mathtitle2.html", 13 | "_linked_unenum_notitle.html", 14 | "_linked_unenum_title.html", 15 | "_linked_wrong_targetlabel.html", 16 | ], 17 | ) 18 | def test_solution(app, idir, file_regression): 19 | """Test solution directive markup.""" 20 | app.build() 21 | path_solution_directive = app.outdir / "solution" / idir 22 | assert path_solution_directive.exists() 23 | 24 | # get content markup 25 | soup = BeautifulSoup( 26 | path_solution_directive.read_text(encoding="utf8"), "html.parser" 27 | ) 28 | 29 | sol = soup.select("div.solution")[0] 30 | file_regression.check(str(sol), basename=idir.split(".")[0], extension=".html") 31 | 32 | 33 | @pytest.mark.sphinx("html", testroot="mybook") 34 | @pytest.mark.parametrize( 35 | "docname", 36 | [ 37 | "_linked_duplicate_label", 38 | "_linked_enum", 39 | "_linked_enum_class", 40 | "_linked_missing_arg", 41 | "_linked_unenum_mathtitle", 42 | "_linked_unenum_mathtitle2", 43 | "_linked_unenum_notitle", 44 | "_linked_unenum_title", 45 | "_linked_wrong_targetlabel", 46 | ], 47 | ) 48 | def test_solution_doctree(app, docname, file_regression, get_sphinx_app_doctree): 49 | app.build() 50 | docname = "solution" + "/" + docname 51 | get_sphinx_app_doctree( 52 | app, 53 | docname, 54 | resolve=False, 55 | regress=True, 56 | flatten_outdir=True, # noqa: E501 flatten files "solution/<file> -> <file>.xml" for convenience 57 | ) 58 | -------------------------------------------------------------------------------- /tests/test_solution/_linked_duplicate_label.xml: -------------------------------------------------------------------------------- 1 | <document source="_linked_duplicate_label.rst"> 2 | <section ids="linked-duplicate-label" names="_linked_duplicate_label"> 3 | <title> 4 | _linked_duplicate_label 5 | <solution_node classes="solution" docname="solution/_linked_duplicate_label" hidden="False" ids="sol-duplicate-label" label="sol-duplicate-label" names="sol-duplicate-label" serial_number="0" target_label="ex-nonumber-notitle" title="Solution to" type="solution"> 6 | <solution_title> 7 | Solution to 8 | <section ids="solution-content"> 9 | <paragraph> 10 | Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. 11 | -------------------------------------------------------------------------------- /tests/test_solution/_linked_enum.html: -------------------------------------------------------------------------------- 1 | <div class="solution admonition" id="sol-number"> 2 | <p class="admonition-title">Solution to<a class="reference internal" href="#ex-number"> Exercise 6 (This is a title)</a></p> 3 | <section id="solution-content"> 4 | <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</p> 5 | <div class="math notranslate nohighlight"> 6 | \[P_t(x, y) = \mathbb 1\{x = y\} + t Q(x, y) + o(t)\]</div> 7 | <p>Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p> 8 | <div class="math notranslate nohighlight" id="equation-ex-math"> 9 | <span class="eqno">(1)<a class="headerlink" href="#equation-ex-math" title="Permalink to this equation">¶</a></span>\[P_t(x, y) = \mathbb 1\{x = y\} + t Q(x, y) + o(t)\]</div> 10 | </section> 11 | </div> -------------------------------------------------------------------------------- /tests/test_solution/_linked_enum.xml: -------------------------------------------------------------------------------- 1 | <document source="_linked_enum.rst"> 2 | <section ids="linked-enum" names="_linked_enum"> 3 | <title> 4 | _linked_enum 5 | <exercise_enumerable_node classes="exercise" docname="solution/_linked_enum" hidden="False" ids="ex-number" label="ex-number" names="ex-number" serial_number="0" title="Exercise" type="exercise"> 6 | <exercise_title> 7 | Exercise 8 | <exercise_subtitle> 9 | This is a title 10 | <section ids="exercise-content"> 11 | <paragraph> 12 | Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. 13 | <paragraph> 14 | 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. 15 | <paragraph> 16 | Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. 17 | <solution_node classes="solution" docname="solution/_linked_enum" hidden="False" ids="sol-number" label="sol-number" names="sol-number" serial_number="1" target_label="ex-number" title="Solution to" type="solution"> 18 | <solution_title> 19 | Solution to 20 | <section ids="solution-content"> 21 | <paragraph> 22 | Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. 23 | <math_block docname="solution/_linked_enum" label="True" nowrap="False" number="True" xml:space="preserve"> 24 | P_t(x, y) = \mathbb 1\{x = y\} + t Q(x, y) + o(t) 25 | <paragraph> 26 | Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. 27 | <target refid="equation-ex-math"> 28 | <math_block docname="solution/_linked_enum" ids="equation-ex-math" label="ex-math" nowrap="False" number="1" xml:space="preserve"> 29 | P_t(x, y) = \mathbb 1\{x = y\} + t Q(x, y) + o(t) 30 | -------------------------------------------------------------------------------- /tests/test_solution/_linked_enum_class.html: -------------------------------------------------------------------------------- 1 | <div class="solution test-solution admonition" id="solution-label"> 2 | <p class="admonition-title">Solution to<a class="reference internal" href="_linked_enum.html#ex-number"> Exercise 6 (This is a title)</a></p> 3 | <section id="solution-content"> 4 | <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</p> 5 | </section> 6 | </div> -------------------------------------------------------------------------------- /tests/test_solution/_linked_enum_class.xml: -------------------------------------------------------------------------------- 1 | <document source="_linked_enum_class.rst"> 2 | <section ids="linked-enum-class" names="_linked_enum_class"> 3 | <title> 4 | _linked_enum_class 5 | <solution_node classes="solution test-solution" docname="solution/_linked_enum_class" hidden="False" ids="solution-label" label="solution-label" names="solution-label" serial_number="0" target_label="ex-number" title="Solution to" type="solution"> 6 | <solution_title> 7 | Solution to 8 | <section ids="solution-content"> 9 | <paragraph> 10 | Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. 11 | -------------------------------------------------------------------------------- /tests/test_solution/_linked_missing_arg.xml: -------------------------------------------------------------------------------- 1 | <document source="_linked_missing_arg.rst"> 2 | <section ids="linked-missing-arg" names="_linked_missing_arg"> 3 | <title> 4 | _linked_missing_arg 5 | -------------------------------------------------------------------------------- /tests/test_solution/_linked_unenum_mathtitle.html: -------------------------------------------------------------------------------- 1 | <div class="solution admonition" id="sol-nonumber-title-math"> 2 | <p class="admonition-title">Solution to<a class="reference internal" href="#ex-nonumber-title-math"> Exercise (This is a title <span class="math notranslate nohighlight">\(\mathbb{R}\)</span>)</a></p> 3 | <section id="solution-content"> 4 | <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</p> 5 | </section> 6 | </div> -------------------------------------------------------------------------------- /tests/test_solution/_linked_unenum_mathtitle.xml: -------------------------------------------------------------------------------- 1 | <document source="_linked_unenum_mathtitle.rst"> 2 | <section ids="linked-unenum-mathtitle" names="_linked_unenum_mathtitle"> 3 | <title> 4 | _linked_unenum_mathtitle 5 | <exercise_node classes="exercise" docname="solution/_linked_unenum_mathtitle" hidden="False" ids="ex-nonumber-title-math" label="ex-nonumber-title-math" names="ex-nonumber-title-math" serial_number="0" title="Exercise" type="exercise"> 6 | <exercise_title> 7 | Exercise 8 | <exercise_subtitle> 9 | This is a title 10 | <math> 11 | \mathbb{R} 12 | <section ids="exercise-content"> 13 | <paragraph> 14 | Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. 15 | <paragraph> 16 | 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. 17 | <paragraph> 18 | Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. 19 | <solution_node classes="solution" docname="solution/_linked_unenum_mathtitle" hidden="False" ids="sol-nonumber-title-math" label="sol-nonumber-title-math" names="sol-nonumber-title-math" serial_number="1" target_label="ex-nonumber-title-math" title="Solution to" type="solution"> 20 | <solution_title> 21 | Solution to 22 | <section ids="solution-content"> 23 | <paragraph> 24 | Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. 25 | -------------------------------------------------------------------------------- /tests/test_solution/_linked_unenum_mathtitle2.html: -------------------------------------------------------------------------------- 1 | <div class="solution admonition" id="sol-nonumber-title-math2"> 2 | <p class="admonition-title">Solution to<a class="reference internal" href="#ex-nonumber-title-math2"> Exercise (This is a title <span class="math notranslate nohighlight">\(P_t(x, y) = \mathbb 1\{x = y\} + t Q(x, y) + o(t)\)</span>)</a></p> 3 | <section id="solution-content"> 4 | <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</p> 5 | </section> 6 | </div> -------------------------------------------------------------------------------- /tests/test_solution/_linked_unenum_mathtitle2.xml: -------------------------------------------------------------------------------- 1 | <document source="_linked_unenum_mathtitle2.rst"> 2 | <section ids="linked-unenum-mathtitle2" names="_linked_unenum_mathtitle2"> 3 | <title> 4 | _linked_unenum_mathtitle2 5 | <exercise_node classes="exercise" docname="solution/_linked_unenum_mathtitle2" hidden="False" ids="ex-nonumber-title-math2" label="ex-nonumber-title-math2" names="ex-nonumber-title-math2" serial_number="0" title="Exercise" type="exercise"> 6 | <exercise_title> 7 | Exercise 8 | <exercise_subtitle> 9 | This is a title 10 | <math> 11 | P_t(x, y) = \mathbb 1\{x = y\} + t Q(x, y) + o(t) 12 | <section ids="exercise-content"> 13 | <paragraph> 14 | Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. 15 | <paragraph> 16 | 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. 17 | <paragraph> 18 | Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. 19 | <solution_node classes="solution" docname="solution/_linked_unenum_mathtitle2" hidden="False" ids="sol-nonumber-title-math2" label="sol-nonumber-title-math2" names="sol-nonumber-title-math2" serial_number="1" target_label="ex-nonumber-title-math2" title="Solution to" type="solution"> 20 | <solution_title> 21 | Solution to 22 | <section ids="solution-content"> 23 | <paragraph> 24 | Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. 25 | -------------------------------------------------------------------------------- /tests/test_solution/_linked_unenum_notitle.html: -------------------------------------------------------------------------------- 1 | <div class="solution admonition" id="sol-nonumber-notitle"> 2 | <p class="admonition-title">Solution to<a class="reference internal" href="#ex-nonumber-notitle"> Exercise</a></p> 3 | <section id="solution-content"> 4 | <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</p> 5 | </section> 6 | </div> -------------------------------------------------------------------------------- /tests/test_solution/_linked_unenum_notitle.xml: -------------------------------------------------------------------------------- 1 | <document source="_linked_unenum_notitle.rst"> 2 | <section ids="linked-unenum-notitle" names="_linked_unenum_notitle"> 3 | <title> 4 | _linked_unenum_notitle 5 | <exercise_node classes="exercise" docname="solution/_linked_unenum_notitle" hidden="False" ids="ex-nonumber-notitle" label="ex-nonumber-notitle" names="ex-nonumber-notitle" serial_number="0" title="Exercise" type="exercise"> 6 | <exercise_title> 7 | Exercise 8 | <section ids="exercise-content"> 9 | <paragraph> 10 | Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. 11 | <paragraph> 12 | 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. 13 | <paragraph> 14 | Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. 15 | <solution_node classes="solution" docname="solution/_linked_unenum_notitle" hidden="False" ids="sol-nonumber-notitle" label="sol-nonumber-notitle" names="sol-nonumber-notitle" serial_number="1" target_label="ex-nonumber-notitle" title="Solution to" type="solution"> 16 | <solution_title> 17 | Solution to 18 | <section ids="solution-content"> 19 | <paragraph> 20 | Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. 21 | -------------------------------------------------------------------------------- /tests/test_solution/_linked_unenum_title.html: -------------------------------------------------------------------------------- 1 | <div class="solution admonition" id="sol-nonumber-title"> 2 | <p class="admonition-title">Solution to<a class="reference internal" href="#ex-nonumber-title"> Exercise (This is a title)</a></p> 3 | <section id="solution-content"> 4 | <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</p> 5 | </section> 6 | </div> -------------------------------------------------------------------------------- /tests/test_solution/_linked_unenum_title.xml: -------------------------------------------------------------------------------- 1 | <document source="_linked_unenum_title.rst"> 2 | <section ids="linked-unenum-title" names="_linked_unenum_title"> 3 | <title> 4 | _linked_unenum_title 5 | <exercise_node classes="exercise" docname="solution/_linked_unenum_title" hidden="False" ids="ex-nonumber-title" label="ex-nonumber-title" names="ex-nonumber-title" serial_number="0" title="Exercise" type="exercise"> 6 | <exercise_title> 7 | Exercise 8 | <exercise_subtitle> 9 | This is a title 10 | <section ids="exercise-content"> 11 | <paragraph> 12 | Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. 13 | <paragraph> 14 | 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. 15 | <paragraph> 16 | Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. 17 | <solution_node classes="solution" docname="solution/_linked_unenum_title" hidden="False" ids="sol-nonumber-title" label="sol-nonumber-title" names="sol-nonumber-title" serial_number="1" target_label="ex-nonumber-title" title="Solution to" type="solution"> 18 | <solution_title> 19 | Solution to 20 | <section ids="solution-content"> 21 | <paragraph> 22 | Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. 23 | -------------------------------------------------------------------------------- /tests/test_solution/_linked_wrong_targetlabel.html: -------------------------------------------------------------------------------- 1 | <div class="solution admonition" id="solution/_linked_wrong_targetlabel-solution-0"> 2 | <p class="admonition-title">Solution to</p> 3 | <section id="solution-content"> 4 | <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</p> 5 | </section> 6 | </div> -------------------------------------------------------------------------------- /tests/test_solution/_linked_wrong_targetlabel.xml: -------------------------------------------------------------------------------- 1 | <document source="_linked_wrong_targetlabel.rst"> 2 | <section ids="linked-wrong-targetlabel" names="_linked_wrong_targetlabel"> 3 | <title> 4 | _linked_wrong_targetlabel 5 | <solution_node classes="solution" docname="solution/_linked_wrong_targetlabel" hidden="False" ids="solution/_linked_wrong_targetlabel-solution-0" label="solution/_linked_wrong_targetlabel-solution-0" names="solution/_linked_wrong_targetlabel-solution-0" serial_number="0" target_label="wrong-ex-label" title="Solution to" type="solution"> 6 | <solution_title> 7 | Solution to 8 | <section ids="solution-content"> 9 | <paragraph> 10 | Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. 11 | -------------------------------------------------------------------------------- /tests/test_solution_references.py: -------------------------------------------------------------------------------- 1 | from bs4 import BeautifulSoup 2 | import pytest 3 | 4 | 5 | @pytest.mark.sphinx("html", testroot="mybook") 6 | @pytest.mark.parametrize( 7 | "idir", 8 | [ 9 | "_linked_ref_enum.html", 10 | "_linked_ref_unenum_mathtitle.html", 11 | "_linked_ref_unenum_mathtitle2.html", 12 | "_linked_ref_unenum_notitle.html", 13 | "_linked_ref_unenum_title.html", 14 | ], 15 | ) 16 | def test_reference(app, idir, file_regression): 17 | """Test solution ref role markup.""" 18 | app.builder.build_all() 19 | path_solution_directive = app.outdir / "solution" / idir 20 | assert path_solution_directive.exists() 21 | # get content markup 22 | soup = BeautifulSoup( 23 | path_solution_directive.read_text(encoding="utf8"), "html.parser" 24 | ) 25 | 26 | excs = "" 27 | all_refs = soup.select("p") 28 | for ref in all_refs: 29 | excs += f"{ref}\n" 30 | 31 | file_regression.check( 32 | str(excs[:-1]), basename=idir.split(".")[0], extension=".html" 33 | ) 34 | 35 | 36 | @pytest.mark.sphinx("html", testroot="mybook") 37 | @pytest.mark.parametrize( 38 | "docname", 39 | [ 40 | "_linked_ref_enum", 41 | "_linked_ref_unenum_mathtitle", 42 | "_linked_ref_unenum_mathtitle2", 43 | "_linked_ref_unenum_notitle", 44 | "_linked_ref_unenum_title", 45 | "_linked_ref_wronglabel", 46 | ], 47 | ) 48 | def test_solution_doctree(app, docname, file_regression, get_sphinx_app_doctree): 49 | app.build() 50 | docname = "solution" + "/" + docname 51 | get_sphinx_app_doctree( 52 | app, 53 | docname, 54 | resolve=False, 55 | regress=True, 56 | flatten_outdir=True, # noqa: E501 flatten files "solution/<file> -> <file>.xml" for convenience 57 | ) 58 | -------------------------------------------------------------------------------- /tests/test_solution_references/_linked_ref_enum.html: -------------------------------------------------------------------------------- 1 | <p>referencing: <a class="reference internal" href="_linked_enum.html#sol-number"><span class="std std-ref">Solution to</span></a>.</p> 2 | <p>referencing: <a class="reference internal" href="_linked_enum.html#sol-number"><span class="std std-ref">simple solution with number</span></a>.</p> -------------------------------------------------------------------------------- /tests/test_solution_references/_linked_ref_enum.xml: -------------------------------------------------------------------------------- 1 | <document source="_linked_ref_enum.rst"> 2 | <section ids="linked-ref-enum" names="_linked_ref_enum"> 3 | <title> 4 | _linked_ref_enum 5 | <paragraph> 6 | referencing: 7 | <pending_xref refdoc="solution/_linked_ref_enum" refdomain="std" refexplicit="False" reftarget="sol-number" reftype="ref" refwarn="True"> 8 | <inline classes="xref std std-ref"> 9 | sol-number 10 | . 11 | <paragraph> 12 | referencing: 13 | <pending_xref refdoc="solution/_linked_ref_enum" refdomain="std" refexplicit="True" reftarget="sol-number" reftype="ref" refwarn="True"> 14 | <inline classes="xref std std-ref"> 15 | simple solution with number 16 | . 17 | -------------------------------------------------------------------------------- /tests/test_solution_references/_linked_ref_unenum_mathtitle.html: -------------------------------------------------------------------------------- 1 | <p>referencing: <a class="reference internal" href="_linked_unenum_mathtitle.html#sol-nonumber-title-math"><span class="std std-ref">Solution to</span></a>.</p> 2 | <p>referencing: <a class="reference internal" href="_linked_unenum_mathtitle.html#sol-nonumber-title-math"><span class="std std-ref">exercise with nonumber but with inline math title</span></a>.</p> -------------------------------------------------------------------------------- /tests/test_solution_references/_linked_ref_unenum_mathtitle.xml: -------------------------------------------------------------------------------- 1 | <document source="_linked_ref_unenum_mathtitle.rst"> 2 | <section ids="linked-ref-unenum-mathtitle" names="_linked_ref_unenum_mathtitle"> 3 | <title> 4 | _linked_ref_unenum_mathtitle 5 | <paragraph> 6 | referencing: 7 | <pending_xref refdoc="solution/_linked_ref_unenum_mathtitle" refdomain="std" refexplicit="False" reftarget="sol-nonumber-title-math" reftype="ref" refwarn="True"> 8 | <inline classes="xref std std-ref"> 9 | sol-nonumber-title-math 10 | . 11 | <paragraph> 12 | referencing: 13 | <pending_xref refdoc="solution/_linked_ref_unenum_mathtitle" refdomain="std" refexplicit="True" reftarget="sol-nonumber-title-math" reftype="ref" refwarn="True"> 14 | <inline classes="xref std std-ref"> 15 | exercise with nonumber but with inline math title 16 | . 17 | -------------------------------------------------------------------------------- /tests/test_solution_references/_linked_ref_unenum_mathtitle2.html: -------------------------------------------------------------------------------- 1 | <p>referencing: <a class="reference internal" href="_linked_unenum_mathtitle2.html#sol-nonumber-title-math2"><span class="std std-ref">Solution to</span></a>.</p> 2 | <p>referencing: <a class="reference internal" href="_linked_unenum_mathtitle2.html#sol-nonumber-title-math2"><span class="std std-ref">exercise with nonumber but with inline math title ex2</span></a>.</p> -------------------------------------------------------------------------------- /tests/test_solution_references/_linked_ref_unenum_mathtitle2.xml: -------------------------------------------------------------------------------- 1 | <document source="_linked_ref_unenum_mathtitle2.rst"> 2 | <section ids="linked-ref-unenum-mathtitle2" names="_linked_ref_unenum_mathtitle2"> 3 | <title> 4 | _linked_ref_unenum_mathtitle2 5 | <paragraph> 6 | referencing: 7 | <pending_xref refdoc="solution/_linked_ref_unenum_mathtitle2" refdomain="std" refexplicit="False" reftarget="sol-nonumber-title-math2" reftype="ref" refwarn="True"> 8 | <inline classes="xref std std-ref"> 9 | sol-nonumber-title-math2 10 | . 11 | <paragraph> 12 | referencing: 13 | <pending_xref refdoc="solution/_linked_ref_unenum_mathtitle2" refdomain="std" refexplicit="True" reftarget="sol-nonumber-title-math2" reftype="ref" refwarn="True"> 14 | <inline classes="xref std std-ref"> 15 | exercise with nonumber but with inline math title ex2 16 | . 17 | -------------------------------------------------------------------------------- /tests/test_solution_references/_linked_ref_unenum_notitle.html: -------------------------------------------------------------------------------- 1 | <p>referencing: <a class="reference internal" href="_linked_unenum_notitle.html#sol-nonumber-notitle"><span class="std std-ref">Solution to</span></a>.</p> 2 | <p>referencing: <a class="reference internal" href="_linked_unenum_notitle.html#sol-nonumber-notitle"><span class="std std-ref">ex with nonumber and notitle</span></a>.</p> -------------------------------------------------------------------------------- /tests/test_solution_references/_linked_ref_unenum_notitle.xml: -------------------------------------------------------------------------------- 1 | <document source="_linked_ref_unenum_notitle.rst"> 2 | <section ids="linked-ref-unenum-notitle" names="_linked_ref_unenum_notitle"> 3 | <title> 4 | _linked_ref_unenum_notitle 5 | <paragraph> 6 | referencing: 7 | <pending_xref refdoc="solution/_linked_ref_unenum_notitle" refdomain="std" refexplicit="False" reftarget="sol-nonumber-notitle" reftype="ref" refwarn="True"> 8 | <inline classes="xref std std-ref"> 9 | sol-nonumber-notitle 10 | . 11 | <paragraph> 12 | referencing: 13 | <pending_xref refdoc="solution/_linked_ref_unenum_notitle" refdomain="std" refexplicit="True" reftarget="sol-nonumber-notitle" reftype="ref" refwarn="True"> 14 | <inline classes="xref std std-ref"> 15 | ex with nonumber and notitle 16 | . 17 | -------------------------------------------------------------------------------- /tests/test_solution_references/_linked_ref_unenum_title.html: -------------------------------------------------------------------------------- 1 | <p>referencing: <a class="reference internal" href="_linked_unenum_title.html#sol-nonumber-title"><span class="std std-ref">Solution to</span></a>.</p> 2 | <p>referencing: <a class="reference internal" href="_linked_unenum_title.html#sol-nonumber-title"><span class="std std-ref">exercise with nonumber but with title</span></a>.</p> -------------------------------------------------------------------------------- /tests/test_solution_references/_linked_ref_unenum_title.xml: -------------------------------------------------------------------------------- 1 | <document source="_linked_ref_unenum_title.rst"> 2 | <section ids="linked-ref-unenum-title" names="_linked_ref_unenum_title"> 3 | <title> 4 | _linked_ref_unenum_title 5 | <paragraph> 6 | referencing: 7 | <pending_xref refdoc="solution/_linked_ref_unenum_title" refdomain="std" refexplicit="False" reftarget="sol-nonumber-title" reftype="ref" refwarn="True"> 8 | <inline classes="xref std std-ref"> 9 | sol-nonumber-title 10 | . 11 | <paragraph> 12 | referencing: 13 | <pending_xref refdoc="solution/_linked_ref_unenum_title" refdomain="std" refexplicit="True" reftarget="sol-nonumber-title" reftype="ref" refwarn="True"> 14 | <inline classes="xref std std-ref"> 15 | exercise with nonumber but with title 16 | . 17 | -------------------------------------------------------------------------------- /tests/test_solution_references/_linked_ref_wronglabel.xml: -------------------------------------------------------------------------------- 1 | <document source="_linked_ref_wronglabel.rst"> 2 | <section ids="linked-ref-wronglabel" names="_linked_ref_wronglabel"> 3 | <title> 4 | _linked_ref_wronglabel 5 | <paragraph> 6 | referencing: 7 | <pending_xref refdoc="solution/_linked_ref_wronglabel" refdomain="std" refexplicit="False" reftarget="foobar" reftype="ref" refwarn="True"> 8 | <inline classes="xref std std-ref"> 9 | foobar 10 | . 11 | -------------------------------------------------------------------------------- /tox.ini: -------------------------------------------------------------------------------- 1 | # To use tox, see https://tox.readthedocs.io 2 | # Simply pip or conda install tox 3 | # If you use conda, you may also want to install tox-conda 4 | # then run `tox` or `tox -- {pytest args}` 5 | # To run in parallel using `tox -p` (this does not appear to work for this repo) 6 | 7 | # To rebuild the tox environment, for example when dependencies change, use 8 | # `tox -r` 9 | 10 | [tox] 11 | envlist = py{311,312} 12 | skip_missing_interpreters = true 13 | 14 | [testenv] 15 | usedevelop=true 16 | recreate = false 17 | 18 | [testenv:py{311,312}-pre-commit] 19 | extras = code_style 20 | commands = pre-commit run {posargs} 21 | 22 | [testenv:py{311,312}-sphinx{5,6}] 23 | extras = testing 24 | deps = 25 | sphinx5: sphinx>=5,<6 26 | sphinx5: sphinx>=6,<7 27 | commands = pytest --verbose {posargs} 28 | 29 | [testenv:docs-{update,clean}] 30 | extras = rtd 31 | whitelist_externals = rm 32 | commands = 33 | clean: rm -rf docs/build 34 | sphinx-build {posargs} -b html docs/source docs/build/html 35 | --------------------------------------------------------------------------------