示例#1
0
    def test_directed_edge_get(self):
        """ Get an attribute of a directed edge """
        v0 = DirectedVertex(val='v0')
        v1 = DirectedVertex(val='v1')
        e01 = DirectedEdge((v0, v1), attrs={'weight': 5})

        self.assertEqual(e01.get('weight'), 5)
        self.assertIsNone(e01.get('notthere'))
示例#2
0
    def test_directed_edge_attrs(self):
        """ Get an directed edge's attrs property """
        v0 = DirectedVertex(val='v0')
        v1 = DirectedVertex(val='v1')
        e01 = DirectedEdge((v0, v1), {'weight': 5})

        self.assertEqual(e01.attrs, {'weight': 5})
        with self.assertRaises(AttributeError):
            e01.attrs = {'key': 'value'}
示例#3
0
    def test_directed_edge_del_attr(self):
        """ Delete an attribute of a directed edge """
        v0 = DirectedVertex(val='v0')
        v1 = DirectedVertex(val='v1')
        e01 = DirectedEdge((v0, v1), attrs={'weight': 5, 0: 1})

        e01.del_attr('weight')

        self.assertEqual(e01.attrs, {0: 1})

        e01.del_attr(0)

        self.assertEqual(e01.attrs, {})
示例#4
0
    def test_directed_edge_set(self):
        """ Set an attribute of a directed edge """
        v0 = DirectedVertex(val='v0')
        v1 = DirectedVertex(val='v1')
        e01 = DirectedEdge((v0, v1))

        e01.set('weight', 5)

        self.assertEqual(e01.attrs, {'weight': 5})

        e01.set(0, 1)

        self.assertEqual(e01.attrs, {'weight': 5, 0: 1})
示例#5
0
    def test_directed_edge_v_from_and_v_to(self):
        """ Get a directed edge's v_from and v_to properties """
        v0 = DirectedVertex(val='v0')
        v1 = DirectedVertex(val='v1')
        v2 = DirectedVertex(val='v2')
        v3 = DirectedVertex(val='v3')
        e01 = DirectedEdge((v0, v1))

        self.assertEqual(e01.v_from, v0)
        self.assertEqual(e01.v_to, v1)
        with self.assertRaises(AttributeError):
            e01.v_from = v2
        with self.assertRaises(AttributeError):
            e01.v_to = v3
示例#6
0
    def test_directed_edge_has_attr(self):
        """ Check if a directed edge has a particular attribute """
        v0 = DirectedVertex(val='v0')
        v1 = DirectedVertex(val='v1')
        e01 = DirectedEdge((v0, v1), attrs={'weight': 5, 0: 1})

        self.assertTrue(e01.has_attr('weight'))
        self.assertFalse(e01.has_attr('length'))

        e01.del_attr('weight')

        self.assertFalse(e01.has_attr('weight'))