Coverage for tests / tests_registers / test_save_register.py: 95%

22 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 

31import physioblocks.registers.save_function_register as save_reg 

32from physioblocks.registers.save_function_register import ( 

33 get_save_function, 

34 has_save_function, 

35 saves, 

36) 

37 

38 

39class ClassA: 

40 pass 

41 

42 

43class ClassB(ClassA): 

44 pass 

45 

46 

47@patch( 

48 "physioblocks.registers.type_register.__type_register", 

49 new={ 

50 ClassA.__name__: ClassA, 

51 ClassA: ClassA.__name__, 

52 ClassB.__name__: ClassB, 

53 ClassB: ClassB.__name__, 

54 }, 

55) 

56def test_save_function_register(): 

57 @saves(ClassA) 

58 def save_func(): 

59 pass 

60 

61 assert has_save_function(ClassA) is True 

62 assert has_save_function(ClassB) is True 

63 assert get_save_function(ClassA) == save_func 

64 assert get_save_function(ClassB) == save_func 

65 

66 

67@patch.object( 

68 save_reg, 

69 attribute="__save_functions_register", 

70 new={}, 

71) 

72def test_save_function_exceptions(): 

73 err_msg = str.format("No save function registered for type {0}", ClassA.__name__) 

74 with pytest.raises(KeyError, match=err_msg): 

75 get_save_function(ClassA)