Debian Codegraph @

tests/i/test_id_cli.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 """Some integration tests running on live workflows to test filtering properly.
18 """
19
20 import pytest
21
22 from cylc.flow.pathutil import get_cylc_run_dir
23 from cylc.flow.id_cli import parse_ids_async
24
25
26 @pytest.fixture(scope='module')
27 async def harness(
28 mod_run,
29 mod_scheduler,
30 mod_flow,
31 mod_one_conf,
32 mod_test_dir,
33 ):
34 """Create three workflows, two running, one stopped."""
35 reg_prefix = mod_test_dir.relative_to(get_cylc_run_dir())
36 # abc:running
37 reg1 = mod_flow(mod_one_conf, name='abc')
38 schd1 = mod_scheduler(reg1)
39 # def:running
40 reg2 = mod_flow(mod_one_conf, name='def')
41 schd2 = mod_scheduler(reg2)
42 # ghi:stopped
43 reg3 = mod_flow(mod_one_conf, name='ghi')
44 async with mod_run(schd1):
45 async with mod_run(schd2):
46 yield reg_prefix, reg1, reg2, reg3
47
48
49 async def test_glob_wildcard(harness):
50 """It should search for workflows using globs."""
51 reg_prefix, reg1, reg2, reg3 = harness
52 # '*' should return all workflows
53 workflows, _ = await parse_ids_async(
54 f'{reg_prefix / "*"}',
55 constraint='workflows',
56 match_workflows=True,
57 )
58 assert sorted(workflows) == sorted([reg1, reg2])
59 workflows, _ = await parse_ids_async(
60 f'{reg_prefix / "z*"}',
61 constraint='workflows',
62 match_workflows=True,
63 )
64 assert sorted(workflows) == sorted([])
65
66
67 async def test_glob_pattern(harness):
68 """It should support fnmatch syntax including square brackets."""
69 # [a]* should match workflows starting with "a"
70 reg_prefix, reg1, reg2, reg3 = harness
71 workflows, _ = await parse_ids_async(
72 f'{reg_prefix / "[a]*"}',
73 constraint='workflows',
74 match_workflows=True,
75 )
76 assert sorted(workflows) == sorted([reg1])
77 workflows, _ = await parse_ids_async(
78 f'{reg_prefix / "[z]*"}',
79 constraint='workflows',
80 match_workflows=True,
81 )
82 assert sorted(workflows) == sorted([])
83
84
85 async def test_state_filter(harness):
86 """It should filter by workflow state."""
87 reg_prefix, reg1, reg2, reg3 = harness
88 # '*' should return all workflows
89 workflows, _ = await parse_ids_async(
90 f'{reg_prefix / "*"}',
91 constraint='workflows',
92 match_workflows=True,
93 match_active=None,
94 )
95 assert sorted(workflows) == sorted([reg1, reg2, reg3])
96 workflows, _ = await parse_ids_async(
97 f'{reg_prefix / "*"}',
98 constraint='workflows',
99 match_workflows=True,
100 match_active=True,
101 )
102 assert sorted(workflows) == sorted([reg1, reg2])
103 workflows, _ = await parse_ids_async(
104 f'{reg_prefix / "*"}',
105 constraint='workflows',
106 match_workflows=True,
107 match_active=False,
108 )
109 assert sorted(workflows) == sorted([reg3])