Exemplo n.º 1
0
 def test_exports_failed_render_ignore(self):
     node1_exports = Exports({'a': '${a}'}, SETTINGS, '')
     node1_parameters = Parameters(
         {
             'name': 'node1',
             'a': 1,
             'exp': '$[ +IgnoreErrors exports:a ]'
         }, SETTINGS, '')
     node1_entity = Entity(SETTINGS,
                           classes=None,
                           applications=None,
                           parameters=node1_parameters,
                           exports=node1_exports)
     node2_exports = Exports({'a': '${b}'}, SETTINGS, '')
     node2_parameters = Parameters({'name': 'node1', 'a': 2}, SETTINGS, '')
     node2_entity = Entity(SETTINGS,
                           classes=None,
                           applications=None,
                           parameters=node2_parameters,
                           exports=node2_exports)
     node1_entity.initialise_interpolation()
     node2_entity.initialise_interpolation()
     queries = node1_entity.parameters.get_inv_queries()
     for p, q in queries:
         node1_entity.interpolate_single_export(q)
         node2_entity.interpolate_single_export(q)
     res_inv = {'node1': {'a': 1}, 'node2': {}}
     res_params = {'a': 1, 'name': 'node1', 'exp': {'node1': 1}}
     inventory = {}
     inventory['node1'] = node1_entity.exports.as_dict()
     inventory['node2'] = node2_entity.exports.as_dict()
     node1_entity.interpolate(inventory)
     self.assertDictEqual(node1_parameters.as_dict(), res_params)
     self.assertDictEqual(inventory, res_inv)
Exemplo n.º 2
0
 def test_interpolate_list_types(self):
     node1_exports = Exports({'exps': ['${one}']}, SETTINGS, 'first')
     node1_parameters = Parameters(
         {
             'alpha': ['${two}', '${three}'],
             'one': 1,
             'two': 2,
             'three': 3
         }, SETTINGS, 'first')
     node1_entity = Entity(SETTINGS,
                           classes=None,
                           applications=None,
                           parameters=node1_parameters,
                           exports=node1_exports)
     node2_exports = Exports({'exps': '${alpha}'}, SETTINGS, 'second')
     node2_parameters = Parameters({}, SETTINGS, 'second')
     node2_entity = Entity(SETTINGS,
                           classes=None,
                           applications=None,
                           parameters=node2_parameters,
                           exports=node2_exports)
     result = {'exps': [1, 2, 3]}
     node1_entity.merge(node2_entity)
     node1_entity.interpolate(None)
     self.assertIs(type(node1_entity.exports.as_dict()['exps']), list)
     self.assertDictEqual(node1_entity.exports.as_dict(), result)
Exemplo n.º 3
0
 def test_exports_failed_render(self):
     node1_exports = Exports({'a': '${a}'}, SETTINGS, '')
     node1_parameters = Parameters(
         {
             'name': 'node1',
             'a': 1,
             'exp': '$[ exports:a ]'
         }, SETTINGS, '')
     node1_entity = Entity(SETTINGS,
                           classes=None,
                           applications=None,
                           parameters=node1_parameters,
                           exports=node1_exports)
     node2_exports = Exports({'a': '${b}'}, SETTINGS, '')
     node2_parameters = Parameters({'name': 'node2', 'a': 2}, SETTINGS, '')
     node2_entity = Entity(SETTINGS,
                           classes=None,
                           applications=None,
                           parameters=node2_parameters,
                           exports=node2_exports)
     node1_entity.initialise_interpolation()
     node2_entity.initialise_interpolation()
     queries = node1_entity.parameters.get_inv_queries()
     with self.assertRaises(ResolveError):
         for p, q in queries:
             node1_entity.interpolate_single_export(q)
             node2_entity.interpolate_single_export(q)
Exemplo n.º 4
0
 def test_exports_with_refs(self):
     inventory = {'node1': {'a': 1, 'b': 2}, 'node2': {'a': 3, 'b': 4}}
     node3_exports = Exports({'a': '${a}', 'b': '${b}'}, SETTINGS, '')
     node3_parameters = Parameters({
         'name': 'node3',
         'a': '${c}',
         'b': 5
     }, SETTINGS, '')
     node3_parameters.merge({'c': 3})
     node3_entity = Entity(SETTINGS,
                           classes=None,
                           applications=None,
                           parameters=node3_parameters,
                           exports=node3_exports)
     node3_entity.interpolate_exports()
     inventory['node3'] = node3_entity.exports.as_dict()
     r = {
         'node1': {
             'a': 1,
             'b': 2
         },
         'node2': {
             'a': 3,
             'b': 4
         },
         'node3': {
             'a': 3,
             'b': 5
         }
     }
     self.assertDictEqual(inventory, r)
Exemplo n.º 5
0
 def test_interpolate_types(self):
     e = Exports({
         'alpha': {
             'one': 1,
             'two': 2
         },
         'beta': [1, 2]
     }, SETTINGS, '')
     r = {'alpha': {'one': 1, 'two': 2}, 'beta': [1, 2]}
     self.assertIs(type(e.as_dict()['alpha']), ParameterDict)
     self.assertIs(type(e.as_dict()['beta']), ParameterList)
     e.interpolate()
     self.assertIs(type(e.as_dict()['alpha']), dict)
     self.assertIs(type(e.as_dict()['beta']), list)
     self.assertEqual(e.as_dict(), r)
