load_yaml: Rename include directive to jw.include
The include directive was previously triggered by a bare "include"
key in YAML files. This could collide with user-defined keys.
Rename it to "jw.include" so that:
jw.include: file.yaml
jw.include:
- file1.yaml
- file2.yaml
is used instead of just "include:". This follows the convention
established by "jw.link" for link expansion markers.
Signed-off-by: Jan Lindemann <jan@janware.com>
This commit is contained in:
parent
d7454341e8
commit
57a75399a2
1 changed files with 20 additions and 14 deletions
|
|
@ -139,7 +139,7 @@ class TestIncludeDirective:
|
|||
base = temp_dir(
|
||||
[
|
||||
('base.yaml', 'shared: from_base\n'),
|
||||
('main.yaml', 'include: base.yaml\ncurrent: here\n'),
|
||||
('main.yaml', 'jw.include: base.yaml\ncurrent: here\n'),
|
||||
]
|
||||
)
|
||||
data = load_yaml(pathlib.Path(base) / 'main.yaml')
|
||||
|
|
@ -151,7 +151,7 @@ class TestIncludeDirective:
|
|||
[
|
||||
('a.yaml', 'from_a: 1\nshared: a\n'),
|
||||
('b.yaml', 'from_b: 2\nshared: b\n'),
|
||||
('main.yaml', 'include:\n - a.yaml\n - b.yaml\nlocal: yes\n'),
|
||||
('main.yaml', 'jw.include:\n - a.yaml\n - b.yaml\nlocal: yes\n'),
|
||||
]
|
||||
)
|
||||
data = load_yaml(pathlib.Path(base) / 'main.yaml')
|
||||
|
|
@ -164,7 +164,7 @@ class TestIncludeDirective:
|
|||
def test_optional_include(self, temp_dir: Callable) -> None:
|
||||
base = temp_dir(
|
||||
[
|
||||
('main.yaml', 'include:\n - "- nonexist.yaml"\nok: true\n'),
|
||||
('main.yaml', 'jw.include:\n - "- nonexist.yaml"\nok: true\n'),
|
||||
]
|
||||
)
|
||||
data = load_yaml(pathlib.Path(base) / 'main.yaml')
|
||||
|
|
@ -175,7 +175,13 @@ class TestIncludeDirective:
|
|||
[
|
||||
('base.yaml', 'config:\n db:\n host: localhost\n port: 5432\n'),
|
||||
('override.yaml', 'config:\n db:\n port: 3306\n name: mydb\n'),
|
||||
('main.yaml', 'include:\n - override.yaml\nconfig:\n cache: true\n'),
|
||||
(
|
||||
'main.yaml',
|
||||
'jw.include:\n'
|
||||
' - override.yaml\n'
|
||||
'config:\n'
|
||||
' cache: true\n'
|
||||
),
|
||||
]
|
||||
)
|
||||
data = load_yaml(pathlib.Path(base) / 'main.yaml')
|
||||
|
|
@ -187,8 +193,8 @@ class TestIncludeDirective:
|
|||
base = temp_dir(
|
||||
[
|
||||
('level1.yaml', 'from: level1\n'),
|
||||
('level2.yaml', 'include: level1.yaml\nfrom: level2\n'),
|
||||
('main.yaml', 'include: level2.yaml\n'),
|
||||
('level2.yaml', 'jw.include: level1.yaml\nfrom: level2\n'),
|
||||
('main.yaml', 'jw.include: level2.yaml\n'),
|
||||
]
|
||||
)
|
||||
data = load_yaml(pathlib.Path(base) / 'main.yaml')
|
||||
|
|
@ -197,8 +203,8 @@ class TestIncludeDirective:
|
|||
def test_include_circular_detect(self, temp_dir: Callable) -> None:
|
||||
base = temp_dir(
|
||||
[
|
||||
('a.yaml', 'include: b.yaml\n'),
|
||||
('b.yaml', 'include: a.yaml\n'),
|
||||
('a.yaml', 'jw.include: b.yaml\n'),
|
||||
('b.yaml', 'jw.include: a.yaml\n'),
|
||||
]
|
||||
)
|
||||
with pytest.raises(ValueError, match = 'Cyclic YAML include'):
|
||||
|
|
@ -208,7 +214,7 @@ class TestIncludeDirective:
|
|||
base = temp_dir(
|
||||
[
|
||||
('sub/inner.yaml', 'secret: found\n'),
|
||||
('main.yaml', 'include: sub/inner.yaml\n'),
|
||||
('main.yaml', 'jw.include: sub/inner.yaml\n'),
|
||||
]
|
||||
)
|
||||
data = load_yaml(pathlib.Path(base) / 'main.yaml')
|
||||
|
|
@ -526,7 +532,7 @@ class TestIncludePlusLinks:
|
|||
base = temp_dir(
|
||||
[
|
||||
('base.yaml', 'shared: from_include\n'),
|
||||
('main.yaml', 'include: base.yaml\nlink:\n jw.link: shared\n'),
|
||||
('main.yaml', 'jw.include: base.yaml\nlink:\n jw.link: shared\n'),
|
||||
]
|
||||
)
|
||||
data = load_yaml(pathlib.Path(base) / 'main.yaml')
|
||||
|
|
@ -537,7 +543,7 @@ class TestIncludePlusLinks:
|
|||
base = temp_dir(
|
||||
[
|
||||
('base.yaml', 'target: included\ndecorator:\n jw.link: target\n'),
|
||||
('main.yaml', 'include: base.yaml\nlocal: here\n'),
|
||||
('main.yaml', 'jw.include: base.yaml\nlocal: here\n'),
|
||||
]
|
||||
)
|
||||
data = load_yaml(pathlib.Path(base) / 'main.yaml')
|
||||
|
|
@ -550,7 +556,7 @@ class TestIncludePlusLinks:
|
|||
('base.yaml', 'base_val: ok\n'),
|
||||
(
|
||||
'main.yaml',
|
||||
'include: base.yaml\nlocal:\n link:\n jw.link: ..base_val\n'
|
||||
'jw.include: base.yaml\nlocal:\n link:\n jw.link: ..base_val\n'
|
||||
),
|
||||
]
|
||||
)
|
||||
|
|
|
|||
Loading…
Reference in a new issue