Skip to content
This repository was archived by the owner on Apr 26, 2024. It is now read-only.

Commit e446401

Browse files
committed
Add tests for _flatten_dict.
1 parent d5651e5 commit e446401

File tree

1 file changed

+25
-1
lines changed

1 file changed

+25
-1
lines changed

tests/push/test_push_rule_evaluator.py

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
from typing import Dict, List, Optional, Set, Union, cast
15+
from typing import Any, Dict, List, Optional, Set, Union, cast
1616

1717
import frozendict
1818

@@ -37,6 +37,30 @@
3737
from tests.test_utils.event_injection import create_event, inject_member_event
3838

3939

40+
class FlattenDictTestCase(unittest.TestCase):
41+
def test_simple(self) -> None:
42+
"""Test a dictionary that isn't modified."""
43+
input = {"foo": "abc"}
44+
self.assertEqual(input, _flatten_dict(input))
45+
46+
def test_nested(self) -> None:
47+
"""Nested dictionaries become dotted paths."""
48+
input = {"foo": {"bar": "abc"}}
49+
self.assertEqual({"foo.bar": "abc"}, _flatten_dict(input))
50+
51+
def test_non_string(self) -> None:
52+
"""Non-string items are dropped."""
53+
input: Dict[str, Any] = {
54+
"woo": "woo",
55+
"foo": True,
56+
"bar": 1,
57+
"baz": None,
58+
"fuzz": [],
59+
"boo": {},
60+
}
61+
self.assertEqual({"woo": "woo"}, _flatten_dict(input))
62+
63+
4064
class PushRuleEvaluatorTestCase(unittest.TestCase):
4165
def _get_evaluator(
4266
self,

0 commit comments

Comments
 (0)