def test_model_add_remove(self): """ Tests the outcome of adding and removing a model 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_models({models['model6'].name: models['model6']}) self.assertTrue(models['model6'] not in g.get_models().values(), "Model was unsuccessfully removed from the graph.") for s in g._input_to_model.values(): self.assertTrue(models['model6'] not in s, "Model was unsuccessfully removed from the graph.") for s in g._output_to_model.values(): self.assertTrue(models['model6'] not in s, "Model was unsuccessfully removed from the graph.") m6 = models['model6'] del models['model6'] for m in models.values(): self.assertTrue(m in g.get_models().values(), "Too many models were removed.") g.update_models({'Model6': m6}) self.assertTrue(m6 in g.get_models().values(), "Model was unsuccessfully added to the graph.") self.assertTrue(m6 in g._input_to_model[symbols['D']], "Model was unsuccessfully added to the graph.") self.assertTrue(m6 in g._input_to_model[symbols['F']], "Model was unsuccessfully added to the graph.") self.assertTrue(m6 in g._output_to_model[symbols['A']], "Model was unsuccessfully added to the graph.")
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))
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.")