Exemplo n.º 6
0
 def test_reference_to_an_export(self):
     inventory = {'node1': {'a': 1, 'b': 2}, 'node2': {'a': 3, 'b': 4}}
     node3_exports = Exports({'a': '${a}', 'b': '${b}'}, SETTINGS, '')
     node3_parameters = Parameters(
         {
             'name': 'node3',
             'ref': '${exp}',
             'a': '${c}',
             'b': 5
         }, SETTINGS, '')
     node3_parameters.merge({'c': 3, 'exp': '$[ exports:a ]'})
     node3_entity = Entity(SETTINGS,
                           classes=None,
                           applications=None,
                           parameters=node3_parameters,
                           exports=node3_exports)
     node3_entity.interpolate_exports()
     inventory['node3'] = node3_entity.exports.as_dict()
     node3_entity.interpolate(inventory)
     res_inv = {
         'node1': {
             'a': 1,
             'b': 2
         },
         'node2': {
             'a': 3,
             'b': 4
         },
         'node3': {
             'a': 3,
             'b': 5
         }
     }
     res_params = {
         'a': 3,
         'c': 3,
         'b': 5,
         'name': 'node3',
         'exp': {
             'node1': 1,
             'node3': 3,
             'node2': 3
         },
         'ref': {
             'node1': 1,
             'node3': 3,
             'node2': 3
         }
     }
     self.assertDictEqual(node3_parameters.as_dict(), res_params)
     self.assertDictEqual(inventory, res_inv)
Exemplo n.º 7
0
 def test_exports_with_nested_references(self):
     inventory = {
         'node1': {
             'alpha': {
                 'a': 1,
                 'b': 2
             }
         },
         'node2': {
             'alpha': {
                 'a': 3,
                 'b': 4
             }
         }
     }
     node3_exports = Exports({'alpha': '${alpha}'})
     node3_parameters = Parameters({
         'name': 'node3',
         'alpha': {
             'a': '${one}',
             'b': '${two}'
         },
         'beta': '$[ exports:alpha ]',
         'one': '111',
         'two': '${three}',
         'three': '123'
     })
     node3_entity = Entity(None, None, node3_parameters, node3_exports)
     res_params = {
         'beta': {
             'node1': {
                 'a': 1,
                 'b': 2
             },
             'node3': {
                 'a': '111',
                 'b': '123'
             },
             'node2': {
                 'a': 3,
                 'b': 4
             }
         },
         'name': 'node3',
         'alpha': {
             'a': '111',
             'b': '123'
         },
         'three': '123',
         'two': '123',
         'one': '111'
     }
     res_inv = {
         'node1': {
             'alpha': {
                 'a': 1,
                 'b': 2
             }
         },
         'node2': {
             'alpha': {
                 'a': 3,
                 'b': 4
             }
         },
         'node3': {
             'alpha': {
                 'a': '111',
                 'b': '123'
             }
         }
     }
     node3_entity.interpolate_exports()
     inventory['node3'] = node3_entity.exports.as_dict()
     node3_entity.interpolate('node3', inventory)
     self.assertDictEqual(node3_parameters.as_dict(), res_params)
     self.assertDictEqual(inventory, res_inv)
Exemplo n.º 8
0
 def _make_instances(self, Classes, Applications, Parameters, Exports):
     return Classes(), Applications(), Parameters(), Exports()
Exemplo n.º 9
0
 def test_overwrite_method(self):
     e = Exports({'alpha': {'one': 1, 'two': 2}})
     d = {'alpha': {'three': 3, 'four': 4}}
     e.overwrite(d)
     e.initialise_interpolation()
     self.assertEqual(e.as_dict(), d)
Exemplo n.º 10
0
 def test_exports_with_ancestor_references(self):
     inventory = {
         'node1': {
             'alpha': {
                 'beta': {
                     'a': 1,
                     'b': 2
                 }
             }
         },
         'node2': {
             'alpha': {
                 'beta': {
                     'a': 3,
                     'b': 4
                 }
             }
         }
     }
     node3_exports = Exports({'alpha': '${alpha}'}, SETTINGS, '')
     node3_parameters = Parameters(
         {
             'name': 'node3',
             'alpha': {
                 'beta': {
                     'a': 5,
                     'b': 6
                 }
             },
             'exp': '$[ exports:alpha:beta ]'
         }, SETTINGS, '')
     node3_entity = Entity(SETTINGS,
                           classes=None,
                           applications=None,
                           parameters=node3_parameters,
                           exports=node3_exports)
     res_params = {
         'exp': {
             'node1': {
                 'a': 1,
                 'b': 2
             },
             'node2': {
                 'a': 3,
                 'b': 4
             },
             'node3': {
                 'a': 5,
                 'b': 6
             }
         },
         'name': 'node3',
         'alpha': {
             'beta': {
                 'a': 5,
                 'b': 6
             }
         }
     }
     res_inv = {
         'node1': {
             'alpha': {
                 'beta': {
                     'a': 1,
                     'b': 2
                 }
             }
         },
         'node2': {
             'alpha': {
                 'beta': {
                     'a': 3,
                     'b': 4
                 }
             }
         },
         'node3': {
             'alpha': {
                 'beta': {
                     'a': 5,
                     'b': 6
                 }
             }
         }
     }
     node3_entity.initialise_interpolation()
     queries = node3_entity.parameters.get_inv_queries()
     for p, q in queries:
         node3_entity.interpolate_single_export(q)
     inventory['node3'] = node3_entity.exports.as_dict()
     node3_entity.interpolate(inventory)
     self.assertDictEqual(node3_parameters.as_dict(), res_params)
     self.assertDictEqual(inventory, res_inv)
