示例#1
0
文件: graph.py 项目: rv816/graphlib
    def test_relate_rev(self):
        s = Node()
        e = Node()

        r = e.relate(s, '-', direction=-1)
        _r = s.relate(e, '-', direction=1)
        self.assertEqual(r, _r)
示例#2
0
文件: graph.py 项目: rv816/graphlib
    def test_relate(self):
        s = Node()
        e = Node()

        r = s.relate(e, 'YES', direction=1)
        _r = e.relate(s, 'YES', direction=-1)
        self.assertEqual(r, _r)

        # Any relationship
        self.assertTrue(s.related(e))
        self.assertTrue(e.related(s))

        # Specific relationship
        self.assertTrue(s.related(e, 'YES'))
        self.assertTrue(e.related(s, 'YES'))

        self.assertFalse(s.related(e, 'NO'))
        self.assertFalse(e.related(s, 'NO'))

        # Specific direction
        self.assertTrue(s.related(e, 'YES', outgoing=True))
        self.assertTrue(e.related(s, 'YES', incoming=True))

        self.assertFalse(s.related(e, 'YES', incoming=True))
        self.assertFalse(e.related(s, 'YES', outgoing=True))
示例#3
0
    def test(self):
        s = Serializer()
        n = Node({'foo': 'bar', 'bar': 1})

        # Add properties for coverage
        n.labels = ['Special']
        n.match_props = ['foo']
        n.update_props = ['bar']

        rels = n.relate([Node() for _ in range(5)], 'NEXT')

        o = Node()
        n.relate(o, 'OTHER')

        # Add properties for coverage
        rels[0].match_props = ['foo']
        rels[0].update_props = ['bar']

        # Single relationship (and start and end node)
        s.serialize(rels[0])

        # Remaining rels
        s.serialize(rels[1:])

        s.serialize(n)

        # No effect
        s.serialize(n, traverse=False)
        s.serialize(rels[0])

        self.assertRaises(TypeError, s.serialize, None)

        self.assertEqual(len(s.items), 13)
        self.assertEqual(len(s.batches), 2)
示例#4
0
文件: graph.py 项目: rv816/graphlib
    def test(self):
        n0, n1, n2, n3 = Node(), Node(), Node(), Node()

        n0.relate([n1, n2, n3], 'CONTAINS')
        n0.relate([n1, n2], 'RELATED')

        # Get all relationships from n0
        rels = n0.rels()
        nodes = rels.nodes()

        # Gets distinct set of end nodes of rels
        self.assertCountEqual(nodes, [n1, n2, n3])
示例#5
0
文件: graph.py 项目: rv816/graphlib
    def test_relate_idempotent(self):
        s = Node()
        e = Node()

        r0 = s.relate(e, 'YES')
        r1 = s.relate(e, 'YES', {'one': 1})
        r2 = s.relate(e, 'YES')
        r3 = e.relate(s, 'YES', direction=-1)

        self.assertEqual(r1, r0)
        self.assertEqual(r2, r0)
        self.assertEqual(r3, r0)

        self.assertEqual(r0.props, {'one': 1})
示例#6
0
文件: neo4j.py 项目: bruth/graphlib
 def test_parse_merge_rel(self):
     n = Node()
     r = n.relate(Node(), 'TO', {'foo': 1, 'bar': 'a'}, match_props=['foo'])
     s = "MERGE (x0)-[x2:TO {foo: 1}]->(x1) " \
         "ON CREATE SET x2 = {bar: 'a', foo: 1} " \
         "ON MATCH SET x2.bar = 'a', x2.foo = 1"
     # Third statement.. after creating the nodes
     self.assertEqual(neo4j.parse(serialize(r))[2], s)
示例#7
0
文件: neo4j.py 项目: rv816/graphlib
 def test_parse_merge_rel(self):
     n = Node()
     r = n.relate(Node(), 'TO', {'foo': 1, 'bar': 'a'}, match_props=['foo'])
     s = "MERGE (x0)-[x2:TO {foo: 1}]->(x1) " \
         "ON CREATE SET x2 = {bar: 'a', foo: 1} " \
         "ON MATCH SET x2.bar = 'a', x2.foo = 1"
     # Third statement.. after creating the nodes
     self.assertEqual(neo4j.parse(serialize(r))[2], s)
