From 11d6508476ccc50a2ca2e5bb20ef4de3a054e0a1 Mon Sep 17 00:00:00 2001 From: Massimo Fabbro Date: Mon, 16 Mar 2026 17:17:58 +0100 Subject: [PATCH] Add tests for cost tool --- src/bonsai/test/tool/test_cost.py | 49 +++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 src/bonsai/test/tool/test_cost.py diff --git a/src/bonsai/test/tool/test_cost.py b/src/bonsai/test/tool/test_cost.py new file mode 100644 index 0000000000..3cfbe03c91 --- /dev/null +++ b/src/bonsai/test/tool/test_cost.py @@ -0,0 +1,49 @@ +# Bonsai - OpenBIM Blender Add-on +# Copyright (C) 2021 Dion Moult +# +# This file is part of Bonsai. +# +# Bonsai is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Bonsai is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with Bonsai. If not, see . + + +import test.bim.bootstrap +import ifcopenshell.api.cost + +import bonsai.core.tool +import bonsai.tool as tool +import test.bim.bootstrap +from test.bim.bootstrap import NewFile + +from bonsai.tool.cost import Cost as subject + +class TestImplementsTool(NewFile): + def test_run(self): + assert isinstance(subject(), bonsai.core.tool.Cost) + +class TestDisableEditingCostItemParent(NewFile): + def test_avoid_recursion_error(newfile, monkeypatch): + class DummyProps: + def __init__(self): + self.change_cost_item_parent = None + self.active_cost_item_id = 5 + + props = DummyProps() + monkeypatch.setattr( + "bonsai.tool.Cost.get_cost_props", + lambda: props + ) + subject.disable_editing_cost_item_parent() + assert props.active_cost_item_id == 0 + assert props.change_cost_item_parent is not False +