Exemplo n.º 11
0
 def test_exports_with_nested_references(self):
     inventory = self._make_inventory({
         'node1': {
             'alpha': {
                 'a': 1,
                 'b': 2
             }
         },
         'node2': {
             'alpha': {
                 'a': 3,
                 'b': 4
             }
         }
     })
     node3_exports = Exports({'alpha': '${alpha}'}, SETTINGS, '')
     node3_parameters = Parameters(
         {
             'name': 'node3',
             'alpha': {
                 'a': '${one}',
                 'b': '${two}'
             },
             'beta': '$[ exports:alpha ]',
             'one': '111',
             'two': '${three}',
             'three': '123'
         }, SETTINGS, '')
     node3_entity = Entity(SETTINGS,
                           classes=None,
                           applications=None,
                           parameters=node3_parameters,
                           exports=node3_exports)
     res_params = {
         'name': 'node3',
         'alpha': {
             'a': '111',
             'b': '123'
         },
         'beta': {
             'node1': {
                 'a': 1,
                 'b': 2
             },
             'node2': {
                 'a': 3,
                 'b': 4
             },
             'node3': {
                 'a': '111',
                 'b': '123'
             }
         },
         'one': '111',
         'two': '123',
         'three': '123'
     }
     res_inv = {
         'node1': NodeInventory({'alpha': {
             'a': 1,
             'b': 2
         }}, True),
         'node2': NodeInventory({'alpha': {
             'a': 3,
             'b': 4
         }}, True),
         'node3': NodeInventory({'alpha': {
             'a': '111',
             'b': '123'
         }}, True)
     }
     node3_entity.interpolate_exports()
     inventory['node3'] = NodeInventory(node3_entity.exports.as_dict(),
                                        True)
     node3_entity.interpolate(inventory)
     self.assertDictEqual(node3_parameters.as_dict(), res_params)
     self.assertDictEqual(inventory, res_inv)
Exemplo n.º 12
0
 def test_exports_multiple_nodes(self):
     node1_exports = Exports({'a': '${a}'}, SETTINGS, '')
     node1_parameters = Parameters(
         {
             'name': 'node1',
             'a': {
                 'test': '${b}'
             },
             'b': 1,
             'exp': '$[ exports:a ]'
         }, SETTINGS, '')
     node1_entity = Entity(SETTINGS,
                           classes=None,
                           applications=None,
                           parameters=node1_parameters,
                           exports=node1_exports)
     node2_exports = Exports({'a': '${a}'}, SETTINGS, '')
     node2_parameters = Parameters(
         {
             'name': 'node2',
             'a': {
                 'test': '${b}'
             },
             'b': 2
         }, SETTINGS, '')
     node2_entity = Entity(SETTINGS,
                           classes=None,
                           applications=None,
                           parameters=node2_parameters,
                           exports=node2_exports)
     node1_entity.initialise_interpolation()
     node2_entity.initialise_interpolation()
     queries = node1_entity.parameters.get_inv_queries()
     for p, q in queries:
         node1_entity.interpolate_single_export(q)
         node2_entity.interpolate_single_export(q)
     res_inv = {
         'node1': NodeInventory({'a': {
             'test': 1
         }}, True),
         'node2': NodeInventory({'a': {
             'test': 2
         }}, True)
     }
     res_params = {
         'name': 'node1',
         'a': {
             'test': 1
         },
         'b': 1,
         'exp': {
             'node1': {
                 'test': 1
             },
             'node2': {
                 'test': 2
             }
         }
     }
     inventory = self._make_inventory({
         'node1':
         node1_entity.exports.as_dict(),
         'node2':
         node2_entity.exports.as_dict()
     })
     node1_entity.interpolate(inventory)
     self.assertDictEqual(node1_parameters.as_dict(), res_params)
     self.assertDictEqual(inventory, res_inv)
Exemplo n.º 13
0
 def test_overwrite_method(self):
     e = Exports({'alpha': {'one': 1, 'two': 2}}, SETTINGS, '')
     d = {'alpha': {'three': 3, 'four': 4}}
     e.overwrite(d)
     e.interpolate()
     self.assertEqual(e.as_dict(), d)