File: test_input.py

package info (click to toggle)
python-annotatedyaml 1.0.2-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 2,088 kB
  • sloc: python: 1,303; makefile: 18
file content (27 lines) | stat: -rw-r--r-- 736 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
"""Test inputs."""

import pytest

from annotatedyaml import Input, UndefinedSubstitution, extract_inputs, substitute


def test_extract_inputs() -> None:
    """Test extracting inputs from data."""
    assert extract_inputs(Input("hello")) == {"hello"}
    assert extract_inputs({"info": [1, Input("hello"), 2, Input("world")]}) == {
        "hello",
        "world",
    }


def test_substitute() -> None:
    """Test we can substitute."""
    assert substitute(Input("hello"), {"hello": 5}) == 5

    with pytest.raises(UndefinedSubstitution):
        substitute(Input("hello"), {})

    assert substitute(
        {"info": [1, Input("hello"), 2, Input("world")]},
        {"hello": 5, "world": 10},
    ) == {"info": [1, 5, 2, 10]}