"""Tests for flow.core.template.""" import os import pytest from flow.core.errors import ConfigError from flow.core.template import substitute_template class TestSubstituteTemplate: def test_replaces_double_braces(self): assert substitute_template("nvim-{{os}}", {"os": "linux"}) == "nvim-linux" def test_env_dot_notation(self, monkeypatch): monkeypatch.setenv("USER", "tomas") result = substitute_template("{{ env.USER }}", {"env": dict(os.environ)}) assert result == "tomas" def test_nested_dict_lookup(self): ctx = {"platform": {"arch": "arm64"}} assert substitute_template("{{ platform.arch }}", ctx) == "arm64" def test_unknown_variable_raises(self): with pytest.raises(ConfigError, match=r"\{\{ unknown \}\}"): substitute_template("{{ unknown }}", {}) def test_nested_unresolved_raises(self): with pytest.raises(ConfigError, match=r"\{\{ platform.missing \}\}"): substitute_template("{{ platform.missing }}", {"platform": {"arch": "arm64"}}) def test_unresolved_env_raises(self, monkeypatch): monkeypatch.delenv("SOME_NEVER_SET_VAR", raising=False) with pytest.raises(ConfigError): substitute_template("{{ env.SOME_NEVER_SET_VAR }}", {"env": {}}) def test_non_string_passthrough(self): assert substitute_template(42, {}) == 42 def test_whitespace_in_braces(self): assert substitute_template("{{ os }}", {"os": "linux"}) == "linux"