Coverage for tests / base / test_register.py: 100%
27 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.base.registers import (
30 RegisterError,
31 check_key_value_type,
32 register,
33)
35KEY_A = "key_a"
36KEY_B = "key_b"
37VALUE_A = "value_a"
38VALUE_B = "value_a"
41def test_register():
42 test_register = {}
43 register(test_register, KEY_A, VALUE_A)
44 assert KEY_A in test_register
45 assert VALUE_A in test_register
48def test_already_registered_exception():
49 test_register = {KEY_A: VALUE_A, VALUE_A: KEY_A}
51 message = str.format("{0}: {1} key or value is already registered.", KEY_A, VALUE_B)
52 with pytest.raises(RegisterError, match=message):
53 register(test_register, KEY_A, VALUE_B)
55 message = str.format("{0}: {1} key or value is already registered.", KEY_B, VALUE_A)
56 with pytest.raises(RegisterError, match=message):
57 register(test_register, KEY_B, VALUE_A)
60def test_check_key_value_type_exception():
61 check_key_value_type(KEY_A, str, VALUE_A, str)
62 message = str.format(
63 "Expected type for key is {0} but got {1}.", str.__name__, float.__name__
64 )
65 with pytest.raises(TypeError, match=message):
66 check_key_value_type(0.0, str, 0.0, str)
68 message = str.format(
69 "Expected type for value is {0} but got {1}.", str.__name__, float.__name__
70 )
71 with pytest.raises(TypeError, match=message):
72 check_key_value_type(KEY_A, str, 0.0, str)