diff --git a/Changelog.md b/Changelog.md index 12e2a77..17ffe4d 100644 --- a/Changelog.md +++ b/Changelog.md @@ -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. diff --git a/tests/test_docstring.py b/tests/test_docstring.py new file mode 100644 index 0000000..9b5615d --- /dev/null +++ b/tests/test_docstring.py @@ -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__)) diff --git a/tests/utils.py b/tests/utils.py index cf25c39..7e1f926 100644 --- a/tests/utils.py +++ b/tests/utils.py @@ -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", @@ -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.