def test_exception_thrown_if_requested_state_alias_not_provided(self): trans = EnvrStateAliasTranslator() trans.state_aliases = {0: "state1", 1: "state2", 2: "state3"} with self.assertRaises(ValueError) as cm: trans.state_alias(3) self.assertEqual( str(cm.exception), "No alias specified for state " "with code '3'." )
def test_exception_thrown_if_requested_cond_alias_not_provided(self): trans = EnvrStateAliasTranslator() trans.add_cond_aliases("cond1", {0: False, 1: True}) trans.add_cond_aliases("cond2", {0: "low", 1: "high"}) with self.assertRaises(ValueError) as cm: trans.cond_alias("cond2", 2) self.assertEqual( str(cm.exception), "No alias specified for" " condition 'cond2' with value '2'.", )
def test_can_add_condition_aliases(self): trans = EnvrStateAliasTranslator() trans.add_cond_aliases("cond1", {0: False, 1: True}) trans.add_cond_aliases("cond2", {0: "low", 1: "high"}) self.assertEqual(trans.cond_alias("cond1", 0), False) self.assertEqual(trans.cond_alias("cond1", 1), True) self.assertEqual(trans.cond_alias("cond2", 0), "low") self.assertEqual(trans.cond_alias("cond2", 1), "high")
def test_coded_queries_correct(self): """A state alias translator can be used to convert codes to names.""" trans = EnvrStateAliasTranslator() trans.state_aliases = {0: "state1", 1: "state2", 2: "state3"} trans.add_cond_aliases("cond1", {0: "low", 1: "high"}) trans.add_cond_aliases("cond3", {0: False, 1: True}) ttp = TransTableProcessor( self.demo_coded_table, "start", "end", state_alias_translator=trans ) query_iter = ttp.iterqueries() query1 = CypherQuery( 'MERGE (start:State {code:"state1"}) ' + 'MERGE (end:State {code:"state2"}) ' + "MERGE (start)<-[:SOURCE]-(trans:Transition)-[:TARGET]->(end) " + 'MERGE (cond:Condition {cond1:"low", cond2:2, cond3:true})' + "-[:CAUSES]->(trans);" ) query2 = CypherQuery( 'MERGE (start:State {code:"state2"}) ' + 'MERGE (end:State {code:"state3"}) ' + "MERGE (start)<-[:SOURCE]-(trans:Transition)-[:TARGET]->(end) " + 'MERGE (cond:Condition {cond1:"high", cond2:3, cond3:false})' + "-[:CAUSES]->(trans);" ) self.assertEqual(six.next(query_iter).statement, query1.statement) self.assertEqual(six.next(query_iter).statement, query2.statement) self.assertRaises(StopIteration, partial(six.next, query_iter))
def test_coded_transition_table_can_be_used(self): trans = EnvrStateAliasTranslator() gl = GraphLoader() try: gl.load_tabular(self.demo_coded_table, "start", "end", state_alias_translator=trans) except Exception: self.fail("Could not use state_alias_translator in load_tabular.")
def test_exception_thrown_if_condition_not_specified(self): trans = EnvrStateAliasTranslator() trans.add_cond_aliases("cond2", {0: "low", 1: "high"}) with self.assertRaises(ValueError) as cm: trans.cond_alias("cond1", 0) self.assertEqual( str(cm.exception), "No aliases specified for" " condition 'cond1'." )
def test_can_get_list_of_all_aliased_conditions(self): trans = EnvrStateAliasTranslator() trans.add_cond_aliases("cond1", {0: False, 1: True}) trans.add_cond_aliases("cond2", {0: "low", 1: "high"}) self.assertEqual(trans.all_conds, ["cond1", "cond2"])
def test_can_add_state_aliases(self): trans = EnvrStateAliasTranslator() trans.state_aliases = {0: "state1", 1: "state2", 2: "state3"} self.assertEqual(trans.state_alias(0), "state1") self.assertEqual(trans.state_alias(1), "state2") self.assertEqual(trans.state_alias(2), "state3")