Skip to content

Commit f356c68

Browse files
committed
0.4.1 - add test test_docstring
Add a test for validating that the docstring of the main component is consistent with that of the auto-generated component.
1 parent d969552 commit f356c68

File tree

3 files changed

+67
-0
lines changed

3 files changed

+67
-0
lines changed

Changelog.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@
66

77
### 0.4.1 @ 10/26/2024
88

9+
#### :mega: New
10+
11+
1. Add a test for validating that the docstring of the main component is consistent with that of the auto-generated component.
12+
913
#### :wrench: Fix
1014

1115
1. Fix: Update the docstring of the component and the typehint `ThemeConfigs` to the newest version.

tests/test_docstring.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# -*- coding: UTF-8 -*-
2+
"""
3+
Docstring
4+
=========
5+
@ Dash JSON Grid Viewer - Tests
6+
7+
Author
8+
------
9+
Yuchen Jin (cainmagi)
10+
11+
12+
Description
13+
-----------
14+
The tests for validating the consistency between the docstrings of the main component
15+
and the auto-generated comonent.
16+
"""
17+
18+
import logging
19+
20+
from dash_json_grid import DashJsonGrid
21+
from dash_json_grid.DashJsonGrid import DashJsonGrid as _DashJsonGrid
22+
23+
from . import utils
24+
25+
26+
__all__ = ("TestDocstring",)
27+
28+
29+
class TestDocstring:
30+
"""Test the consistency between the mixin-merged component and the auto-genrated
31+
component."""
32+
33+
def test_docstring_components(self) -> None:
34+
"""Test the comparison between the docstrings of the components."""
35+
log = logging.getLogger("dash_json_grid.test")
36+
37+
assert utils.docstring_space_remove(
38+
DashJsonGrid
39+
) == utils.docstring_space_remove(_DashJsonGrid)
40+
log.info("Confirm that {0}.__doc__ is valid.".format(DashJsonGrid.__name__))

tests/utils.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
"is_eq_mapping",
3636
"is_eq_sequence",
3737
"is_mapping_with_keys",
38+
"docstring_space_remove",
3839
"attribute_value_neq",
3940
"wait_for_the_attribute_value_neq",
4041
"wait_for_dcc_loading",
@@ -81,6 +82,28 @@ def is_mapping_with_keys(val: Any, keys: Sequence[Any]) -> bool:
8182
return set(val.keys()) == set(keys)
8283

8384

85+
def docstring_space_remove(obj: Any) -> str:
86+
"""Get the docstring of an object, with the leading/trailing spaces removed.
87+
88+
Arguments
89+
---------
90+
obj: `Any`
91+
The object containing a docstring.
92+
93+
Returns
94+
-------
95+
#1: `str`
96+
The normalized docstring of `obj` where the leading/trailing spaces are
97+
removed.
98+
"""
99+
doc = getattr(obj, "__doc__", None)
100+
if not doc:
101+
return ""
102+
if not isinstance(doc, str):
103+
return ""
104+
return "".join(line.strip() for line in doc.splitlines())
105+
106+
84107
class attribute_value_neq:
85108
"""Wait-for method: attribute value does not equal to something.
86109

0 commit comments

Comments
 (0)