Beispiel #1
0
def test_block():
    src = dedent('''\
        ---
        - block:
          a''')
    target = api.Script(src)._search_tree()
    assert {k for k, v in target.items() if v} == {'block'}
Beispiel #2
0
def test_blank_list():
    src = dedent('''\
        ---
        - hosts
        - ''')
    script = api.Script(src)
    assert script.data.tree == [['hosts', None], None]
Beispiel #3
0
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'}
Beispiel #4
0
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'}
Beispiel #5
0
def test_colon_absence():
    src = dedent('''\
        ---
        - name: name
          hosts
        ''')
    script = api.Script(src)
    assert script.data == [{'name': 'name', 'hosts': None}]
Beispiel #6
0
def test_unhandled_error():
    src = dedent('''\
        ---
        - hosts
        hoge
        ''')
    with pytest.raises(ParserError):
        api.Script(src)
Beispiel #7
0
def test_unallowed_map():
    src = dedent('''\
        ---
        - name
          hosts: all
        ''')
    script = api.Script(src)
    assert script.data == [{'name': None, 'hosts': 'all'}]
Beispiel #8
0
def test_unquoted():
    src = dedent('''\
        ---
        - name: "hoge
            fuga
        ''')
    script = api.Script(src)
    assert script.data == [{'name': 'hoge fuga'}]
Beispiel #9
0
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'}
Beispiel #10
0
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'}
Beispiel #11
0
    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
Beispiel #12
0
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'}
Beispiel #13
0
    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
Beispiel #14
0
    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
Beispiel #15
0
    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
Beispiel #16
0
 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
Beispiel #17
0
 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
Beispiel #18
0
 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
Beispiel #19
0
 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'
Beispiel #20
0
 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'