def test_dm_parser_limit(self): dm = dotmotif.dotmotif(limit=3) dm.from_motif(_DEMO_G_MIN) self.assertTrue("LIMIT 3" in Neo4jExecutor.motif_to_cypher(dm).strip()) dm = dotmotif.dotmotif() dm.from_motif(_DEMO_G_MIN) self.assertFalse("LIMIT" in Neo4jExecutor.motif_to_cypher(dm).strip())
def test_dm_parser_no_direction(self): dm = dotmotif.dotmotif(ignore_direction=True) dm.from_motif(_DEMO_G_MIN) self.assertEqual( Neo4jExecutor.motif_to_cypher(dm).strip(), _DEMO_G_MIN_CYPHER.strip().replace("->", "-"), )
def test_dm_parser_no_pretty_print(self): dm = dotmotif.dotmotif(pretty_print=False) dm.from_motif(_DEMO_G_MIN) self.assertEqual( Neo4jExecutor.motif_to_cypher(dm).strip(), _DEMO_G_MIN_CYPHER.strip().replace("\n", " "), )
def test_cypher_edge_many_attributes(self): dm = dotmotif.dotmotif() dm.from_motif(""" A -> B [weight=4, area<=10, area<=20] X -> Y [weight=2] """) self.assertEqual( Neo4jExecutor.motif_to_cypher(dm).strip(), _DEMO_EDGE_ATTR_CYPHER_2.strip())
def test_dynamic_constraints_in_cypher(self): dm = dotmotif.dotmotif(enforce_inequality=True) dm.from_motif(""" A -> B A.radius >= B.radius A.zorf != B.zorf """) self.assertIn( "WHERE A.radius >= B.radius AND A.zorf <> B.zorf", Neo4jExecutor.motif_to_cypher(dm).strip(), )
def test_cypher_node_attributes(self): dm = dotmotif.dotmotif() dm.from_motif(""" A -> B A.size = "big" """) self.assertEqual( Neo4jExecutor.motif_to_cypher(dm).strip(), """MATCH (A:Neuron)-[A_B:SYN]->(B:Neuron)\nWHERE A.size = "big"\nRETURN DISTINCT A,B""" .strip(), )
def test_cypher_node_same_node_many_attributes(self): dm = dotmotif.dotmotif() dm.from_motif(""" A -> B A.personality != "exciting" A.personality != "funny" """) self.assertEqual( Neo4jExecutor.motif_to_cypher(dm).strip(), """MATCH (A:Neuron)-[A_B:SYN]->(B:Neuron)\nWHERE A.personality <> "exciting" AND A.personality <> "funny"\nRETURN DISTINCT A,B""" .strip(), )
def test_cypher_node_and_edge_attributes(self): dm = dotmotif.dotmotif() dm.from_motif(""" A -> B [area != 10] A.area <= 10 B.area <= 10 """) self.assertEqual( Neo4jExecutor.motif_to_cypher(dm).strip(), ("MATCH (A:Neuron)-[A_B:SYN]->(B:Neuron)\n" "WHERE A.area <= 10 AND B.area <= 10 AND A_B.area <> 10\n" "RETURN DISTINCT A,B").strip(), )
def test_dm_parser_inequality(self): dm = dotmotif.dotmotif(enforce_inequality=True) dm.from_motif(_DEMO_G_MIN) self.assertTrue("A<>B" in Neo4jExecutor.motif_to_cypher(dm).strip() or "B<>A" in Neo4jExecutor.motif_to_cypher(dm).strip()) self.assertTrue("B<>C" in Neo4jExecutor.motif_to_cypher(dm).strip() or "C<>B" in Neo4jExecutor.motif_to_cypher(dm).strip()) self.assertTrue("A<>C" in Neo4jExecutor.motif_to_cypher(dm).strip() or "C<>A" in Neo4jExecutor.motif_to_cypher(dm).strip())
def test_cypher_negative_edge_and_inequality(self): dm = dotmotif.dotmotif(enforce_inequality=True) dm.from_motif(""" A -> B A -> C B !> C """) self.assertEqual( Neo4jExecutor.motif_to_cypher(dm).strip(), ("MATCH (A:Neuron)-[A_B:SYN]->(B:Neuron)\n" "MATCH (A:Neuron)-[A_C:SYN]->(C:Neuron)\n" "WHERE NOT (B:Neuron)-[:SYN]->(C:Neuron) AND A<>B AND A<>C AND B<>C\n" "RETURN DISTINCT A,B,C").strip(), )
def test_dm_parser_defaults(self): dm = dotmotif.dotmotif() dm.from_motif(_DEMO_G_MIN) self.assertEqual( Neo4jExecutor.motif_to_cypher(dm).strip(), _DEMO_G_MIN_CYPHER.strip())
def test_fix_where_clause__github_35(self): dm = dotmotif.dotmotif(enforce_inequality=True) dm.from_motif(""" A -> B """) self.assertIn("WHERE", Neo4jExecutor.motif_to_cypher(dm).strip())