From f526c9c2c692903611d5a6051d586b96a2eea906 Mon Sep 17 00:00:00 2001 From: Kay Date: Wed, 10 Sep 2025 00:45:55 +0800 Subject: [PATCH 1/4] feat: nested_key_dict to tree to support child_key=None --- bigtree/tree/construct/dictionaries.py | 38 +++++++++- tests/tree/construct/test_dictionaries.py | 90 +++++++++++++++++++++++ 2 files changed, 125 insertions(+), 3 deletions(-) diff --git a/bigtree/tree/construct/dictionaries.py b/bigtree/tree/construct/dictionaries.py index 0e58ad2d..5763e719 100644 --- a/bigtree/tree/construct/dictionaries.py +++ b/bigtree/tree/construct/dictionaries.py @@ -305,11 +305,13 @@ def _recursive_add_child( def nested_dict_key_to_tree( node_attrs: Mapping[str, Mapping[str, Any]], - child_key: str = "children", + child_key: Optional[str] = "children", node_type: Type[T] = node.Node, # type: ignore[assignment] ) -> T: """Construct tree from nested recursive dictionary, where the keys are node names. + If child_key is a string + - ``key``: node name - ``value``: dict of node attributes and node children (recursive) @@ -318,6 +320,15 @@ def nested_dict_key_to_tree( - ``key`` that is not ``child_key`` has node attribute as value - ``key`` that is ``child_key`` has dictionary of node children as value (recursive) + --- + + If child_key is None + + - ``key``: node name + - ``value``: dict of node children (recursive), there are no node attributes + + Value dictionary consist of ``key`` that is node names of children + Examples: >>> from bigtree import nested_dict_key_to_tree >>> nested_dict = { @@ -345,6 +356,23 @@ def nested_dict_key_to_tree( └── e [age=35] └── g [age=10] + >>> from bigtree import nested_dict_key_to_tree + >>> nested_dict = { + ... "a": { + ... "b": { + ... "d": {}, + ... "e": {"g": {}}, + ... }, + ... } + ... } + >>> root = nested_dict_key_to_tree(nested_dict, child_key=None) + >>> root.show() + a + └── b + ├── d + └── e + └── g + Args: node_attrs: node, children, and node attribute information, key: node name @@ -370,8 +398,12 @@ def _recursive_add_child( Returns: Node """ - child_dict = dict(child_dict) - node_children = child_dict.pop(child_key, {}) + if child_key: + child_dict = dict(child_dict) + node_children = child_dict.pop(child_key, {}) + else: + node_children = child_dict + child_dict = {} if not isinstance(node_children, Mapping): raise TypeError( f"child_key {child_key} should be Dict type, received {node_children}" diff --git a/tests/tree/construct/test_dictionaries.py b/tests/tree/construct/test_dictionaries.py index 62481d28..34e7fc9e 100644 --- a/tests/tree/construct/test_dictionaries.py +++ b/tests/tree/construct/test_dictionaries.py @@ -1016,3 +1016,93 @@ def test_nested_dict_key_to_tree_custom_node_type(): assert_tree_structure_basenode_root(root) assert_tree_structure_customnode_root_attr(root) assert_tree_structure_node_root(root) + + +class TestNestedDictKeyToTreeNullKey(unittest.TestCase): + def setUp(self): + """ + Tree should have structure + a + |-- b + | |-- d + | +-- e + | |-- g + | +-- h + +-- c + +-- f + """ + self.nested_dict = { + "a": { + "b": { + "d": {}, + "e": { + "g": {}, + "h": {}, + }, + }, + "c": {"f": {}}, + } + } + + def tearDown(self): + self.nested_dict = None + + def test_nested_dict_key_to_tree(self): + root = construct.nested_dict_key_to_tree(self.nested_dict, child_key=None) + assert_tree_structure_basenode_root(root) + assert_tree_structure_node_root(root) + + @staticmethod + def test_nested_dict_key_to_tree_null_children_error(): + child_key = None + child = None + nested_dict = { + "a": { + "b": { + "d": {}, + "e": { + "g": child, + "h": {}, + }, + }, + "c": {"f": {}}, + } + } + with pytest.raises(TypeError) as exc_info: + construct.nested_dict_key_to_tree(nested_dict, child_key=child_key) + assert str(exc_info.value) == Constants.ERROR_NODE_DICT_CHILD_TYPE.format( + child_key=child_key, type="Dict", child=child + ) + + @staticmethod + def test_nested_dict_key_to_tree_int_children_error(): + child_key = None + child = 1 + nested_dict = { + "a": { + "b": { + "d": {}, + "e": { + "g": child, + "h": {}, + }, + }, + "c": {"f": {}}, + } + } + with pytest.raises(TypeError) as exc_info: + construct.nested_dict_key_to_tree(nested_dict, child_key=child_key) + assert str(exc_info.value) == Constants.ERROR_NODE_DICT_CHILD_TYPE.format( + child_key=child_key, type="Dict", child=child + ) + + def test_nested_dict_key_to_tree_node_type(self): + root = construct.nested_dict_key_to_tree( + self.nested_dict, child_key=None, node_type=NodeA + ) + assert isinstance(root, NodeA), Constants.ERROR_CUSTOM_TYPE.format(type="NodeA") + assert all( + isinstance(_node, NodeA) for _node in root.children + ), Constants.ERROR_CUSTOM_TYPE.format(type="NodeA") + assert_tree_structure_basenode_root(root) + assert_tree_structure_node_root(root) From 0dd54c7369d69ddd674ab51507bd08752aef5b76 Mon Sep 17 00:00:00 2001 From: Kay Date: Wed, 10 Sep 2025 01:11:51 +0800 Subject: [PATCH 2/4] feat: tree to nested_key_dict to support child_key=None --- bigtree/tree/export/dictionaries.py | 23 +++++++--- tests/test_constants.py | 3 ++ tests/tree/export/test_dictionaries.py | 60 +++++++++++++++++++++++++- 3 files changed, 80 insertions(+), 6 deletions(-) diff --git a/bigtree/tree/export/dictionaries.py b/bigtree/tree/export/dictionaries.py index bff612bb..afcc95fd 100644 --- a/bigtree/tree/export/dictionaries.py +++ b/bigtree/tree/export/dictionaries.py @@ -150,7 +150,7 @@ def _recursive_append(_node: T, parent_dict: Dict[str, Any]) -> None: def tree_to_nested_dict_key( tree: T, - child_key: str = "children", + child_key: Optional[str] = "children", attr_dict: Optional[Dict[str, str]] = None, all_attrs: bool = False, max_depth: int = 0, @@ -160,6 +160,7 @@ def tree_to_nested_dict_key( All descendants from `tree` will be exported, `tree` can be the root node or child node of tree. Exported dictionary will have key as node names, and children as node attributes and nested recursive dictionary. + If child_key is None, the children key is nested recursive dictionary of node names (there will be no attributes). Examples: >>> from bigtree import Node, tree_to_nested_dict_key @@ -171,6 +172,9 @@ def tree_to_nested_dict_key( >>> tree_to_nested_dict_key(root, all_attrs=True) {'a': {'age': 90, 'children': {'b': {'age': 65, 'children': {'d': {'age': 40}, 'e': {'age': 35}}}, 'c': {'age': 60}}}} + >>> tree_to_nested_dict_key(root, child_key=None) + {'a': {'b': {'d': {}, 'e': {}}, 'c': {}}} + Args: tree: tree to be exported child_key: dictionary key for children @@ -190,16 +194,25 @@ def _recursive_append(_node: T, parent_dict: Dict[str, Any]) -> None: _node: current node parent_dict: parent dictionary """ + if child_key is None: + if attr_dict or all_attrs: + raise ValueError( + "If child_key is None, no node attributes can be exported" + ) + if _node: if not max_depth or _node.depth <= max_depth: data_child = common.assemble_attributes(_node, attr_dict, all_attrs) - if child_key in parent_dict: - parent_dict[child_key][_node.node_name] = data_child + if child_key: + if child_key in parent_dict: + parent_dict[child_key][_node.node_name] = data_child + else: + parent_dict[child_key] = {_node.node_name: data_child} else: - parent_dict[child_key] = {_node.node_name: data_child} + parent_dict[_node.node_name] = data_child for _child in _node.children: _recursive_append(_child, data_child) _recursive_append(tree, data_dict) - return data_dict[child_key] + return data_dict[child_key] if child_key else data_dict diff --git a/tests/test_constants.py b/tests/test_constants.py index 17d4740a..e670feaa 100644 --- a/tests/test_constants.py +++ b/tests/test_constants.py @@ -136,6 +136,9 @@ class Constants: # tree/export ERROR_NODE_TYPE = "Tree should be of type `{type}`, or inherit from `{type}`" + ERROR_NODE_EXPORT_DICT_NO_ATTRS = ( + "If child_key is None, no node attributes can be exported" + ) ERROR_NODE_EXPORT_PRINT_ATTR_BRACKET = ( "Expect open and close brackets in `attr_bracket`, received {attr_bracket}" ) diff --git a/tests/tree/export/test_dictionaries.py b/tests/tree/export/test_dictionaries.py index e189621a..789e6532 100644 --- a/tests/tree/export/test_dictionaries.py +++ b/tests/tree/export/test_dictionaries.py @@ -1,3 +1,5 @@ +import pytest + from bigtree.node import node from bigtree.tree import export from tests.node.test_basenode import ( @@ -5,6 +7,7 @@ assert_tree_structure_basenode_root_attr, ) from tests.node.test_node import assert_tree_structure_node_root +from tests.test_constants import Constants class TestTreeToDict: @@ -437,7 +440,7 @@ def test_tree_to_nested_dict_key_attr_dict(tree_node): }, } } - actual = export.tree_to_nested_dict_key(tree_node, attr_dict={"age": "AGE"}) + actual = export.tree_to_nested_dict_key(tree_node, attr_dict={"age": age_key}) assert actual == expected, f"Expected\n{expected}\nReceived\n{actual}" @staticmethod @@ -539,3 +542,58 @@ def test_tree_to_nested_dict_key_to_tree(tree_node): assert_tree_structure_basenode_root(tree) assert_tree_structure_basenode_root_attr(tree) assert_tree_structure_node_root(tree) + + +class TestTreeToNestedDictKeyNullKey: + @staticmethod + def test_tree_to_nested_dict_key(tree_node): + expected = { + "a": { + "b": { + "d": {}, + "e": { + "g": {}, + "h": {}, + }, + }, + "c": {"f": {}}, + } + } + actual = export.tree_to_nested_dict_key(tree_node, child_key=None) + assert actual == expected, f"Expected\n{expected}\nReceived\n{actual}" + + @staticmethod + def test_tree_to_nested_dict_key_empty(): + root = node.Node("a") + expected = {"a": {}} + actual = export.tree_to_nested_dict_key(root, child_key=None) + assert actual == expected, f"Expected\n{expected}\nReceived\n{actual}" + + @staticmethod + def test_tree_to_nested_dict_key_attr_dict_error(tree_node): + with pytest.raises(ValueError) as exc_info: + export.tree_to_nested_dict_key( + tree_node, child_key=None, attr_dict={"age": "AGE"} + ) + assert str(exc_info.value) == Constants.ERROR_NODE_EXPORT_DICT_NO_ATTRS + + @staticmethod + def test_tree_to_nested_dict_key_all_attr_error(tree_node): + with pytest.raises(ValueError) as exc_info: + export.tree_to_nested_dict_key(tree_node, child_key=None, all_attrs=True) + assert str(exc_info.value) == Constants.ERROR_NODE_EXPORT_DICT_NO_ATTRS + + @staticmethod + def test_tree_to_nested_dict_key_max_depth(tree_node): + expected = {"a": {"b": {}, "c": {}}} + actual = export.tree_to_nested_dict_key(tree_node, child_key=None, max_depth=2) + assert actual == expected, f"Expected\n{expected}\nReceived\n{actual}" + + @staticmethod + def test_tree_to_nested_dict_key_to_tree(tree_node): + from bigtree.tree.construct import nested_dict_key_to_tree + + d = export.tree_to_nested_dict_key(tree_node, child_key=None) + tree = nested_dict_key_to_tree(d, child_key=None) + assert_tree_structure_basenode_root(tree) + assert_tree_structure_node_root(tree) From 44529796fc81d64a35b54b5dc65adf72dff5d52f Mon Sep 17 00:00:00 2001 From: Kay Date: Thu, 23 Oct 2025 00:08:14 +0800 Subject: [PATCH 3/4] bump: v1.0.2 --- CHANGELOG.md | 5 ++++- bigtree/__init__.py | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6c9e4ef9..c3a4a87d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). ## [Unreleased] + +## [1.0.2] - 2025-10-23 ### Added: - Test: Fix code coverage. ### Changed: @@ -849,7 +851,8 @@ ignore null attribute columns. - Utility Iterator: Tree traversal methods. - Workflow To Do App: Tree use case with to-do list implementation. -[Unreleased]: https://github.com/kayjan/bigtree/compare/1.0.1...HEAD +[Unreleased]: https://github.com/kayjan/bigtree/compare/1.0.2...HEAD +[1.0.2]: https://github.com/kayjan/bigtree/compare/1.0.1...1.0.2 [1.0.1]: https://github.com/kayjan/bigtree/compare/1.0.0...1.0.1 [1.0.0]: https://github.com/kayjan/bigtree/compare/0.31.2...1.0.0 [0.31.2]: https://github.com/kayjan/bigtree/compare/0.31.1...0.31.2 diff --git a/bigtree/__init__.py b/bigtree/__init__.py index 5b5dde34..dee74eef 100644 --- a/bigtree/__init__.py +++ b/bigtree/__init__.py @@ -1,4 +1,4 @@ -__version__ = "1.0.1" +__version__ = "1.0.2" from bigtree.binarytree.binarytree import BinaryTree from bigtree.binarytree.construct import list_to_binarytree From 5f5375bce8f6aaae88463453036b7e864695af55 Mon Sep 17 00:00:00 2001 From: Kay Date: Thu, 23 Oct 2025 00:44:09 +0800 Subject: [PATCH 4/4] feat: optional checks toggle after import --- CHANGELOG.md | 3 ++ bigtree/__init__.py | 1 + bigtree/globals.py | 4 ++- bigtree/node/basenode.py | 4 +-- bigtree/node/binarynode.py | 4 +-- bigtree/node/dagnode.py | 4 +-- bigtree/node/node.py | 6 ++-- docs/others/remove_checks.md | 7 ++++ tests/node/test_basenode_no_assertions.py | 2 +- tests/node/test_binarynode_no_assertions.py | 2 +- tests/node/test_dagnode_no_assertions.py | 2 +- tests/node/test_node.py | 2 +- tests/node/test_node_benchmark.py | 37 ++++++++++++++++++--- 13 files changed, 60 insertions(+), 18 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c3a4a87d..9a722b03 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,9 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). ## [Unreleased] +### Added: +- Optional checks: Able to toggle for optional checks after importing bigtree. Previously, you can only set the +environment variables before import. ## [1.0.2] - 2025-10-23 ### Added: diff --git a/bigtree/__init__.py b/bigtree/__init__.py index dee74eef..e6d6cbc6 100644 --- a/bigtree/__init__.py +++ b/bigtree/__init__.py @@ -6,6 +6,7 @@ from bigtree.dag.dag import DAG from bigtree.dag.export import dag_to_dataframe, dag_to_dict, dag_to_dot, dag_to_list from bigtree.dag.parsing import get_path_dag +from bigtree.globals import ASSERTIONS from bigtree.node.basenode import BaseNode from bigtree.node.binarynode import BinaryNode from bigtree.node.dagnode import DAGNode diff --git a/bigtree/globals.py b/bigtree/globals.py index 52e79771..26b5fb64 100644 --- a/bigtree/globals.py +++ b/bigtree/globals.py @@ -1,3 +1,5 @@ import os -ASSERTIONS: bool = bool(os.environ.get("BIGTREE_CONF_ASSERTIONS", True)) + +class ASSERTIONS: + FLAG: bool = bool(os.environ.get("BIGTREE_CONF_ASSERTIONS", True)) diff --git a/bigtree/node/basenode.py b/bigtree/node/basenode.py index 6af8f728..f9262522 100644 --- a/bigtree/node/basenode.py +++ b/bigtree/node/basenode.py @@ -192,7 +192,7 @@ def parent(self: T, new_parent: T) -> None: Args: new_parent: parent node """ - if ASSERTIONS: + if ASSERTIONS.FLAG: self.__check_parent_type(new_parent) self.__check_parent_loop(new_parent) @@ -335,7 +335,7 @@ def children(self: T, new_children: list[T] | tuple[T] | set[T]) -> None: Args: new_children: child node """ - if ASSERTIONS: + if ASSERTIONS.FLAG: self.__check_children_type(new_children) self.__check_children_loop(new_children) new_children = list(new_children) diff --git a/bigtree/node/binarynode.py b/bigtree/node/binarynode.py index 1fc6d574..89e856ea 100644 --- a/bigtree/node/binarynode.py +++ b/bigtree/node/binarynode.py @@ -166,7 +166,7 @@ def parent(self: T, new_parent: T | None) -> None: Args: new_parent: parent node """ - if ASSERTIONS: + if ASSERTIONS.FLAG: self.__check_parent_type(new_parent) self._BaseNode__check_parent_loop(new_parent) # type: ignore @@ -296,7 +296,7 @@ def children(self: T, _new_children: list[T | None]) -> None: """ self._BaseNode__check_children_type(_new_children) # type: ignore new_children = self.__check_children_type(_new_children) - if ASSERTIONS: + if ASSERTIONS.FLAG: self.__check_children_loop(new_children) current_new_children = { diff --git a/bigtree/node/dagnode.py b/bigtree/node/dagnode.py index ede174b8..a64f3f65 100644 --- a/bigtree/node/dagnode.py +++ b/bigtree/node/dagnode.py @@ -212,7 +212,7 @@ def parents(self: T, new_parents: list[T]) -> None: Args: new_parents: parent nodes """ - if ASSERTIONS: + if ASSERTIONS.FLAG: self.__check_parent_type(new_parents) self.__check_parent_loop(new_parents) @@ -311,7 +311,7 @@ def children(self: T, new_children: Iterable[T]) -> None: Args: new_children: child node """ - if ASSERTIONS: + if ASSERTIONS.FLAG: self.__check_children_type(new_children) self.__check_children_loop(new_children) diff --git a/bigtree/node/node.py b/bigtree/node/node.py index bbd473bb..ece0cb43 100644 --- a/bigtree/node/node.py +++ b/bigtree/node/node.py @@ -84,7 +84,7 @@ def __init__(self, name: str, sep: str = "/", **kwargs: Any): self.name = name self._sep = sep super().__init__(**kwargs) - if ASSERTIONS and not self.node_name: + if ASSERTIONS.FLAG and not self.node_name: raise exceptions.TreeError("Node must have a `name` attribute") @property @@ -133,7 +133,7 @@ def _BaseNode__pre_assign_parent(self: T, new_parent: T) -> None: Args: new_parent: new parent to be added """ - if ASSERTIONS and new_parent is not None: + if ASSERTIONS.FLAG and new_parent is not None: if any( child.node_name == self.node_name and child is not self for child in new_parent.children @@ -149,7 +149,7 @@ def _BaseNode__pre_assign_children(self: T, new_children: list[T]) -> None: Args: new_children: new children to be added """ - if ASSERTIONS: + if ASSERTIONS.FLAG: children_names = [node.node_name for node in new_children] duplicate_names = [ item[0] for item in Counter(children_names).items() if item[1] > 1 diff --git a/docs/others/remove_checks.md b/docs/others/remove_checks.md index 3636c38c..99ee9acc 100644 --- a/docs/others/remove_checks.md +++ b/docs/others/remove_checks.md @@ -27,3 +27,10 @@ os.environ["BIGTREE_CONF_ASSERTIONS"] = "" import bigtree ``` + +Alternatively, if you have already imported bigtree, you can set the configuration manually. + +```python +import bigtree +bigtree.ASSERTIONS.FLAG = False +``` diff --git a/tests/node/test_basenode_no_assertions.py b/tests/node/test_basenode_no_assertions.py index c701b4df..1dff2fc6 100644 --- a/tests/node/test_basenode_no_assertions.py +++ b/tests/node/test_basenode_no_assertions.py @@ -6,7 +6,7 @@ from bigtree.node import basenode -@patch("bigtree.node.basenode.ASSERTIONS", "") +@patch("bigtree.node.basenode.ASSERTIONS.FLAG", "") class TestBaseNodeNoAssertions(unittest.TestCase): def setUp(self): """ diff --git a/tests/node/test_binarynode_no_assertions.py b/tests/node/test_binarynode_no_assertions.py index 80efc405..357b3015 100644 --- a/tests/node/test_binarynode_no_assertions.py +++ b/tests/node/test_binarynode_no_assertions.py @@ -7,7 +7,7 @@ from bigtree.utils.exceptions import TreeError -@patch("bigtree.node.binarynode.ASSERTIONS", "") +@patch("bigtree.node.binarynode.ASSERTIONS.FLAG", "") class TestBinaryNodeNoAssertions(unittest.TestCase): def setUp(self): self.a = binarynode.BinaryNode(1) diff --git a/tests/node/test_dagnode_no_assertions.py b/tests/node/test_dagnode_no_assertions.py index dca2c4d0..53adaeaf 100644 --- a/tests/node/test_dagnode_no_assertions.py +++ b/tests/node/test_dagnode_no_assertions.py @@ -6,7 +6,7 @@ from bigtree.node import basenode, dagnode, node -@patch("bigtree.node.dagnode.ASSERTIONS", "") +@patch("bigtree.node.dagnode.ASSERTIONS.FLAG", "") class TestDAGNodeNoAssertions(unittest.TestCase): def setUp(self): """ diff --git a/tests/node/test_node.py b/tests/node/test_node.py index 14605a46..c4a9eb37 100644 --- a/tests/node/test_node.py +++ b/tests/node/test_node.py @@ -182,7 +182,7 @@ def test_set_children_sep_different_error(self): path=path ) - @patch("bigtree.node.node.ASSERTIONS", "") + @patch("bigtree.node.node.ASSERTIONS.FLAG", "") def test_set_children_sep_different_no_assertion(self): b = node.Node("b", sep="\\") self.a.children = [self.b, b] diff --git a/tests/node/test_node_benchmark.py b/tests/node/test_node_benchmark.py index 431a64e5..6564a4f9 100644 --- a/tests/node/test_node_benchmark.py +++ b/tests/node/test_node_benchmark.py @@ -3,6 +3,7 @@ import pytest +import bigtree from bigtree.node import node sys.setrecursionlimit(2000) @@ -49,24 +50,52 @@ def test_node_benchmark_width_2_depth_10(benchmark): @pytest.mark.benchmark(group="width_1_depth_10") -@patch("bigtree.node.basenode.ASSERTIONS", "") +@patch("bigtree.node.basenode.ASSERTIONS.FLAG", "") def test_node_benchmark_width_1_depth_10_no_assertions(benchmark): benchmark.pedantic(run_construct_node, (10, 1), iterations=10, rounds=2) +@pytest.mark.benchmark(group="width_1_depth_10") +def test_node_benchmark_width_1_depth_10_no_assertions_config(benchmark): + bigtree.ASSERTIONS.FLAG = False + benchmark.pedantic(run_construct_node, (10, 1), iterations=10, rounds=2) + bigtree.ASSERTIONS.FLAG = True + + @pytest.mark.benchmark(group="width_1_depth_100") -@patch("bigtree.node.basenode.ASSERTIONS", "") +@patch("bigtree.node.basenode.ASSERTIONS.FLAG", "") def test_node_benchmark_width_1_depth_100_no_assertions(benchmark): benchmark.pedantic(run_construct_node, (100, 1), iterations=10, rounds=2) +@pytest.mark.benchmark(group="width_1_depth_100") +def test_node_benchmark_width_1_depth_100_no_assertions_config(benchmark): + bigtree.ASSERTIONS.FLAG = False + benchmark.pedantic(run_construct_node, (100, 1), iterations=10, rounds=2) + bigtree.ASSERTIONS.FLAG = True + + @pytest.mark.benchmark(group="width_1_depth_1000") -@patch("bigtree.node.basenode.ASSERTIONS", "") +@patch("bigtree.node.basenode.ASSERTIONS.FLAG", "") def test_node_benchmark_width_1_depth_1000_no_assertions(benchmark): benchmark.pedantic(run_construct_node, (1000, 1), iterations=10, rounds=2) +@pytest.mark.benchmark(group="width_1_depth_1000") +def test_node_benchmark_width_1_depth_1000_no_assertions_config(benchmark): + bigtree.ASSERTIONS.FLAG = False + benchmark.pedantic(run_construct_node, (1000, 1), iterations=10, rounds=2) + bigtree.ASSERTIONS.FLAG = True + + @pytest.mark.benchmark(group="width_2_depth_10") -@patch("bigtree.node.basenode.ASSERTIONS", "") +@patch("bigtree.node.basenode.ASSERTIONS.FLAG", "") def test_node_benchmark_width_2_depth_10_no_assertions(benchmark): benchmark.pedantic(run_construct_node, (10, 2), iterations=10, rounds=2) + + +@pytest.mark.benchmark(group="width_2_depth_10") +def test_node_benchmark_width_2_depth_10_no_assertions_config(benchmark): + bigtree.ASSERTIONS.FLAG = False + benchmark.pedantic(run_construct_node, (10, 2), iterations=10, rounds=2) + bigtree.ASSERTIONS.FLAG = True