Beispiel #1
0
def test_load_yaml_ok():
    '''
    Verify that proper YAML is parsed correctly
    '''
    yaml_data = '---\ncommands:\n- /bin/abc/def\n- /bin/ghi/jkl\nfiles:\n- /etc/abc/def.conf\n'
    with patch_open(yaml_data):
        result = load_yaml('test')
    assert result
Beispiel #2
0
def test_load_yaml_inline_tokens_in_regex_quotes():
    '''
    Verify that, if specifying a regex containing tokens parseable
    by YAML (such as []), when wrapped in quotation marks,
    the regex is parsed properly.
    '''
    yaml_data = '---\npatterns:\n  regex:\n  - \"[[:digit:]]*\"\n'
    with patch_open(yaml_data):
        result = load_yaml('test')
    assert result
Beispiel #3
0
def test_load_yaml_error():
    '''
    Verify that improper YAML raises an error
    '''
    yaml_data = '---\ncommands: files:\n- /etc/abc/def.conf\n'
    with patch_open(yaml_data):
        with pytest.raises(RuntimeError) as e:
            result = load_yaml('test')
            assert not result
    assert 'Cannot parse' in str(e.value)
Beispiel #4
0
def test_load_yaml_inline_tokens_in_regex_noquotes():
    '''
    Verify that, if specifying a regex containing tokens parseable
    by YAML (such as []), when not wrapped in quotation marks,
    an error is raised.
    '''
    yaml_data = '---\npatterns:\n  regex:\n  - [[:digit:]]*\n'
    with patch_open(yaml_data):
        with pytest.raises(RuntimeError) as e:
            result = load_yaml('test')
            assert not result
    assert 'Cannot parse' in str(e.value)