예제 #1
0
    def testVertexEdgeToWithOtherProperties(self):
        """Make sure you can set other properties on the edge"""
        t = Vertex()
        u = Vertex()

        e = t.edgeto(u, weight=5, label="First Edge")
        self.assertEqual(e.label, "First Edge")
예제 #2
0
    def testVertexEdgeFromWithWeight(self):
        """Connect 2 Vertices with an edge, and give the edge a weight"""
        u = Vertex()
        v = Vertex()

        e = u.edgefrom(v, weight=5)

        self.assertEqual(e.weight, 5)
예제 #3
0
    def testVertexIn(self):
        """
        Vertex().in() should ret a list of the vertices that come 'in' to it
        """
        u = Vertex()
        v = Vertex()
        e = u >> v

        self.assertEqual(v.in_(), {u})
예제 #4
0
    def testVertexInE(self):
        """
        Vertex().inE() should ret a list of the edges that come 'in' to it
        """
        u = Vertex()
        v = Vertex()

        e = u >> v

        self.assertEqual(v.inE(), {e})
예제 #5
0
    def testVertexOut(self):
        """
        Vertex().out() should ret a list of the vertices that are 'out' from it
        """
        u = Vertex()
        v = Vertex()

        e = u >> v

        self.assertEqual(u.out(), {v})
예제 #6
0
    def testVertexEdgeFrom(self):
        """Connect 2 Vertices with an edge"""
        u = Vertex()
        v = Vertex()

        e = u.edgefrom(v)

        self.assertIsInstance(e, Edge)
        self.assertEqual(e.from_, v)
        self.assertEqual(e.to, u)
예제 #7
0
    def testVertexOutE(self):
        """
        Vertex().outE() should ret a list of the edges that go 'out' from it
        """
        u = Vertex()
        v = Vertex()

        e = u >> v

        self.assertEqual(u.outE(), {e})
예제 #8
0
    def testFiltersOutE(self):
        """Make sure filters work with Edges, on the outE property"""
        t = Vertex(name="Frank")
        u = Vertex(name="Bob")
        v = Vertex(name="Sally")

        e1 = t.edgeto(u, weight=4, label="First Edge")
        e2 = t.edgeto(v, weight=5, label="Second Edge")

        results = t.outE(weight=5).label
        self.assertEqual(results, {'Second Edge'})
예제 #9
0
    def testAttributeSelectorWithFilterMultipleResults(self):
        """Make sure having multiple results doesn't mess it up"""
        t = Vertex(name="_t", value=1)
        u = Vertex(name="_u", value=5)
        v = Vertex(name="_v", value=5)

        e1 = t >> u
        e2 = t >> v

        result = t.out(value=5).name
        self.assertEqual(result, {"_u", "_v"})
예제 #10
0
    def testAttributeSelectorWithFilter(self):
        """Make sure you can still get the attribute after using a filter"""
        t = Vertex(name="_t", value=1)
        u = Vertex(name="_u", value=3)
        v = Vertex(name="_v", value=5)

        e1 = t >> u
        e2 = t >> v

        result = t.out(value=5).name
        self.assertEqual(result, {"_v"})
예제 #11
0
    def testVertexBothE(self):
        """
        Vertex().bothE() should ret a list of all 'connected' edges
        """
        t = Vertex()
        u = Vertex()
        v = Vertex()

        e1 = t >> u
        e2 = u >> v
        self.assertEqual(u.bothE(), {e2, e1})
예제 #12
0
    def testVertexBoth(self):
        """
        Vertex().both() should ret a list of all adjacent vertices
        """
        t = Vertex()
        u = Vertex()
        v = Vertex()

        e1 = t >> u
        e2 = u >> v

        self.assertEqual(u.both(), {v, t})
예제 #13
0
    def testChainingSelectorsWithAttributeAccess(self):
        """
        Chain selectors together and request an attribute at the end of the chain
        """
        t = Vertex()
        u = Vertex()
        u.name = "I am U"

        e = t >> u

        should_be_i_am_u = t.outE().inV().name
        self.assertEqual(should_be_i_am_u, {"I am U"})
예제 #14
0
    def testSelectorWithFilter(self):
        """
        Selectors take optional keyword arguments as filters
        """
        t = Vertex(name="_t", value=1)
        u = Vertex(name="_u", value=3)
        v = Vertex(name="_v", value=5)

        e1 = t >> u
        e2 = t >> v

        result = t.out(value=5)
        self.assertEqual(result, {v})
예제 #15
0
    def testMultipleFiltersMultipleResultsSomeMissingAttribute(self):
        """Ensure multiple filters get applied correctly"""
        t = Vertex()
        u = Vertex(name="_u", value=3)
        v = Vertex(name="_v", class_="blah", value=4)
        w = Vertex(name="_w", class_="blah", value=4)

        e1 = t >> u
        e2 = t >> v
        e3 = t >> w

        result = t.out(class_="blah", value=4)
        self.assertEqual(result, {v, w})
예제 #16
0
    def testSelectorWithFilterMultipleResults(self):
        """
        Ensure a query with multiple results gets returned correctly
        """
        t = Vertex(name="_t", value=1)
        u = Vertex(name="_u", value=5)
        v = Vertex(name="_v", value=5)

        e1 = t >> u
        e2 = t >> v

        result = t.out(value=5)
        self.assertEqual(result, {u, v})
예제 #17
0
    def testChainingSelectors(self):
        """Chain {in,out}{_,E,V} calls together"""
        t = Vertex()
        u = Vertex()
        e = t >> u

        # >>> t.outE()
        # {e}
        # >>> e.inV()
        # {u}
        should_be_u = t.outE().inV()

        self.assertEqual(should_be_u, {u})
예제 #18
0
    def testChainingSelectorsWithAttributeMultiple(self):
        """
        Chain selectors together, and get a list of attributes
        """
        t = Vertex()
        u = Vertex()
        v = Vertex()
        t.name = "_t"
        u.name = "_u"
        v.name = "_v"

        e1 = t >> v
        e2 = u >> v

        result = t.out().in_().name
        self.assertEqual(result, {"_t", "_u"})