def test_block(): src = dedent('''\ --- - block: a''') target = api.Script(src)._search_tree() assert {k for k, v in target.items() if v} == {'block'}
def test_blank_list(): src = dedent('''\ --- - hosts - ''') script = api.Script(src) assert script.data.tree == [['hosts', None], None]
def test_single_play(): src = dedent('''\ --- - name tasks: ''') target = api.Script(src, line=1, column=6)._search_tree() assert {k for k in target if target[k]} == {'play'}
def test_second_play(): src = dedent('''\ --- - name: name tasks: - nam''') target = api.Script(src, line=1, column=6)._search_tree() assert {k for k, v in target.items() if v} == {'play'}
def test_colon_absence(): src = dedent('''\ --- - name: name hosts ''') script = api.Script(src) assert script.data == [{'name': 'name', 'hosts': None}]
def test_unhandled_error(): src = dedent('''\ --- - hosts hoge ''') with pytest.raises(ParserError): api.Script(src)
def test_unallowed_map(): src = dedent('''\ --- - name hosts: all ''') script = api.Script(src) assert script.data == [{'name': None, 'hosts': 'all'}]
def test_unquoted(): src = dedent('''\ --- - name: "hoge fuga ''') script = api.Script(src) assert script.data == [{'name': 'hoge fuga'}]
def test_common_directive_only(): src = dedent('''\ - vars: become: true - a''') target = api.Script(src, line=2, column=3)._search_tree() assert {k for k in target if target[k]} == {'play', 'block', 'task', 'module'}
def test_task_and_module_name(): src = dedent('''\ --- - m - register: registed''') script = api.Script(src, line=1, column=3) print(script.data.tree) target = script._search_tree() assert {k for k, v in target.items() if v} == {'task', 'module'}
def test_api_search_tree_block(self): src = '''--- - tasks: - block: a ''' result = api.Script(src, line=3, column=7)._search_tree() assert result['task'] is False assert result['block'] is True
def test_role(): src = dedent('''\ --- - name: play roles: - a''') script = api.Script(src) print(script.data.tree) target = script._search_tree() assert {k for k, v in target.items() if v} == {'role'}
def test_api_search_tree_role(self): src = '''--- - roles: - ''' result = api.Script(src, line=2, column=5)._search_tree() print(result) assert result['task'] is False assert result['block'] is False assert result['role'] is True
def test_api_completions_in_second_play(self): src = '''--- - name: tasks: - command: echo - na ''' result = api.Script(src, line=5, column=4).completions() directive_names = [d.name for d in result if isinstance(d, Directive)] assert 'name' in directive_names
def test_api_module_name_completions(self): for src, ( line, column ), modules, emodules, directives, edirectives in self.TEST_DATA: result = api.Script(src, line=line, column=column).completions() assert all([isinstance(m, (Module, Directive)) for m in result]) module_names = [m.name for m in result if isinstance(m, Module)] for m in modules: assert m in module_names for m in emodules: assert m not in module_names directive_names = [ d.name for d in result if isinstance(d, Directive) ] for d in directives: assert d in directive_names for d in edirectives: assert d not in directive_names
def test_api_search_tree_task(self): result = api.Script(SRC2, line=2, column=5)._search_tree() assert result['task'] is True assert result['block'] is False assert result['module'] is True assert result['play'] is False
def test_api_search_tree_module(self): result = api.Script(SRC3, line=1, column=14)._search_tree() assert result['task'] is False assert result['module'] is True
def test_api_search_tree_play(self): result = api.Script(SRC, line=1, column=6)._search_tree() assert result['task'] is False assert result['play'] is True
def test_api_search_tree_module_arg(self): script = api.Script(SRC4, line=3, column=5) result = script._search_tree() assert isinstance(result['module_arg'], Module) assert result['module_arg'].name == 'yum'
def test_api_search_tree_module_arg_command(self): result = api.Script(SRC5, line=3, column=5)._search_tree() assert isinstance(result['module_arg'], Module) assert result['module_arg'].name == 'command'