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

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/>. 

26 

27from unittest.mock import patch 

28 

29import pytest 

30 

31from physioblocks.description.flux import ( 

32 Dof, 

33 FluxDofTypesRegister, 

34 get_flux_dof_register, 

35) 

36 

37FLUX_TYPE_ID = "flux" 

38DOF_TYPE_ID = "potential" 

39 

40FLUX_TYPE_A = "flux_a" 

41DOF_TYPE_A = "potential_a" 

42 

43FLUX_TYPE_B = "flux_b" 

44DOF_TYPE_B = "potential_b" 

45 

46 

47@pytest.fixture 

48def register() -> FluxDofTypesRegister: 

49 return get_flux_dof_register() 

50 

51 

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 

57 

58 with pytest.raises(ValueError): 

59 register.register_flux_dof_couple(FLUX_TYPE_ID, "unregistered") 

60 

61 with pytest.raises(ValueError): 

62 register.register_flux_dof_couple("unregistered", FLUX_TYPE_ID) 

63 

64 with pytest.raises(ValueError): 

65 register.register_flux_dof_couple(DOF_TYPE_ID, "unregistered") 

66 

67 with pytest.raises(ValueError): 

68 register.register_flux_dof_couple("unregistered", DOF_TYPE_ID) 

69 

70 assert "unregistered" not in register.dof_flux_couples 

71 assert "unregistered" not in register.flux_dof_couples 

72 

73 assert FLUX_TYPE_ID not in register.dof_flux_couples 

74 assert DOF_TYPE_ID not in register.flux_dof_couples 

75 

76 register.unregister_flux_dof_couple(FLUX_TYPE_ID) 

77 

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 

86 

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] 

92 

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] 

97 

98 with pytest.raises(ValueError): 

99 register.unregister_flux_dof_couple(FLUX_TYPE_ID) 

100 

101 with pytest.raises(ValueError): 

102 register.unregister_flux_dof_couple(DOF_TYPE_ID) 

103 

104 

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 

110 

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) 

117 

118 dof_id_1 = "dof_a" 

119 dof_id_2 = "dof_b" 

120 

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