Coverage for tests / tests_library / tests_functions / test_watch_functions.py: 100%

18 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 Mock, patch 

28 

29import pytest 

30 

31from physioblocks.computing.quantities import Quantity 

32from physioblocks.library.functions.watchers import SumBlocksQuantity, WatchQuantity 

33 

34 

35@pytest.fixture 

36def scalar_qty() -> Quantity: 

37 return Quantity(0.1) 

38 

39 

40def test_eval_watch_quantity(scalar_qty: Quantity): 

41 func = WatchQuantity(scalar_qty) 

42 assert func.eval() == pytest.approx(0.1) 

43 

44 

45@patch("physioblocks.computing.quantities.Quantity") 

46@patch("physioblocks.description.blocks.Block") 

47def test_eval_sum_blocks_quantity(mock_block: Mock, mock_qty: Mock): 

48 mock_qty.current = 0.1 

49 mock_block.scalar = mock_qty 

50 

51 block_list = [mock_block, mock_block, mock_block] 

52 func = SumBlocksQuantity("scalar", block_list) 

53 assert func.eval() == pytest.approx(0.3)