Coverage for tests / tests_description / test_relations.py: 100%
67 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/>.
27from unittest.mock import patch
29import pytest
31from physioblocks.description.flux import (
32 Dof,
33 FluxDofTypesRegister,
34 get_flux_dof_register,
35)
37FLUX_TYPE_ID = "flux"
38DOF_TYPE_ID = "potential"
40FLUX_TYPE_A = "flux_a"
41DOF_TYPE_A = "potential_a"
43FLUX_TYPE_B = "flux_b"
44DOF_TYPE_B = "potential_b"
47@pytest.fixture
48def register() -> FluxDofTypesRegister:
49 return get_flux_dof_register()
52class TestFluxDofCouple:
53 def test_register(self, register: FluxDofTypesRegister):
54 register.register_flux_dof_couple(FLUX_TYPE_ID, DOF_TYPE_ID)
55 assert DOF_TYPE_ID in register.dof_flux_couples
56 assert FLUX_TYPE_ID in register.flux_dof_couples
58 with pytest.raises(ValueError):
59 register.register_flux_dof_couple(FLUX_TYPE_ID, "unregistered")
61 with pytest.raises(ValueError):
62 register.register_flux_dof_couple("unregistered", FLUX_TYPE_ID)
64 with pytest.raises(ValueError):
65 register.register_flux_dof_couple(DOF_TYPE_ID, "unregistered")
67 with pytest.raises(ValueError):
68 register.register_flux_dof_couple("unregistered", DOF_TYPE_ID)
70 assert "unregistered" not in register.dof_flux_couples
71 assert "unregistered" not in register.flux_dof_couples
73 assert FLUX_TYPE_ID not in register.dof_flux_couples
74 assert DOF_TYPE_ID not in register.flux_dof_couples
76 register.unregister_flux_dof_couple(FLUX_TYPE_ID)
78 def test_get_matching_type(self, register: FluxDofTypesRegister):
79 with patch.multiple(
80 register,
81 _fluxes_types={FLUX_TYPE_ID: DOF_TYPE_ID},
82 _dof_types={DOF_TYPE_ID: FLUX_TYPE_ID},
83 ):
84 assert register.flux_dof_couples[FLUX_TYPE_ID] == DOF_TYPE_ID
85 assert register.dof_flux_couples[DOF_TYPE_ID] == FLUX_TYPE_ID
87 def test_unregister(self, register: FluxDofTypesRegister):
88 register.register_flux_dof_couple(FLUX_TYPE_ID, DOF_TYPE_ID)
89 register.unregister_flux_dof_couple(FLUX_TYPE_ID)
90 with pytest.raises(KeyError):
91 register.flux_dof_couples[FLUX_TYPE_ID]
93 register.register_flux_dof_couple(FLUX_TYPE_ID, DOF_TYPE_ID)
94 register.unregister_flux_dof_couple(DOF_TYPE_ID)
95 with pytest.raises(KeyError):
96 register.dof_flux_couples[DOF_TYPE_ID]
98 with pytest.raises(ValueError):
99 register.unregister_flux_dof_couple(FLUX_TYPE_ID)
101 with pytest.raises(ValueError):
102 register.unregister_flux_dof_couple(DOF_TYPE_ID)
105class TestDof:
106 def test_constructor(self):
107 dof = Dof("dof_a", DOF_TYPE_ID)
108 assert dof.dof_id == "dof_a"
109 assert dof.dof_type == DOF_TYPE_ID
111 def test_eq(self):
112 dof_1 = Dof("dof_a", DOF_TYPE_A)
113 dof_2 = Dof("dof_a", DOF_TYPE_A)
114 dof_3 = Dof("dof_a", DOF_TYPE_B)
115 dof_4 = Dof("dof_b", DOF_TYPE_A)
116 dof_5 = Dof("dof_b", DOF_TYPE_B)
118 dof_id_1 = "dof_a"
119 dof_id_2 = "dof_b"
121 assert dof_1 == dof_2
122 assert dof_1 == dof_3
123 assert dof_1 != dof_4
124 assert dof_1 != dof_5
125 assert dof_1 == dof_id_1
126 assert dof_1 != dof_id_2
127 assert dof_1 != 1