提交 2ad248f3 编写于 作者: HansBug's avatar HansBug 😆

dev(hansbug): update the default value of include_nodes from False to True

上级 c803ab42
...@@ -623,7 +623,7 @@ def get_tree_test(tree_value_clazz: Type[TreeValue]): ...@@ -623,7 +623,7 @@ def get_tree_test(tree_value_clazz: Type[TreeValue]):
def test_walk(self): def test_walk(self):
tv1 = tree_value_clazz({'a': 1, 'b': 'dks', 'c': {'x': 2, 'y': 3}}) tv1 = tree_value_clazz({'a': 1, 'b': 'dks', 'c': {'x': 2, 'y': 3}})
for p, v in tv1.walk(): for p, v in tv1.walk(include_nodes=False):
if p == ('a',): if p == ('a',):
assert v == 1 assert v == 1
elif p == ('b',): elif p == ('b',):
...@@ -635,7 +635,7 @@ def get_tree_test(tree_value_clazz: Type[TreeValue]): ...@@ -635,7 +635,7 @@ def get_tree_test(tree_value_clazz: Type[TreeValue]):
else: else:
pytest.fail('Should not reach here - %s is accessed.' % (repr(p),)) pytest.fail('Should not reach here - %s is accessed.' % (repr(p),))
for p, v in tv1.walk(include_nodes=True): for p, v in tv1.walk():
if p == (): if p == ():
assert v == tv1 assert v == tv1
elif p == ('a',): elif p == ('a',):
......
...@@ -105,9 +105,17 @@ class TestTreeTreeService: ...@@ -105,9 +105,17 @@ class TestTreeTreeService:
tv1 = MyTreeValue({'a': 1, 'b': 2, 'c': {'x': 2, 'y': 3}}) tv1 = MyTreeValue({'a': 1, 'b': 2, 'c': {'x': 2, 'y': 3}})
assert dict(walk(tv1, include_nodes=False)) == {
('a',): 1,
('b',): 2,
('c', 'x',): 2,
('c', 'y',): 3,
}
assert dict(walk(tv1)) == { assert dict(walk(tv1)) == {
(): MyTreeValue({'a': 1, 'b': 2, 'c': {'x': 2, 'y': 3}}),
('a',): 1, ('a',): 1,
('b',): 2, ('b',): 2,
('c',): MyTreeValue({'x': 2, 'y': 3}),
('c', 'x',): 2, ('c', 'x',): 2,
('c', 'y',): 3, ('c', 'y',): 3,
} }
...@@ -126,8 +134,10 @@ class TestTreeTreeService: ...@@ -126,8 +134,10 @@ class TestTreeTreeService:
'c': delayed(lambda: tv1.c), 'c': delayed(lambda: tv1.c),
}) })
assert dict(walk(tv2)) == { assert dict(walk(tv2)) == {
(): MyTreeValue({'a': 1, 'b': 2, 'c': {'x': 2, 'y': 3}}),
('a',): 1, ('a',): 1,
('b',): 2, ('b',): 2,
('c',): MyTreeValue({'x': 2, 'y': 3}),
('c', 'x',): 2, ('c', 'x',): 2,
('c', 'y',): 3, ('c', 'y',): 3,
} }
...@@ -210,7 +210,7 @@ def general_tree_value(base: Optional[Mapping[str, Any]] = None, ...@@ -210,7 +210,7 @@ def general_tree_value(base: Optional[Mapping[str, Any]] = None,
return filter_(self, func, remove_empty) return filter_(self, func, remove_empty)
@_decorate_method @_decorate_method
def walk(self, include_nodes: bool = False): def walk(self, include_nodes: bool = True):
""" """
Overview: Overview:
Walk the values and nodes in the tree. Walk the values and nodes in the tree.
......
...@@ -106,7 +106,7 @@ def _p_walk(TreeStorage tree, object type_, tuple path, bool include_nodes): ...@@ -106,7 +106,7 @@ def _p_walk(TreeStorage tree, object type_, tuple path, bool include_nodes):
yield curpath, v yield curpath, v
@cython.binding(True) @cython.binding(True)
cpdef walk(TreeValue tree, bool include_nodes=False): cpdef walk(TreeValue tree, bool include_nodes=True):
""" """
Overview: Overview:
Walk the values and nodes in the tree. Walk the values and nodes in the tree.
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册