Coverage for tests / tests_io / test_aliases.py: 100%
28 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 pathlib import Path
28from unittest.mock import Mock, patch
30import pytest
32from physioblocks.io.aliases import load_aliases
35@patch("physioblocks.io.aliases.add_alias")
36@patch("physioblocks.io.aliases.read_json")
37@patch("pathlib.Path.iterdir")
38@patch("pathlib.Path.exists")
39@patch("pathlib.Path.is_dir")
40def test_load_aliases(
41 mock_path_is_dir: Mock,
42 mock_path_exists: Mock,
43 mock_iter_dir: Mock,
44 mock_read_json: Mock,
45 mock_add_alias: Mock,
46):
47 mock_path_is_dir.side_effect = [True, True, True, False]
48 mock_path_exists.return_value = True
49 mock_iter_dir.side_effect = [[Path(), Path("alias.json")], []]
50 mock_read_json.return_value = True
52 load_aliases("")
53 mock_add_alias.assert_called_once_with("alias", True)
56@patch("pathlib.Path.exists")
57@patch("pathlib.Path.is_dir")
58def test_load_aliases_exceptions(mock_path_is_dir: Mock, mock_path_exists: Mock):
59 # path does not described a directory
60 mock_path_is_dir.return_value = False
61 err_msg = "Provided alias directory is not a folder: "
62 with pytest.raises(OSError, match=err_msg):
63 load_aliases("")
65 # path does not exists
66 mock_path_is_dir.return_value = True
67 mock_path_exists.return_value = False
68 err_msg = "Provided alias directory do not exist: "
69 with pytest.raises(OSError, match=err_msg):
70 load_aliases("")