' "Run {[project]} as {[exe]} on {[project]}.
" "Nothing here.
" ""
)
var_store.replace_node(node)
assert_equal(node.get("id"), "pgbackrest-block")
# Text before a child, inside it, and trailing it are all replaced, since a paragraph is text and markup interleaved
assert_equal(xml_node_content(node[0]), "Run pgBackRest as pgbackrest on pgBackRest.")
assert_equal(xml_node_content(node[1]), "Nothing here.")
####################################################################################################################################
def test_var_store_set():
"""A variable that is only known once the build is running replaces what it had, unlike one a document declares."""
var_store = VarStore()
var_store.add("host", "one")
var_store.add("host", "two")
assert_equal(var_store.get("host"), "one")
# An address or the output of a command is set rather than added, since it is not known until it is known
var_store.set("host", "three")
assert_equal(var_store.get("host"), "three")
assert_true(var_store.test("host", "three"))
assert_false(var_store.test("host", "one"))
# A variable that was never set has no value rather than an empty one
assert_is_none(var_store.get("missing"))
assert_false(var_store.test("missing", ""))
# Nothing is what nothing replaces to, so a caller with something optional in hand does not have to check first
assert_is_none(var_store.replace_str(None))
####################################################################################################################################
def test_var_store_eval():
"""A variable may ask for a fact about the environment that the document has no other way to know."""
import os
from common.user import user_name
var_store = VarStore()
assert_equal(eval_value("cwd"), os.getcwd())
assert_equal(eval_value("'vagrant' if user == 'root' else user"), "vagrant" if user_name() == "root" else user_name())
# The result is text, since that is what a variable holds
assert_equal(eval_value("1 + 1"), "2")
# What it may use is a short list rather than the whole interpreter
with assert_raises(ToolError) as raised:
eval_value("open('/etc/passwd')")
assert_in("unable to evaluate 'open('/etc/passwd')'", str(raised.exception))
####################################################################################################################################
def test_var_store_add_node():
"""A variable is declared by a node, which says whether what it holds is the value or how to work it out."""
from common.xml import xml_parse
var_store = VarStore()
var_store.add("project", "pgBackRest")
var_store.add_node(xml_parse("