Skip to content

Commit

Permalink
0.4.1 - add test test_docstring
Browse files Browse the repository at this point in the history
Add a test for validating that the docstring of the main component is consistent with that of the auto-generated component.
  • Loading branch information
cainmagi committed Oct 26, 2024
1 parent d969552 commit f356c68
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 0 deletions.
4 changes: 4 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@

### 0.4.1 @ 10/26/2024

#### :mega: New

1. Add a test for validating that the docstring of the main component is consistent with that of the auto-generated component.

#### :wrench: Fix

1. Fix: Update the docstring of the component and the typehint `ThemeConfigs` to the newest version.
Expand Down
40 changes: 40 additions & 0 deletions tests/test_docstring.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# -*- coding: UTF-8 -*-
"""
Docstring
=========
@ Dash JSON Grid Viewer - Tests
Author
------
Yuchen Jin (cainmagi)
cainmagi@gmail.com
Description
-----------
The tests for validating the consistency between the docstrings of the main component
and the auto-generated comonent.
"""

import logging

from dash_json_grid import DashJsonGrid
from dash_json_grid.DashJsonGrid import DashJsonGrid as _DashJsonGrid

from . import utils


__all__ = ("TestDocstring",)


class TestDocstring:
"""Test the consistency between the mixin-merged component and the auto-genrated
component."""

def test_docstring_components(self) -> None:
"""Test the comparison between the docstrings of the components."""
log = logging.getLogger("dash_json_grid.test")

assert utils.docstring_space_remove(
DashJsonGrid
) == utils.docstring_space_remove(_DashJsonGrid)
log.info("Confirm that {0}.__doc__ is valid.".format(DashJsonGrid.__name__))
23 changes: 23 additions & 0 deletions tests/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
"is_eq_mapping",
"is_eq_sequence",
"is_mapping_with_keys",
"docstring_space_remove",
"attribute_value_neq",
"wait_for_the_attribute_value_neq",
"wait_for_dcc_loading",
Expand Down Expand Up @@ -81,6 +82,28 @@ def is_mapping_with_keys(val: Any, keys: Sequence[Any]) -> bool:
return set(val.keys()) == set(keys)


def docstring_space_remove(obj: Any) -> str:
"""Get the docstring of an object, with the leading/trailing spaces removed.
Arguments
---------
obj: `Any`
The object containing a docstring.
Returns
-------
#1: `str`
The normalized docstring of `obj` where the leading/trailing spaces are
removed.
"""
doc = getattr(obj, "__doc__", None)
if not doc:
return ""
if not isinstance(doc, str):
return ""
return "".join(line.strip() for line in doc.splitlines())


class attribute_value_neq:
"""Wait-for method: attribute value does not equal to something.
Expand Down

0 comments on commit f356c68

Please sign in to comment.