diff options
-rw-r--r-- | rtemsqual/specdoc.py | 11 | ||||
-rw-r--r-- | rtemsqual/sphinxcontent.py | 19 | ||||
-rw-r--r-- | rtemsqual/tests/test_content_sphinx.py | 6 | ||||
-rw-r--r-- | rtemsqual/tests/test_specdoc.py | 8 |
4 files changed, 25 insertions, 19 deletions
diff --git a/rtemsqual/specdoc.py b/rtemsqual/specdoc.py index a3611045..1cdbaf04 100644 --- a/rtemsqual/specdoc.py +++ b/rtemsqual/specdoc.py @@ -26,7 +26,7 @@ from typing import Any, Dict, Iterator, List, Optional, Set, Tuple -from rtemsqual.sphinxcontent import get_reference, get_section_label, \ +from rtemsqual.sphinxcontent import get_reference, get_label, \ SphinxContent, SphinxMapper from rtemsqual.items import Item, ItemCache from rtemsqual.specverify import NAME @@ -54,7 +54,7 @@ _REQUIRED_ATTRIBUTES = { "none": "None of the explicitly defined attributes are required.", } -_SECTION_PREFIX = "SpecType" +_SPEC_TYPE_PREFIX = "SpecType" def _a_or_an(value: str) -> str: @@ -64,7 +64,7 @@ def _a_or_an(value: str) -> str: def _get_ref_specification_type(value: Any, key: str) -> str: - return get_reference(get_section_label(value[key], _SECTION_PREFIX)) + return get_reference(_SPEC_TYPE_PREFIX + get_label(value[key])) class _AssertContext: @@ -278,7 +278,7 @@ class _Documenter: def get_section_reference(self) -> str: """ Returns the section reference. """ - return get_reference(get_section_label(self.section, _SECTION_PREFIX)) + return get_reference(_SPEC_TYPE_PREFIX + get_label(self.section)) def get_a_section_reference(self) -> str: """ Returns a section reference. """ @@ -430,7 +430,7 @@ class _Documenter: if self.get_list_element_type(): return content.register_license_and_copyrights_of_item(self._item) - with content.section(self.section, _SECTION_PREFIX): + with content.section(self.section, _SPEC_TYPE_PREFIX): last = content.lines[-1] self._add_description(content) if len(self._info_map) == 1: @@ -550,6 +550,7 @@ def document(config: dict, item_cache: ItemCache) -> None: for documenter in documenter_map.values(): documenter.resolve_used_by() documenter_names = set(documenter_map.keys()) + content.section_label_prefix = "ReqEng" with content.section("Specification Items"): with content.section("Specification Item Hierarchy"): content.add( diff --git a/rtemsqual/sphinxcontent.py b/rtemsqual/sphinxcontent.py index e2b2bbc8..c29586f3 100644 --- a/rtemsqual/sphinxcontent.py +++ b/rtemsqual/sphinxcontent.py @@ -54,9 +54,9 @@ def get_reference(label: str, name: Optional[str] = None) -> str: return f":ref:`{label}`" -def get_section_label(name: str, prefix: str = "Section") -> str: - """ Returns the section label for the specified section name. """ - return prefix + _to_camel_case(name.strip()) +def get_label(name: str) -> str: + """ Returns the label for the specified name. """ + return _to_camel_case(name.strip()) class SphinxContent(Content): @@ -65,6 +65,7 @@ class SphinxContent(Content): super().__init__("CC-BY-SA-4.0", True) self._tab = " " self._section_level = section_level + self.section_label_prefix = "Section" def add_label(self, label: str) -> None: """ Adds a label. """ @@ -78,9 +79,11 @@ class SphinxContent(Content): def add_header_with_label(self, name: str, level: int = 2, - label_prefix: str = "Section") -> str: + label_prefix: Optional[str] = None) -> str: """ Adds a header with label. """ - label = get_section_label(name, label_prefix) + if label_prefix is None: + label_prefix = self.section_label_prefix + label = label_prefix + get_label(name) self.add_label(label) self.add_header(name, level) return label @@ -125,7 +128,9 @@ class SphinxContent(Content): yield self.close_directive() - def open_section(self, name: str, label_prefix: str = "Section") -> str: + def open_section(self, + name: str, + label_prefix: Optional[str] = None) -> str: """ Opens a section. """ label = self.add_header_with_label(name, self._section_level, label_prefix) @@ -139,7 +144,7 @@ class SphinxContent(Content): @contextmanager def section(self, name: str, - label_prefix: str = "Section") -> Iterator[str]: + label_prefix: Optional[str] = None) -> Iterator[str]: """ Opens a section context. """ yield self.open_section(name, label_prefix) self.close_section() diff --git a/rtemsqual/tests/test_content_sphinx.py b/rtemsqual/tests/test_content_sphinx.py index 83f4cbd9..46ea052b 100644 --- a/rtemsqual/tests/test_content_sphinx.py +++ b/rtemsqual/tests/test_content_sphinx.py @@ -26,7 +26,7 @@ import pytest -from rtemsqual.sphinxcontent import get_reference, get_section_label, \ +from rtemsqual.sphinxcontent import get_reference, get_label, \ SphinxContent, SphinxMapper from rtemsqual.items import Item, ItemCache, ItemMapper from rtemsqual.tests.util import create_item_cache_config_and_copy_spec @@ -104,8 +104,8 @@ def test_get_reference(): assert get_reference("a", "b") == ":ref:`b <a>`" -def test_get_section_label(): - assert get_section_label("ab cd") == "SectionAbCd" +def test_get_label(): + assert get_label("ab cd") == "AbCd" def test_section(): diff --git a/rtemsqual/tests/test_specdoc.py b/rtemsqual/tests/test_specdoc.py index c4f0c74d..72cfb7f0 100644 --- a/rtemsqual/tests/test_specdoc.py +++ b/rtemsqual/tests/test_specdoc.py @@ -46,12 +46,12 @@ def test_document(tmpdir): .. Copyright (C) 2020 embedded brains GmbH (http://www.embedded-brains.de) -.. _SectionSpecificationItems: +.. _ReqEngSpecificationItems: Specification Items =================== -.. _SectionSpecificationItemHierarchy: +.. _ReqEngSpecificationItemHierarchy: Specification Item Hierarchy ---------------------------- @@ -64,7 +64,7 @@ The specification item types have the following hierarchy: * :ref:`SpecTypeB` -.. _SectionSpecificationItemTypes: +.. _ReqEngSpecificationItemTypes: Specification Item Types ------------------------ @@ -223,7 +223,7 @@ Generic attributes may be defined. Each attribute key shall be a :ref:`SpecTypeName`. The attribute value shall be a list. Each list element shall be a string. -.. _SectionSpecificationAttributeSetsAndValueTypes: +.. _ReqEngSpecificationAttributeSetsAndValueTypes: Specification Attribute Sets and Value Types -------------------------------------------- |