| 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 ast |
| 19 |
from unittest.mock import Mock |
| 20 |
|
| 21 |
import pytest |
| 22 |
import urwid |
| 23 |
|
| 24 |
from cylc.flow.tui.app import BINDINGS |
| 25 |
import cylc.flow.tui.overlay |
| 26 |
from cylc.flow.workflow_status import WorkflowStatus |
| 27 |
|
| 28 |
|
| 29 |
@pytest.fixture |
| 30 |
def overlay_functions(): |
| 31 |
"""List overlay all generator functions in cylc.flow.tui.overlay |
| 32 |
|
| 33 |
Uses ast to parse functions out of the module. |
| 34 |
|
| 35 |
""" |
| 36 |
filepath = cylc.flow.tui.overlay.__file__ |
| 37 |
with open(filepath, 'r') as source_file: |
| 38 |
tree = ast.parse(source_file.read(), filename=filepath) |
| 39 |
|
| 40 |
return [ |
| 41 |
getattr(cylc.flow.tui.overlay, obj.name) |
| 42 |
for obj in tree.body |
| 43 |
if isinstance(obj, ast.FunctionDef) |
| 44 |
and not obj.name.startswith('_') |
| 45 |
] |
| 46 |
|
| 47 |
|
| 48 |
def test_interface(overlay_functions): |
| 49 |
"""Ensure all overlay functions have the correct signature.""" |
| 50 |
for function in overlay_functions: |
| 51 |
# mock up an app object to keep things working |
| 52 |
app = Mock( |
| 53 |
filters={'tasks': {}, 'workflows': {'id': '.*'}}, |
| 54 |
bindings=BINDINGS, |
| 55 |
tree_walker=Mock( |
| 56 |
get_focus=Mock( |
| 57 |
return_value=[ |
| 58 |
Mock( |
| 59 |
get_node=Mock( |
| 60 |
return_value=Mock( |
| 61 |
get_value=lambda: { |
| 62 |
'id_': '~u/a', |
| 63 |
'type_': 'workflow', |
| 64 |
'data': { |
| 65 |
'status': |
| 66 |
WorkflowStatus.RUNNING.value, |
| 67 |
}, |
| 68 |
} |
| 69 |
) |
| 70 |
) |
| 71 |
) |
| 72 |
] |
| 73 |
) |
| 74 |
) |
| 75 |
) |
| 76 |
|
| 77 |
widget, options = function(app) |
| 78 |
|
| 79 |
assert isinstance(widget, urwid.Widget) |
| 80 |
assert isinstance(options, dict) |
| 81 |
assert 'width' in options |
| 82 |
assert 'height' in options |