File: test_yaml.py

package info (click to toggle)
scap-security-guide 0.1.76-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 110,644 kB
  • sloc: xml: 241,883; sh: 73,777; python: 32,527; makefile: 27
file content (68 lines) | stat: -rw-r--r-- 1,769 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import os

import ssg.yaml


def test_list_or_string_update():
    assert ssg.yaml.update_yaml_list_or_string(
        "",
        "",
    ) == ""

    assert ssg.yaml.update_yaml_list_or_string(
        "something",
        "",
    ) == "something"

    assert ssg.yaml.update_yaml_list_or_string(
        ["something"],
        "",
    ) == "something"

    assert ssg.yaml.update_yaml_list_or_string(
        "",
        "else",
    ) == "else"

    assert ssg.yaml.update_yaml_list_or_string(
        "something",
        "else",
    ) == ["something", "else"]

    assert ssg.yaml.update_yaml_list_or_string(
        "",
        ["something", "else"],
    ) == ["something", "else"]

    assert ssg.yaml.update_yaml_list_or_string(
        ["something", "else"],
        "",
    ) == ["something", "else"]

    assert ssg.yaml.update_yaml_list_or_string(
        "something",
        ["entirely", "else"],
    ) == ["something", "entirely", "else"]

    assert ssg.yaml.update_yaml_list_or_string(
        ["something", "entirely"],
        ["entirely", "else"],
    ) == ["something", "entirely", "entirely", "else"]


def test_open_and_macro_expand_from_dir(tmpdir):
    # Setup: Create directory structure
    content_dir = tmpdir / "content_dir"
    macros_dir = content_dir / "shared" / "macros"
    os.makedirs(macros_dir, exist_ok=True)

    # Create YAML file with macro
    yaml_file = content_dir / "test.yaml"
    yaml_file.write("macro: {{{ test_macro() }}}")

    # Create macro file with macro definition
    macro_file = macros_dir / "test_macro.jinja"
    macro_file.write("{{% macro test_macro() %}}test{{% endmacro %}}")

    result = ssg.yaml.open_and_macro_expand_from_dir(str(yaml_file), str(content_dir))
    assert result['macro'] == 'test'