Coverage for tests / tests_description / test_blocks.py: 100%
45 statements
« prev ^ index » next coverage.py v7.13.1, created at 2026-01-09 16:40 +0100
« prev ^ index » next coverage.py v7.13.1, created at 2026-01-09 16:40 +0100
1# SPDX-FileCopyrightText: Copyright INRIA
2#
3# SPDX-License-Identifier: LGPL-3.0-only
4#
5# Copyright INRIA
6#
7# This file is part of PhysioBlocks, a library mostly developed by the
8# [Ananke project-team](https://team.inria.fr/ananke) at INRIA.
9#
10# Authors:
11# - Colin Drieu
12# - Dominique Chapelle
13# - François Kimmig
14# - Philippe Moireau
15#
16# PhysioBlocks is free software: you can redistribute it and/or modify it under the
17# terms of the GNU Lesser General Public License as published by the Free Software
18# Foundation, version 3 of the License.
19#
20# PhysioBlocks is distributed in the hope that it will be useful, but WITHOUT ANY
21# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
22# PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
23#
24# You should have received a copy of the GNU Lesser General Public License along with
25# PhysioBlocks. If not, see <https://www.gnu.org/licenses/>.
27import pytest
29from physioblocks.computing.models import ModelComponent
30from physioblocks.description.blocks import (
31 ID_SEPARATOR,
32 Block,
33 BlockDescription,
34 ModelComponentDescription,
35)
37BLOCK_ID = "block"
38MODEL_ID = "model"
40FLUX_TYPE = "flux_type"
41DOF_TYPE = "dof_type"
42DOF_ID = "dof_id"
44FLUX_TYPE_A = "flux_type_a"
45DOF_TYPE_A = "dof_type_a"
46FLUX_TYPE_B = "flux_type_b"
47DOF_TYPE_B = "dof_type_b"
50class TestBlockDescription:
51 def test_constructor(self):
52 block_desc = BlockDescription(BLOCK_ID, Block, FLUX_TYPE)
54 assert block_desc.name == BLOCK_ID
55 assert block_desc.described_type == Block
56 assert block_desc.flux_type == FLUX_TYPE
57 assert block_desc.global_ids == {}
58 assert block_desc.submodels == {}
60 with pytest.raises(AttributeError):
61 block_desc.name = ""
63 with pytest.raises(AttributeError):
64 block_desc.described_type = None
66 with pytest.raises(AttributeError):
67 block_desc.global_ids = None
69 with pytest.raises(AttributeError):
70 block_desc.flux_type = ""
72 block_desc.global_ids["a"] = "b"
73 assert block_desc.global_ids == {}
75 with pytest.raises(AttributeError):
76 block_desc.submodels = ""
78 block_desc.submodels["a"] = "b"
79 assert block_desc.submodels == {}
81 # test too many attributes:
82 error_msg = str.format("{0} has no attribute named {1}.", "Block", "attr")
83 with pytest.raises(AttributeError, match=error_msg):
84 block_desc = BlockDescription(
85 BLOCK_ID, Block, FLUX_TYPE, {"attr": "error_attr"}
86 )
88 def test_add_remove_submodels(self):
89 block_desc = BlockDescription(BLOCK_ID, Block, FLUX_TYPE)
91 model = ModelComponentDescription(MODEL_ID, ModelComponent)
92 submodel = block_desc.add_submodel(MODEL_ID, model)
94 assert block_desc.submodels[MODEL_ID] == submodel
95 assert submodel.name == ID_SEPARATOR.join([BLOCK_ID, MODEL_ID])
97 block_desc.remove_submodel(MODEL_ID)
98 assert block_desc.submodels == {}