示例#8
0
文件: graph.py 项目: rv816/graphlib
    def test_unrelate(self):
        s = Node()
        e = Node()
        o = Node()

        s.relate(e, 'A')
        s.relate(e, 'B')
        s.relate(e, 'C')
        s.relate(o, 'B')
        s.relate(o, 'D')

        self.assertEqual(s.unrelate(e, 'A'), 1)
        self.assertEqual(s.unrelate(e), 2)
        self.assertEqual(s.unrelate(type='B'), 1)
        self.assertEqual(s.unrelate(), 1)

        e.relate(s, 'A')
        s.relate(e, 'A')

        self.assertEqual(s.unrelate(e, direction=1), 1)
        self.assertEqual(s.unrelate(e, direction=-1), 1)
示例#9
0
文件: graph.py 项目: rv816/graphlib
    def test_rels(self):
        s = Node()
        e = Node()
        o = Node()

        r0 = s.relate(e, 'R')
        r1 = s.relate(e, 'A', direction=-1)
        r2 = s.relate(o, 'R')

        self.assertCountEqual(s.rels(e), [r0, r1])
        self.assertCountEqual(s.rels(e, direction=1), [r0])
        self.assertCountEqual(s.rels(e, direction=-1), [r1])

        self.assertCountEqual(s.rels(type='R'), [r0, r2])
        self.assertCountEqual(s.rels(type='R', direction=1), [r0, r2])
        self.assertCountEqual(s.rels(type='A', direction=-1), [r1])

        self.assertCountEqual(s.rels(e, type='R'), [r0])
        self.assertCountEqual(s.rels(e, type='R', direction=1), [r0])
        self.assertCountEqual(s.rels(e, type='A', direction=-1), [r1])

        self.assertCountEqual(s.rels(), [r0, r1, r2])
        self.assertCountEqual(s.rels(direction=1), [r0, r2])
        self.assertCountEqual(s.rels(direction=-1), [r1])
示例#10
0
文件: neo4j.py 项目: bruth/graphlib
    def setUp(self):
        n = Node({'foo': 'bar', 'baz': 10})

        # Add properties for coverage
        n.labels = ['Special']
        n.match_props = ['foo']
        n.update_props = ['baz']

        rels = []
        for i in range(5):
            rels.append(n.relate(Node({'index': i}), 'NEXT',
                        {'foo': i, 'bar': 2}))

        rels[0].match_props = ['foo']
        rels[0].update_props = ['bar']

        self.data = serialize(n)
示例#11
0
文件: neo4j.py 项目: rv816/graphlib
    def setUp(self):
        n = Node({'foo': 'bar', 'baz': 10})

        # Add properties for coverage
        n.labels = ['Special']
        n.match_props = ['foo']
        n.update_props = ['baz']

        rels = []
        for i in range(5):
            rels.append(
                n.relate(Node({'index': i}), 'NEXT', {
                    'foo': i,
                    'bar': 2
                }))

        rels[0].match_props = ['foo']
        rels[0].update_props = ['bar']

        self.data = serialize(n)
示例#12
0
文件: graph.py 项目: rv816/graphlib
    def test_degree(self):
        n0 = Node()
        n1 = Node()
        n2 = Node()
        n3 = Node()

        self.assertEqual(n0.degree, 0)

        n0.relate(n1, 'X')
        self.assertEqual(n0.degree, 1)
        self.assertEqual(n1.degree, 1)

        n0.relate(n2, 'X')
        self.assertEqual(n0.degree, 2)
        self.assertEqual(n1.degree, 1)
        self.assertEqual(n2.degree, 1)

        n2.relate(n3, 'X')
        self.assertEqual(n0.degree, 2)
        self.assertEqual(n1.degree, 1)
        self.assertEqual(n2.degree, 2)
        self.assertEqual(n3.degree, 1)
示例#13
0
文件: graph.py 项目: rv816/graphlib
 def test_relate_multi(self):
     s = Node()
     o = Node()
     t = Node()
     s.relate([o, t], 'TRI')