← GDG /

#188 gdtest_ref_sectioned

#188 gdtest_ref_sectioned OK CONFIG
Reference with 4 named sections, each containing two functions.
Reference with 4 named sections: Constructors, Transformers, Validators, Utilities. Each lists specific exports.
View Site → Build Log ๐Ÿงช Test Coverage

Build Mode

● Has great-docs.yml

This package ships a pre-supplied config. The great-docs init step is skipped and great-docs build uses the spec-defined configuration directly. Tests specific config options and their rendered output.

Dimensions

P5
P5Multi-section refreference

Source Files

๐Ÿ“ gdtest_ref_sectioned/
๐Ÿ“„ __init__.py
"""Test package for reference with 4 named sections."""

from .constructors import create_layout, create_widget
from .transformers import resize, rotate
from .validators import check_bounds, check_type
from .utilities import from_string, to_string

__all__ = [
    "check_bounds", "check_type", "create_layout", "create_widget",
    "from_string", "resize", "rotate", "to_string",
]
๐Ÿ“„ constructors.py
"""Constructor functions for creating widgets and layouts."""


def create_widget(name: str, width: int = 100) -> dict:
    """Create a new widget with the given name and width.

    Parameters
    ----------
    name : str
        The name of the widget.
    width : int, optional
        The width of the widget in pixels, by default 100.

    Returns
    -------
    dict
        A dictionary representing the created widget.

    Examples
    --------
    >>> create_widget("button")
    {'name': 'button', 'width': 100}
    """
    return {"name": name, "width": width}


def create_layout(orientation: str = "horizontal") -> dict:
    """Create a new layout container.

    Parameters
    ----------
    orientation : str, optional
        The layout orientation, by default "horizontal".

    Returns
    -------
    dict
        A dictionary representing the created layout.

    Examples
    --------
    >>> create_layout("vertical")
    {'orientation': 'vertical', 'children': []}
    """
    return {"orientation": orientation, "children": []}
๐Ÿ“„ transformers.py
"""Transformer functions for resizing and rotating."""


def resize(obj: dict, scale: float) -> dict:
    """Resize an object by the given scale factor.

    Parameters
    ----------
    obj : dict
        The object to resize.
    scale : float
        The scale factor to apply.

    Returns
    -------
    dict
        The resized object.

    Examples
    --------
    >>> resize({"width": 100}, 0.5)
    {'width': 50.0}
    """
    return {k: v * scale if isinstance(v, (int, float)) else v for k, v in obj.items()}


def rotate(obj: dict, angle: float) -> dict:
    """Rotate an object by the given angle in degrees.

    Parameters
    ----------
    obj : dict
        The object to rotate.
    angle : float
        The rotation angle in degrees.

    Returns
    -------
    dict
        The rotated object with angle metadata.

    Examples
    --------
    >>> rotate({"name": "box"}, 90.0)
    {'name': 'box', 'rotation': 90.0}
    """
    obj["rotation"] = angle
    return obj
๐Ÿ“„ utilities.py
"""Utility functions for string conversion."""


def to_string(obj: object) -> str:
    """Convert an object to its string representation.

    Parameters
    ----------
    obj : object
        The object to convert.

    Returns
    -------
    str
        The string representation of the object.

    Examples
    --------
    >>> to_string(42)
    '42'
    """
    return str(obj)


def from_string(text: str) -> object:
    """Parse a string into a Python object.

    Parameters
    ----------
    text : str
        The string to parse.

    Returns
    -------
    object
        The parsed object, or the original string if parsing fails.

    Examples
    --------
    >>> from_string("42")
    42
    """
    try:
        return int(text)
    except ValueError:
        try:
            return float(text)
        except ValueError:
            return text
๐Ÿ“„ validators.py
"""Validator functions for checking bounds and types."""


def check_bounds(value: float, low: float, high: float) -> bool:
    """Check if a value is within the given bounds.

    Parameters
    ----------
    value : float
        The value to check.
    low : float
        The lower bound (inclusive).
    high : float
        The upper bound (inclusive).

    Returns
    -------
    bool
        True if the value is within bounds.

    Examples
    --------
    >>> check_bounds(5.0, 0.0, 10.0)
    True
    """
    return low <= value <= high


def check_type(obj: object, expected: type) -> bool:
    """Check if an object is of the expected type.

    Parameters
    ----------
    obj : object
        The object to type-check.
    expected : type
        The expected type.

    Returns
    -------
    bool
        True if the object matches the expected type.

    Examples
    --------
    >>> check_type("hello", str)
    True
    """
    return isinstance(obj, expected)
๐Ÿ“„ README.md
# gdtest-ref-sectioned

Test reference with 4 named sections.
๐Ÿ“„ great-docs.yml
reference:
  - title: Constructors
    desc: Create objects
    contents:
      - name: create_widget
      - name: create_layout
  - title: Transformers
    desc: Transform data
    contents:
      - name: resize
      - name: rotate
  - title: Validators
    desc: Validate input
    contents:
      - name: check_bounds
      - name: check_type
  - title: Utilities
    desc: Helper utils
    contents:
      - name: to_string
      - name: from_string