Skip to content

Commit

Permalink
accept None as empty string
Browse files Browse the repository at this point in the history
  • Loading branch information
daniel-sanche committed Oct 24, 2024
1 parent 6be8180 commit 54e3007
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
6 changes: 3 additions & 3 deletions google/cloud/bigtable/data/_cross_sync/_decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,18 +201,18 @@ def __init__(
sync_name: str | None = None,
*,
replace_symbols: dict[str, str] | None = None,
docstring_format_vars: dict[str, tuple[str, str]] | None = None,
docstring_format_vars: dict[str, tuple[str | None, str | None]] | None = None,
rm_aio: bool = False,
add_mapping_for_name: str | None = None,
):
self.sync_name = sync_name
self.replace_symbols = replace_symbols
docstring_format_vars = docstring_format_vars or {}
self.async_docstring_format_vars = {
k: v[0] for k, v in docstring_format_vars.items()
k: v[0] or "" for k, v in docstring_format_vars.items()
}
self.sync_docstring_format_vars = {
k: v[1] for k, v in docstring_format_vars.items()
k: v[1] or "" for k, v in docstring_format_vars.items()
}
self.rm_aio = rm_aio
self.add_mapping_for_name = add_mapping_for_name
Expand Down
16 changes: 12 additions & 4 deletions tests/unit/data/_cross_sync/test_cross_sync_decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,10 @@ def test_class_decorator_adds_mapping(self):
["{A}", {"A": (1, 2)}, "1"],
["{A} {B}", {"A": (1, 2), "B": (3, 4)}, "1 3"],
["hello {world_var}", {"world_var": ("world", "moon")}, "hello world"],
["{empty}", {"empty": ("", "")}, ""],
["{empty}", {"empty": (None, None)}, ""],
["maybe{empty}", {"empty": (None, "yes")}, "maybe"],
["maybe{empty}", {"empty": (" no", None)}, "maybe no"]
],
)
def test_class_decorator_docstring_update(self, docstring, format_vars, expected):
Expand All @@ -123,8 +127,8 @@ class Class:
assert Class.__doc__ == expected
# check internal state
instance = self._get_class()(sync_name="s", docstring_format_vars=format_vars)
async_replacements = {k: v[0] for k, v in format_vars.items()}
sync_replacements = {k: v[1] for k, v in format_vars.items()}
async_replacements = {k: v[0] or "" for k, v in format_vars.items()}
sync_replacements = {k: v[1] or "" for k, v in format_vars.items()}
assert instance.async_docstring_format_vars == async_replacements
assert instance.sync_docstring_format_vars == sync_replacements

Expand Down Expand Up @@ -299,6 +303,10 @@ def test_async_decorator_no_docstring(self):
["{A}", {"A": (1, 2)}, "1"],
["{A} {B}", {"A": (1, 2), "B": (3, 4)}, "1 3"],
["hello {world_var}", {"world_var": ("world", "moon")}, "hello world"],
["{empty}", {"empty": ("", "")}, ""],
["{empty}", {"empty": (None, None)}, ""],
["maybe{empty}", {"empty": (None, "yes")}, "maybe"],
["maybe{empty}", {"empty": (" no", None)}, "maybe no"]
],
)
def test_async_decorator_docstring_update(self, docstring, format_vars, expected):
Expand All @@ -314,8 +322,8 @@ class Class:
assert Class.__doc__ == expected
# check internal state
instance = self._get_class()(docstring_format_vars=format_vars)
async_replacements = {k: v[0] for k, v in format_vars.items()}
sync_replacements = {k: v[1] for k, v in format_vars.items()}
async_replacements = {k: v[0] or "" for k, v in format_vars.items()}
sync_replacements = {k: v[1] or "" for k, v in format_vars.items()}
assert instance.async_docstring_format_vars == async_replacements
assert instance.sync_docstring_format_vars == sync_replacements

Expand Down

0 comments on commit 54e3007

Please sign in to comment.