]> git.proxmox.com Git - ceph.git/blame - ceph/src/pybind/mgr/cephadm/tests/test_completion.py
Import ceph 15.2.8
[ceph.git] / ceph / src / pybind / mgr / cephadm / tests / test_completion.py
CommitLineData
9f95a23c
TL
1import sys
2import time
3
4
5try:
6 from typing import Any
7except ImportError:
8 pass
9
10import pytest
11
12
13from tests import mock
14from .fixtures import cephadm_module, wait
e306af50 15from ..module import trivial_completion, forall_hosts
9f95a23c
TL
16
17
18class TestCompletion(object):
19
20 def test_trivial(self, cephadm_module):
21 @trivial_completion
22 def run(x):
23 return x+1
24 assert wait(cephadm_module, run(1)) == 2
25
e306af50
TL
26 def test_exception(self, cephadm_module):
27 @trivial_completion
28 def run(x):
29 raise ValueError
30 c = run(1)
31 with pytest.raises(ValueError):
32 wait(cephadm_module, c)
9f95a23c
TL
33
34 @pytest.mark.parametrize("input,expected", [
35 ([], []),
36 ([1], ["(1,)"]),
37 (["hallo"], ["('hallo',)"]),
38 ("hi", ["('h',)", "('i',)"]),
39 (list(range(5)), [str((x, )) for x in range(5)]),
40 ([(1, 2), (3, 4)], ["(1, 2)", "(3, 4)"]),
41 ])
42 def test_async_map(self, input, expected, cephadm_module):
e306af50
TL
43 @forall_hosts
44 def run_forall(*args):
9f95a23c 45 return str(args)
e306af50 46 assert run_forall(input) == expected
9f95a23c 47
9f95a23c
TL
48 @pytest.mark.parametrize("input,expected", [
49 ([], []),
50 ([1], ["(1,)"]),
51 (["hallo"], ["('hallo',)"]),
52 ("hi", ["('h',)", "('i',)"]),
53 (list(range(5)), [str((x, )) for x in range(5)]),
54 ([(1, 2), (3, 4)], ["(1, 2)", "(3, 4)"]),
55 ])
56 def test_async_map_self(self, input, expected, cephadm_module):
57 class Run(object):
58 def __init__(self):
59 self.attr = 1
60
e306af50
TL
61 @forall_hosts
62 def run_forall(self, *args):
9f95a23c
TL
63 assert self.attr == 1
64 return str(args)
65
e306af50 66 assert Run().run_forall(input) == expected