Debian Codegraph @

tests/u/scripts/test_install.py

raw
1 # THIS FILE IS PART OF THE CYLC WORKFLOW ENGINE.
2 # Copyright (C) NIWA & British Crown (Met Office) & Contributors.
3 #
4 # This program is free software: you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation, either version 3 of the License, or
7 # (at your option) any later version.
8 #
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
13 #
14 # You should have received a copy of the GNU General Public License
15 # along with this program. If not, see <http://www.gnu.org/licenses/>.
16
17
18 import os.path
19 from pathlib import Path
20 from typing import Optional
21
22 import pytest
23
24 from cylc.flow.scripts.install import get_source_location
25
26
27 @pytest.mark.parametrize(
28 'path, expected',
29 [
30 pytest.param(
31 'isla/nublar', '{cylc_src}/isla/nublar',
32 id="implicit relative"
33 ),
34 pytest.param(
35 './isla/nublar', '{cwd}/isla/nublar',
36 id="explicit relative"
37 ),
38 pytest.param(
39 '/welcome/to/jurassic/park', '/welcome/to/jurassic/park',
40 id="absolute"
41 ),
42 pytest.param(
43 None, '{cwd}',
44 id="None"
45 ),
46 pytest.param(
47 '.', '{cwd}',
48 id="dot"
49 ),
50 pytest.param(
51 '$GENNARO/coupon-day', '{env_var}/coupon-day',
52 id="env var expanded"
53 ),
54 ]
55 )
56 def test_get_source_location(
57 path: Optional[str],
58 expected: str,
59 monkeypatch: pytest.MonkeyPatch
60 ):
61 # Setup
62 mock_cylc_src = '/ingen/cylc-src'
63 monkeypatch.setattr(
64 'cylc.flow.scripts.install.search_install_source_dirs',
65 lambda x: Path(mock_cylc_src, x)
66 )
67 mock_env_var = '/donald/gennaro'
68 monkeypatch.setenv('GENNARO', mock_env_var)
69 expected = expected.format(
70 cwd=Path.cwd(),
71 cylc_src=mock_cylc_src,
72 env_var=mock_env_var,
73 )
74 # Test
75 assert get_source_location(path) == Path(expected)
76 assert os.path.isabs(expected)