示例#1
0
    def test_to_graph(self):
        p = Pattern('/foo', '/bar')
        p['/foo', '/bar'] = 1
        g = p.to_graph()
        self.assertItemsEqual(g.nodes(data=True),
                              [('/foo', {'interface': 0, 'io': 'in', 'type': ''}),
                               ('/bar', {'interface': 1, 'io': 'out', 'type': ''})])

        p = Pattern('/foo[0:4]', '/bar[0:4]')
        p['/foo[0]', '/bar[0]'] = 1
        p['/foo[0]', '/bar[1]'] = 1
        p['/foo[1]', '/bar[2]'] = 1
        p['/bar[3]', '/foo[2]'] = 1
        p['/bar[3]', '/foo[3]'] = 1
        g = p.to_graph()

        self.assertItemsEqual(g.nodes(data=True), 
                              [('/bar/0', {'interface': 1, 'io': 'out', 'type': ''}),
                               ('/bar/1', {'interface': 1, 'io': 'out', 'type': ''}),
                               ('/bar/2', {'interface': 1, 'io': 'out', 'type': ''}),
                               ('/bar/3', {'interface': 1, 'io': 'in', 'type': ''}),
                               ('/foo/0', {'interface': 0, 'io': 'in', 'type': ''}),
                               ('/foo/1', {'interface': 0, 'io': 'in', 'type': ''}),
                               ('/foo/2', {'interface': 0, 'io': 'out', 'type': ''}),
                               ('/foo/3', {'interface': 0, 'io': 'out', 'type': ''})])
        self.assertItemsEqual(g.edges(data=True),
                              [('/foo/0', '/bar/0', {}),
                               ('/foo/0', '/bar/1', {}),
                               ('/foo/1', '/bar/2', {}),
                               ('/bar/3', '/foo/2', {}),
                               ('/bar/3', '/foo/3', {})])

        p.interface['/foo[0]','type'] = 'gpot'
        p.interface['/foo[1]','type'] = 'gpot'
        p.interface['/bar[0]','type'] = 'gpot'
        p.interface['/bar[1]','type'] = 'gpot'
        p.interface['/bar[2]','type'] = 'gpot'
        p.interface['/bar[3]','type'] = 'spike'
        p.interface['/foo[2]','type'] = 'spike'
        p.interface['/foo[3]','type'] = 'spike'
        g = p.to_graph()

        self.assertItemsEqual(g.nodes(data=True), 
                              [('/bar/0', {'interface': 1, 'io': 'out', 'type': 'gpot'}),
                               ('/bar/1', {'interface': 1, 'io': 'out', 'type': 'gpot'}),
                               ('/bar/2', {'interface': 1, 'io': 'out', 'type': 'gpot'}),
                               ('/bar/3', {'interface': 1, 'io': 'in', 'type': 'spike'}),
                               ('/foo/0', {'interface': 0, 'io': 'in', 'type': 'gpot'}),
                               ('/foo/1', {'interface': 0, 'io': 'in', 'type': 'gpot'}),
                               ('/foo/2', {'interface': 0, 'io': 'out', 'type': 'spike'}),
                               ('/foo/3', {'interface': 0, 'io': 'out', 'type': 'spike'})])
