diff --git a/pyproject.toml b/pyproject.toml index e445d6c..51faf5b 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -9,7 +9,7 @@ authors = ["team procitec "] license = "MIT" readme = "README.rst" repository = "https://github.com/procitec/sphinx-test-spec" -documentation = "" +documentation = "https://github.com/procitec/sphinx-test-spec" classifiers=[ 'Development Status :: 3 - Alpha', 'Intended Audience :: Developers', diff --git a/sphinx_test_spec/directives.py b/sphinx_test_spec/directives.py index 1258a81..e60d70a 100644 --- a/sphinx_test_spec/directives.py +++ b/sphinx_test_spec/directives.py @@ -112,7 +112,7 @@ def run(self): # any colgroup definitions. class_colwidth = "colwidths-given" if 0 < len(widths) else "colwidths-auto" - _state.node_table = nodes.table(classes=["test-case", class_colwidth]) # , ids=_state.node_table_id) + _state.node_table = nodes.table(classes=classes + [class_colwidth]) # , ids=_state.node_table_id) _state.node_tgroup = nodes.tgroup(cols=_state.columns) @@ -195,7 +195,7 @@ def run(self): # todo add odd/even to clases if "class" in self.options: - classes.append(self.options["classes"]) + classes.append(self.options["class"]) node_row = nodes.row(classes=[_class_test_action_row]) @@ -261,7 +261,7 @@ def run(self): # todo add odd/even to clases if "class" in self.options: - classes.append(self.options["classes"]) + classes.append(self.options["class"]) logger.debug(f"adding test reaction with content {self.content}") self.assert_has_content() @@ -274,7 +274,6 @@ def run(self): # the reaction directive could occur only onces or never in an action if _state.node_reaction is None: - node = nodes.entry(**kwargs) # node = nodes.entry(classes=classes, ids=ids ) self.state.nested_parse(self.content, self.content_offset, node) @@ -287,7 +286,6 @@ def run(self): class FileListDirective(SphinxDirective): - has_content = False required_arguments = 0 option_spec = { @@ -305,17 +303,17 @@ def run(self): if "filter" in self.options: filter_string = self.options["filter"] - for (k, v) in _files.items(): + for k, v in _files.items(): name = v["name"] suffix = v["suffix"] if bool(eval(filter_string, None, locals())): _content.append(k) else: - for (k, v) in _files.items(): + for k, v in _files.items(): _content.append(k) if "class" in self.options: - _classes.append(self.options["classes"]) + _classes.append(self.options["class"]) listnode = nodes.bullet_list(classes=_classes) for entry in _content: diff --git a/sphinx_test_spec/domain.py b/sphinx_test_spec/domain.py index 2a53ca2..51b97aa 100644 --- a/sphinx_test_spec/domain.py +++ b/sphinx_test_spec/domain.py @@ -81,7 +81,6 @@ def run(self) -> tuple[list[Node], list[system_message]]: class TestSpecDomain(Domain): - name = "test" label = "Test Specifications" roles = {"case": XRefRole(), "action": XRefRole(), "file": FileRole()} diff --git a/sphinx_test_spec/main.py b/sphinx_test_spec/main.py index eb73004..1fbd457 100644 --- a/sphinx_test_spec/main.py +++ b/sphinx_test_spec/main.py @@ -15,15 +15,14 @@ def rst_testspec_jinja(app, docname, source): Render our pages as a jinja template for fancy templating goodness. """ # Make sure we're outputting HTML - if not hasattr(app.builder, 'templates'): + if not hasattr(app.builder, "templates"): return src = source[0] - rendered = app.builder.templates.render_string( - src, app.config.testspec_context - ) + rendered = app.builder.templates.render_string(src, app.config.testspec_context) source[0] = rendered + def setup(app): app.add_config_value("testspec_state_symbol", "", "html", [str]) app.add_config_value("testspec_header", [], "html", [list]) diff --git a/tests/doc_test/doc_case_custom_classes/Makefile b/tests/doc_test/doc_case_custom_classes/Makefile new file mode 100644 index 0000000..058d41e --- /dev/null +++ b/tests/doc_test/doc_case_custom_classes/Makefile @@ -0,0 +1,19 @@ +# Minimal makefile for Sphinx documentation +# + +# You can set these variables from the command line. +SPHINXOPTS = -v -v -v +SPHINXBUILD = sphinx-build +SOURCEDIR = . +BUILDDIR = _build + +# Put it first so that "make" without argument is like "make help". +help: + @$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) + +.PHONY: help Makefile + +# Catch-all target: route all unknown targets to Sphinx using the new +# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS). +%: Makefile + @$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) diff --git a/tests/doc_test/doc_case_custom_classes/conf.py b/tests/doc_test/doc_case_custom_classes/conf.py new file mode 100644 index 0000000..e3279d4 --- /dev/null +++ b/tests/doc_test/doc_case_custom_classes/conf.py @@ -0,0 +1,72 @@ +import os + +extensions = ["sphinx_test_spec"] + +test_dir = os.path.dirname(__file__) + +# General information about the project. +project = "sphinx-test-spec test docs" +copyright = "2023, team procitec" +author = "team procitec" + +# The master toctree document. +master_doc = "index" + +# The version info for the project you're documenting, acts as replacement for +# |version| and |release|, also used in various other places throughout the +# built documents. +# +# The short X.Y version. +version = "1.0" +# The full version, including alpha/beta/rc tags. +release = "1.0" + +# The language for content autogenerated by Sphinx. Refer to documentation +# for a list of supported languages. +# +# This is also used if you do content translation via gettext catalogs. +# Usually you set "language" from the command line for these cases. +language = "en" + +# List of patterns, relative to source directory, that match files and +# directories to ignore when looking for source files. +# This patterns also effect to html_static_path and html_extra_path +exclude_patterns = ["_build"] +html_domain_indices = False + +# If true, `todo` and `todoList` produce output, else they produce nothing. +todo_include_todos = False + +# Output file base name for HTML help builder. +htmlhelp_basename = "test-spec-test-docsdoc" + + +# Grouping the document tree into LaTeX files. List of tuples +# (source start file, target name, title, +# author, documentclass [howto, manual, or own class]). +latex_documents = [ + (master_doc, "test-spec-test-docs.tex", "rst-table test docs Documentation", "team procitec", "manual"), +] + +# -- Options for manual page output --------------------------------------- + +# One entry per manual page. List of tuples +# (source start file, name, description, authors, manual section). +man_pages = [(master_doc, "test-spec-test-docs", "rst-table test docs Documentation", [author], 1)] + +# -- Options for Texinfo output ------------------------------------------- + +# Grouping the document tree into Texinfo files. List of tuples +# (source start file, target name, title, author, +# dir menu entry, description, category) +texinfo_documents = [ + ( + master_doc, + "test-spec-test-docs", + "rst-table test docs Documentation", + author, + "test-spec-test-docs", + "One line description of project.", + "Miscellaneous", + ), +] diff --git a/tests/doc_test/doc_case_custom_classes/index.rst b/tests/doc_test/doc_case_custom_classes/index.rst new file mode 100644 index 0000000..4c94e2e --- /dev/null +++ b/tests/doc_test/doc_case_custom_classes/index.rst @@ -0,0 +1,17 @@ +Testing your calculator app +=========================== + +.. test:case:: Summarize and Clear values in calculator + :class: custom-case + + This is free text before the table after the title + + .. test:action:: Type '2+2' into your systems calculator app and press ''. + :class: custom-action + + .. test:reaction:: The calculator sums and shows you '4' as result. + :class: custom-reaction + + .. test:action:: Clear the results, e.g. by typing '' or another button for clearing the results in your app + + .. test:reaction:: The calculator does show '0' or shows nothing diff --git a/tests/doc_test/doc_case_custom_classes/make.bat b/tests/doc_test/doc_case_custom_classes/make.bat new file mode 100644 index 0000000..0fcccb2 --- /dev/null +++ b/tests/doc_test/doc_case_custom_classes/make.bat @@ -0,0 +1,36 @@ +@ECHO OFF + +pushd %~dp0 + +REM Command file for Sphinx documentation + +if "%SPHINXBUILD%" == "" ( + set SPHINXBUILD=sphinx-build +) +set SOURCEDIR=. +set BUILDDIR=_build +set SPHINXPROJ=rsttabletestdocs + +if "%1" == "" goto help + +%SPHINXBUILD% >NUL 2>NUL +if errorlevel 9009 ( + echo. + echo.The 'sphinx-build' command was not found. Make sure you have Sphinx + echo.installed, then set the SPHINXBUILD environment variable to point + echo.to the full path of the 'sphinx-build' executable. Alternatively you + echo.may add the Sphinx directory to PATH. + echo. + echo.If you don't have Sphinx installed, grab it from + echo.http://sphinx-doc.org/ + exit /b 1 +) + +%SPHINXBUILD% -M %1 %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% +goto end + +:help +%SPHINXBUILD% -M help %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% + +:end +popd diff --git a/tests/test_doc_case_custom_classes.py b/tests/test_doc_case_custom_classes.py new file mode 100644 index 0000000..df4a7e5 --- /dev/null +++ b/tests/test_doc_case_custom_classes.py @@ -0,0 +1,38 @@ +from pathlib import Path + +import pytest +from sphinx.util import logging + +logger = logging.getLogger(__name__) + +import sys + + +@pytest.mark.parametrize( + "test_app", + [{"buildername": "html", "srcdir": "doc_test/doc_case_custom_classes", "warnings": sys.stderr}], + indirect=True, +) +def test_case_classes(test_app): + app = test_app + app.build() + html = Path(app.outdir, "index.html").read_text() + + assert html.count("') == 1 + assert html.count('') == 1 + assert html.count('') == 1 + assert html.count('') == 1 + assert html.count('') == 2 + + assert html.count('
') == 1 + + assert ( + '
\n

This is free text before the table after the title

\n
' + in html + )