Пример #1
0
 def test_graph_setup(self):
     """
     Tests the outcome of constructing the canonical graph.
     """
     symbols = GraphTest.generate_canonical_symbols()
     models = GraphTest.generate_canonical_models()
     g = Graph(models=models, symbol_types=symbols, composite_models=dict())
     st_c = {x for x in symbols.values()}
     st_g = g.get_symbol_types()
     m_c = {x.name: x for x in models.values()}
     m_g = g.get_models()
     self.assertTrue(st_c == st_g,
                     'Canonical constructed graph does not have the right Symbol objects.')
     self.assertTrue(m_c == m_g,
                     'Canonical constructed graph does not have the right Model objects.')
     for m in models.values():
         for input_set in m.input_sets:
             for symbol in input_set:
                 self.assertTrue(symbols[symbol] in g._input_to_model.keys(),
                                 "Canonical constructed graph does not have an edge from input: "
                                 "{} to model: {}".format(symbol, m))
                 self.assertTrue(m in g._input_to_model[symbol],
                                 "Canonical constructed graph does not have an edge from input: "
                                 "{} to model: {}".format(symbol, m))
         for output_set in m.output_sets:
             for symbol in output_set:
                 self.assertTrue(symbols[symbol] in g._output_to_model.keys(),
                                 "Canonical constructed graph does not have an edge from input: "
                                 "{} to model: {}".format(symbol, m))
                 self.assertTrue(m in g._output_to_model[symbol],
                                 "Canonical constructed graph does not have an edge from input: "
                                 "{} to model: {}".format(symbol, m))
Пример #2
0
 def test_symbol_add_remove(self):
     """
     Tests the outcome of adding and removing a Symbol from the canonical graph.
     """
     symbols = GraphTest.generate_canonical_symbols()
     models = GraphTest.generate_canonical_models()
     g = Graph(models=models, symbol_types=symbols, composite_models=dict())
     g.remove_symbol_types({'F': symbols['F']})
     self.assertTrue(symbols['F'] not in g.get_symbol_types(),
                     "Symbol was not properly removed.")
     self.assertTrue(symbols['F'] not in g._input_to_model.keys(),
                     "Symbol was not properly removed.")
     self.assertTrue(symbols['F'] not in g._output_to_model.keys(),
                     "Symbol was not properly removed.")
     self.assertTrue(models['model3'] not in g.get_models().values(),
                     "Removing symbol did not remove a model using that symbol.")
     self.assertTrue(models['model6'] not in g.get_models().values(),
                     "Removing symbol did not remove a model using that symbol.")
     g.update_symbol_types({'F': symbols['F']})
     self.assertTrue(symbols['F'] in g.get_symbol_types(),
                    "Symbol was not properly added.")