def test_duplicate_variable(): v1 = tf.Variable("var1", dict(default=1)) v2 = tf.Variable("var1", dict(other=42)) c = tf.Context(strict=True) c += v1 with pytest.raises(tf.DuplicateBlockError): c += v2
def test_multiple_variables(): c = tf.Context() c += tf.Variable('foo', dict( type='string' )) c += tf.Variable('bar', dict( default='whatever' )) assert {'variable': {'foo': {'type': 'string'}, 'bar': {'default': 'whatever'}}} == c.data
def test_share_resource(): t = tf.Variable("var1", dict(default=1)) c = tf.Context() c += t t.name = 'var2' c += t assert c.data == {'variable': {'var2': {'default': 1}}}
def test_copy_resource(): t = tf.Variable("var1", dict(default=1)) c = tf.Context() c += deepcopy(t) t.name = 'var2' c += t assert c.data == {'variable': {'var1': {'default': 1}, 'var2': {'default': 1}}}
def test_many_from_hcl_order(): c = tf.Context() many = tf.many_from_hcl(""" variable "" { default = "1" } variable "a" { default = "1" } variable "a/b" { default = "1" } variable "a/b/c" { default = "1" } """) assert [tf.Variable(name="", body={'default': '1'}), tf.Variable(name="a", body={'default': '1'}), tf.Variable(name="a/b", body={'default': '1'}), tf.Variable(name="a/b/c", body={'default': '1'})] == many
def test_iadd(): a = tf.Context() assert {} == a.data a += tf.Variable('foo', {'type': 'string'}) assert {'variable': {'foo': {'type': 'string'}}} == a.data
def test_variable2(): c = tf.Context() c += tf.Variable('foo', dict( type='string' )) assert {'variable': {'foo': {'type': 'string'}}} == c.data
def test_variable1(): c = tf.Context() c += tf.Variable('foo') assert {'variable': {'foo': {}}} == c.data