示例#2
0
    def test_to_graph(self):
        p = Pattern('/foo', '/bar')
        p['/foo', '/bar'] = 1
        g = p.to_graph()
        self.assertItemsEqual(g.nodes(data=True),
                              [('/foo', {'interface': 0, 'io': 'in', 'type': ''}),
                               ('/bar', {'interface': 1, 'io': 'out', 'type': ''})])

        p = Pattern('/foo[0:4]', '/bar[0:4]')
        p['/foo[0]', '/bar[0]'] = 1
        p['/foo[0]', '/bar[1]'] = 1
        p['/foo[1]', '/bar[2]'] = 1
        p['/bar[3]', '/foo[2]'] = 1
        p['/bar[3]', '/foo[3]'] = 1
        g = p.to_graph()

        self.assertItemsEqual(g.nodes(data=True), 
                              [('/bar/0', {'interface': 1, 'io': 'out', 'type': ''}),
                               ('/bar/1', {'interface': 1, 'io': 'out', 'type': ''}),
                               ('/bar/2', {'interface': 1, 'io': 'out', 'type': ''}),
                               ('/bar/3', {'interface': 1, 'io': 'in', 'type': ''}),
                               ('/foo/0', {'interface': 0, 'io': 'in', 'type': ''}),
                               ('/foo/1', {'interface': 0, 'io': 'in', 'type': ''}),
                               ('/foo/2', {'interface': 0, 'io': 'out', 'type': ''}),
                               ('/foo/3', {'interface': 0, 'io': 'out', 'type': ''})])
        self.assertItemsEqual(g.edges(data=True),
                              [('/foo/0', '/bar/0', {}),
                               ('/foo/0', '/bar/1', {}),
                               ('/foo/1', '/bar/2', {}),
                               ('/bar/3', '/foo/2', {}),
                               ('/bar/3', '/foo/3', {})])

        p.interface['/foo[0]','type'] = 'gpot'
        p.interface['/foo[1]','type'] = 'gpot'
        p.interface['/bar[0]','type'] = 'gpot'
        p.interface['/bar[1]','type'] = 'gpot'
        p.interface['/bar[2]','type'] = 'gpot'
        p.interface['/bar[3]','type'] = 'spike'
        p.interface['/foo[2]','type'] = 'spike'
        p.interface['/foo[3]','type'] = 'spike'
        g = p.to_graph()

        self.assertItemsEqual(g.nodes(data=True), 
                              [('/bar/0', {'interface': 1, 'io': 'out', 'type': 'gpot'}),
                               ('/bar/1', {'interface': 1, 'io': 'out', 'type': 'gpot'}),
                               ('/bar/2', {'interface': 1, 'io': 'out', 'type': 'gpot'}),
                               ('/bar/3', {'interface': 1, 'io': 'in', 'type': 'spike'}),
                               ('/foo/0', {'interface': 0, 'io': 'in', 'type': 'gpot'}),
                               ('/foo/1', {'interface': 0, 'io': 'in', 'type': 'gpot'}),
                               ('/foo/2', {'interface': 0, 'io': 'out', 'type': 'spike'}),
                               ('/foo/3', {'interface': 0, 'io': 'out', 'type': 'spike'})])
示例#3
0
    def test_to_graph(self):
        p = Pattern('/foo[0:4]', '/bar[0:4]')
        p['/foo[0]', '/bar[0]'] = 1
        p['/foo[0]', '/bar[1]'] = 1
        p['/foo[1]', '/bar[2]'] = 1
        p['/bar[3]', '/foo[2]'] = 1
        p['/bar[3]', '/foo[3]'] = 1
        g = p.to_graph()

        self.assertItemsEqual(g.nodes(data=True), 
                              [('/bar[0]', {'interface': 1, 'io': 'out', 'type': ''}),
                               ('/bar[1]', {'interface': 1, 'io': 'out', 'type': ''}),
                               ('/bar[2]', {'interface': 1, 'io': 'out', 'type': ''}),
                               ('/bar[3]', {'interface': 1, 'io': 'in', 'type': ''}),
                               ('/foo[0]', {'interface': 0, 'io': 'in', 'type': ''}),
                               ('/foo[1]', {'interface': 0, 'io': 'in', 'type': ''}),
                               ('/foo[2]', {'interface': 0, 'io': 'out', 'type': ''}),
                               ('/foo[3]', {'interface': 0, 'io': 'out', 'type': ''})])
        self.assertItemsEqual(g.edges(data=True),
                              [('/foo[0]', '/bar[0]', {}),
                               ('/foo[0]', '/bar[1]', {}),
                               ('/foo[1]', '/bar[2]', {}),
                               ('/bar[3]', '/foo[2]', {}),
                               ('/bar[3]', '/foo[3]', {})])