def test_add_auto_data(): c = k8s.Context() s = cfg.AutoData() s.apiVersion = 'v1' s.metadata.name = 'foobar' c += s assert c._render_data() == [{ 'apiVersion': 'v1', 'metadata': { 'name': 'foobar' } }]
def test_auto_item7(): a = cfg.AutoData() a['apiVersion'] = 'v1' a['spec']['template']['spec']['containers'][0]['image'] = 'foo-bar:latest' assert a.data() == { 'apiVersion': 'v1', 'spec': { 'template': { 'spec': { 'containers': [{ 'image': 'foo-bar:latest' }] } } } }
def test_auto_item4(): a = cfg.AutoData() a[1] = 'value' assert a.data() == [None, 'value']
def test_auto_item3(): a = cfg.AutoData() a[0] = 'value' assert a.data() == ['value']
def test_auto_item2(): a = cfg.AutoData() a['top']['bottom'] = 'value' assert a.data() == {'top': {'bottom': 'value'}}
def test_auto_item1(): a = cfg.AutoData() a['key'] = 'value' assert a.data() == {'key': 'value'}
def test_auto_empty_data(): a = cfg.AutoData() assert a.data() == {}
def test_auto_object_invalid_key_type(): a = cfg.AutoData() with pytest.raises(p10s.config_context.InvalidKeyType): a['a'][{}]
def test_auto_object_change_type2(): a = cfg.AutoData() a[0] = '1' assert a.data() == ['1'] with pytest.raises(p10s.config_context.DataAccessMismatch): a['key']
def test_auto_attr2(): a = cfg.AutoData() a.a.b.c[1].d = 'bar' a.data() == {'a': {'b': {'c': [None, {'d': 'bar'}]}}}
def test_auto_attr1(): a = cfg.AutoData() a.foo = 'bar' a.data() == {'foo': 'bar'}
def test_auto_item6(): a = cfg.AutoData() a['a'][4]['f'] = 'z' assert a.data() == {'a': [None, None, None, None, {'f': 'z'}]}
def test_auto_item5(): a = cfg.AutoData() a['a']['b'] = '1' a['a']['c']['d'] = '2' assert a.data() == {'a': {'b': '1', 'c': {'d': '2'}}}