| 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 |
from textwrap import dedent |
| 18 |
|
| 19 |
from ansimarkup import parse as cparse |
| 20 |
import pytest |
| 21 |
|
| 22 |
from cylc.flow.scripts.reinstall import format_reinstall_output |
| 23 |
from cylc.flow.terminal import DIM |
| 24 |
|
| 25 |
|
| 26 |
@pytest.mark.parametrize('verbose', [True, False]) |
| 27 |
def test_format_reinstall_output(verbose, monkeypatch: pytest.MonkeyPatch): |
| 28 |
"""It should: |
| 29 |
- colorize the output |
| 30 |
- remove the itemized changes summary if not in verbose mode |
| 31 |
- remove the "cannot delete non-empty directory" message |
| 32 |
""" |
| 33 |
output = dedent(""" |
| 34 |
*deleting del. Cloud.jpg |
| 35 |
>f+++++++++ send cloud.jpg |
| 36 |
.f...p..... send foo |
| 37 |
>fcsTp..... send bar |
| 38 |
cannot delete non-empty directory: scarf |
| 39 |
>f+++++++++ send meow.txt |
| 40 |
cL+++++++++ send garage -> foo |
| 41 |
""").strip() |
| 42 |
expected = [ |
| 43 |
f"<{DIM}>*deleting </{DIM}> <red>del. Cloud.jpg</red>", |
| 44 |
f"<{DIM}>>f+++++++++</{DIM}> <green>send cloud.jpg</green>", |
| 45 |
f"<{DIM}>.f...p.....</{DIM}> <green>send foo</green>", |
| 46 |
f"<{DIM}>>fcsTp.....</{DIM}> <green>send bar</green>", |
| 47 |
f"<{DIM}>>f+++++++++</{DIM}> <green>send meow.txt</green>", |
| 48 |
f"<{DIM}>cL+++++++++</{DIM}> <green>send garage -> foo</green>", |
| 49 |
] |
| 50 |
if verbose: |
| 51 |
monkeypatch.setattr('cylc.flow.flags.verbosity', 1) |
| 52 |
else: |
| 53 |
# itemized changes summary should not be in output |
| 54 |
shift = len(f'<{DIM}></{DIM}> ') + 11 |
| 55 |
expected = [i[shift:] for i in expected] |
| 56 |
assert format_reinstall_output(output) == [cparse(i) for i in expected] |