Commit graph jw-python/test/unit/python/jw
Author SHA1 Message Date
7595bfc21e
load_yaml: Add target path support to jw.include
jw.include now supports specifying a target path where the included
content should be merged, using syntax similar to named links:

  jw.include: "path.to.target|/path/to/file.yaml"

The file's contents are deep-merged into the target path in the
resulting document tree.  If the target path doesn't exist,
intermediate dicts are created automatically.

Original behavior (plain string) still works:

  jw.include: "/path/to/file.yaml"

This merges the file at the root of the document.

Mixed usage is supported:

  jw.include:
    - "/path/to/plain.yaml"
    - section|/path/to/target.yaml

Added 8 unit tests covering: plain includes, nested paths, deep paths,
merge with existing, override existing, multiple paths, optional
includes, and mixed plain/path includes.

Signed-off-by: Jan Lindemann <jan@janware.com>
2026-08-12 23:10:12 +00:00
ab77b24a50
load_yaml: Add jw.inplace-link with sibling merge
jw.inplace-link behaves like jw.link but can have sibling keys that
are deep-merged into the resolved target dict (siblings override target
on conflict).

Usage:

  entry:
    jw.inplace-link: path.to.target
    sibling_key: value

Expands to:

  entry:
    <merged result of path.to.target + sibling_key: value>

This solves the common use case of pulling in a dict from elsewhere
while overriding specific keys inline.

Added 12 unit tests covering: no siblings, dict siblings, scalar
siblings, non-dict targets, relative paths, cycle detection, chains,
list siblings, list items, deep nesting, sibling override, and
integration with jw.include.

Signed-off-by: Jan Lindemann <jan@janware.com>
2026-08-12 23:10:12 +00:00
57a75399a2
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>
2026-08-12 23:10:12 +00:00
d7454341e8
load_yaml: Implement jw.link expansion
Implement link expansion in _expand_links() to resolve jw.link markers
in YAML documents after the include/merge phase.  Two link forms are
supported:

- Inplace links  jw.link: "path.to.target" replace the marker entirely
  with the resolved value at the target path.
- Named links   jw.link: "name|path.to.target" replace the marker with
  {name: resolved_value}, using the first path segment as the key.

Paths use dot-separated segments.  Relative paths start with ".."
(like Python imports): "." stays at the current level, ".." goes up
one level, "..." two, and so on.  A single pipe character in the link
value separates the link name from the target path for named links.

The implementation includes:

- _parse_link(): splits a link value into (is_named, name, path)
- _resolve_path(): resolves an absolute or relative path to a value
- _expand_links_recursive(): walks the structure, expands links,
  detects cycles via a resolving set, and memoises via a resolved dict.

Cyclic links and missing targets both raise ValueError/KeyError.
jw.link markers with sibling keys are left unexpanded.

Add 86 unit tests covering the entire load_yaml module:

- Basic YAML loading, optional loading, root type checking
- Include directive (single, multiple, deep merge, circular detect)
- Inplace links, named links, relative paths (up, descend, same level)
- Transitive links, cycle detection, missing targets
- Regression tests, combined include+links, edge cases, type preservation

Signed-off-by: Jan Lindemann <jan@janware.com>
2026-08-12 23:10:12 +00:00
499694e1f9
stree.StringTree: Add unit tests
Add pytest-style unit tests for the StringTree class.

This commit also adds the needed infrastructure: Dependency on
python3-pytest, the unit test directory structure and conftest.py in
.gitignore.

Assisted-by: unsloth/Qwen3.6-35B-A3B-GGUF:IQ4_NL with pi.dev v0.80.2
Signed-off-by: Jan Lindemann <jan@janware.com>
2026-08-12 23:10:12 +00:00