def test_get_fully_qualified_port_connections(self):
        # Signature: name(self)
        # Used by the flattening code.
        #
        # This method returns a d list of tuples of the
        # the fully-qualified port connections
        # from nineml.abstraction_layer.component.componentqueryer import ComponentClassQueryer

        # Signature: name(self)
        # Get the namespace address of this component
        d = ComponentClass(
            name='D',
            aliases=['A:=1', 'B:=2'],
            analog_ports=[AnalogSendPort('A'),
                          AnalogSendPort('B')])
        e = ComponentClass(name='E', analog_ports=[AnalogReceivePort('C')])
        f = ComponentClass(name='F', analog_ports=[AnalogReceivePort('D')])
        g = ComponentClass(name='G', analog_ports=[AnalogReceivePort('E')])
        b = ComponentClass(name='B',
                           subnodes={
                               'd': d,
                               'e': e
                           },
                           portconnections=[('d.A', 'e.C')])
        c = ComponentClass(name='C',
                           aliases=['G:=-1'],
                           analog_ports=[AnalogSendPort('G')],
                           subnodes={
                               'f': f,
                               'g': g
                           },
                           portconnections=[('G', 'f.D')])

        a = ComponentClass(name='A',
                           subnodes={
                               'b': b,
                               'c': c
                           },
                           analog_ports=[AnalogReceivePort('F')],
                           portconnections=[('b.d.A', 'F')])

        bNew = a.get_subnode('b')
        cNew = a.get_subnode('c')
        # dNew = a.get_subnode('b.d')
        # eNew = a.get_subnode('b.e')
        # fNew = a.get_subnode('c.f')
        # gNew = a.get_subnode('c.g')

        self.assertEquals(list(a.query.get_fully_qualified_port_connections()),
                          [(NamespaceAddress('b.d.A'), NamespaceAddress('F'))])

        self.assertEquals(
            list(bNew.query.get_fully_qualified_port_connections()),
            [(NamespaceAddress('b.d.A'), NamespaceAddress('b.e.C'))])

        self.assertEquals(
            list(cNew.query.get_fully_qualified_port_connections()),
            [(NamespaceAddress('c.G'), NamespaceAddress('c.f.D'))])
    def test_get_fully_qualified_port_connections(self):
        # Signature: name(self)
                # Used by the flattening code.
                #
                # This method returns a d list of tuples of the
                # the fully-qualified port connections
        # from nineml.abstraction_layer.component.componentqueryer import ComponentClassQueryer

        # Signature: name(self)
                # Get the namespace address of this component
        d = ComponentClass(
            name='D', aliases=['A:=1', 'B:=2'], analog_ports=[AnalogSendPort('A'), AnalogSendPort('B')])
        e = ComponentClass(name='E', analog_ports=[AnalogReceivePort('C')])
        f = ComponentClass(name='F', analog_ports=[AnalogReceivePort('D')])
        g = ComponentClass(name='G', analog_ports=[AnalogReceivePort('E')])
        b = ComponentClass(name='B', subnodes={
                           'd': d, 'e': e}, portconnections=[('d.A', 'e.C')])
        c = ComponentClass(name='C',
                           aliases=['G:=-1'],
                           analog_ports=[AnalogSendPort('G')],
                           subnodes={'f': f, 'g': g},
                           portconnections=[('G', 'f.D')])

        a = ComponentClass(name='A',
                           subnodes={'b': b, 'c': c},
                           analog_ports=[AnalogReceivePort('F')],
                           portconnections=[('b.d.A', 'F')]
                           )

        bNew = a.get_subnode('b')
        cNew = a.get_subnode('c')
        # dNew = a.get_subnode('b.d')
        # eNew = a.get_subnode('b.e')
        # fNew = a.get_subnode('c.f')
        # gNew = a.get_subnode('c.g')

        self.assertEquals(list(a.query.get_fully_qualified_port_connections()),
                          [(NamespaceAddress('b.d.A'), NamespaceAddress('F'))])

        self.assertEquals(list(bNew.query.get_fully_qualified_port_connections()),
                          [(NamespaceAddress('b.d.A'), NamespaceAddress('b.e.C'))])

        self.assertEquals(list(cNew.query.get_fully_qualified_port_connections()),
                          [(NamespaceAddress('c.G'), NamespaceAddress('c.f.D'))])
    def test_get_subns_addr(self):
        # Signature: name(self, component_name)
                # Returns the address of a subcomponent at this address.
                #
                # For example:
                #
                # >>> a = NamespaceAddress('level1.level2.level3')
                # >>> a.get_subns_addr('subcomponent')
                # NameSpaceAddress: '/level1/level2/level3/subcomponent/'

        d = ComponentClass(name='D',)
        e = ComponentClass(name='E')
        f = ComponentClass(name='F')
        g = ComponentClass(name='G')
        b = ComponentClass(name='B', subnodes={'atD': d, 'atE': e})
        c = ComponentClass(name='C', subnodes={'atF': f, 'atG': g})
        a = ComponentClass(name='A', subnodes={'atB': b, 'atC': c})

        # Construction of the objects causes cloning to happen:
        # Therefore we test by looking up and checking that there
        # are the correct component names:
        bNew = a.get_subnode('atB')
        cNew = a.get_subnode('atC')
        dNew = a.get_subnode('atB.atD')
        eNew = a.get_subnode('atB.atE')
        fNew = a.get_subnode('atC.atF')
        gNew = a.get_subnode('atC.atG')

        self.assertEquals(
            gNew.get_node_addr().get_subns_addr('MyObject1'),
            NSA('atC.atG.MyObject1')
        )

        self.assertEquals(
            eNew.get_node_addr().get_subns_addr('MyObject2'),
            NSA('atB.atE.MyObject2')
        )

        self.assertEquals(
            bNew.get_node_addr().get_subns_addr('MyObject3'),
            NSA('atB.MyObject3')
        )
Beispiel #4
0
    def test_get_subns_addr(self):
        # Signature: name(self, component_name)
        # Returns the address of a subcomponent at this address.
        #
        # For example:
        #
        # >>> a = NamespaceAddress('level1.level2.level3')
        # >>> a.get_subns_addr('subcomponent')
        # NameSpaceAddress: '/level1/level2/level3/subcomponent/'

        d = ComponentClass(name='D', )
        e = ComponentClass(name='E')
        f = ComponentClass(name='F')
        g = ComponentClass(name='G')
        b = ComponentClass(name='B', subnodes={'atD': d, 'atE': e})
        c = ComponentClass(name='C', subnodes={'atF': f, 'atG': g})
        a = ComponentClass(name='A', subnodes={'atB': b, 'atC': c})

        # Construction of the objects causes cloning to happen:
        # Therefore we test by looking up and checking that there
        # are the correct component names:
        bNew = a.get_subnode('atB')
        cNew = a.get_subnode('atC')
        dNew = a.get_subnode('atB.atD')
        eNew = a.get_subnode('atB.atE')
        fNew = a.get_subnode('atC.atF')
        gNew = a.get_subnode('atC.atG')

        self.assertEquals(gNew.get_node_addr().get_subns_addr('MyObject1'),
                          NSA('atC.atG.MyObject1'))

        self.assertEquals(eNew.get_node_addr().get_subns_addr('MyObject2'),
                          NSA('atB.atE.MyObject2'))

        self.assertEquals(bNew.get_node_addr().get_subns_addr('MyObject3'),
                          NSA('atB.MyObject3'))
    def test_recurse_all_components(self):
        # Signature: name
                # Returns an iterator over this component and all subcomponents


        d = ComponentClass(name='D')
        e = ComponentClass(name='E')
        f = ComponentClass(name='F')
        g = ComponentClass(name='G')

        b = ComponentClass(name='B')
        b.insert_subnode(namespace='d', subnode=d)
        b.insert_subnode(namespace='e', subnode=e)

        c = ComponentClass(name='C')
        c.insert_subnode(namespace='f', subnode=f)
        c.insert_subnode(namespace='g', subnode=g)

        a = ComponentClass(name='A')
        a.insert_subnode(namespace='b', subnode=b)
        a.insert_subnode(namespace='c', subnode=c)

        # Construction of the objects causes cloning to happen:
        # Therefore we test by looking up and checking that there
        # are the correct component names:
        bNew = a.get_subnode('b')
        cNew = a.get_subnode('c')
        dNew = a.get_subnode('b.d')
        eNew = a.get_subnode('b.e')
        fNew = a.get_subnode('c.f')
        gNew = a.get_subnode('c.g')

        self.assertEquals(
            set(a.query.recurse_all_components),
            set([a, bNew, cNew, dNew, eNew, fNew, gNew]))
        self.assertEquals(
            set(bNew.query.recurse_all_components),
            set([bNew, dNew, eNew]))
        self.assertEquals(
            set(cNew.query.recurse_all_components),
            set([cNew, fNew, gNew]))
        self.assertEquals(
            set(dNew.query.recurse_all_components),
            set([dNew]))
        self.assertEquals(
            set(eNew.query.recurse_all_components),
            set([eNew]))
        self.assertEquals(
            set(fNew.query.recurse_all_components),
            set([fNew]))
        self.assertEquals(
            set(gNew.query.recurse_all_components),
            set([gNew]))
    def test_recurse_all_components(self):
        # Signature: name
        # Returns an iterator over this component and all subcomponents

        d = ComponentClass(name='D')
        e = ComponentClass(name='E')
        f = ComponentClass(name='F')
        g = ComponentClass(name='G')

        b = ComponentClass(name='B')
        b.insert_subnode(namespace='d', subnode=d)
        b.insert_subnode(namespace='e', subnode=e)

        c = ComponentClass(name='C')
        c.insert_subnode(namespace='f', subnode=f)
        c.insert_subnode(namespace='g', subnode=g)

        a = ComponentClass(name='A')
        a.insert_subnode(namespace='b', subnode=b)
        a.insert_subnode(namespace='c', subnode=c)

        # Construction of the objects causes cloning to happen:
        # Therefore we test by looking up and checking that there
        # are the correct component names:
        bNew = a.get_subnode('b')
        cNew = a.get_subnode('c')
        dNew = a.get_subnode('b.d')
        eNew = a.get_subnode('b.e')
        fNew = a.get_subnode('c.f')
        gNew = a.get_subnode('c.g')

        self.assertEquals(set(a.query.recurse_all_components),
                          set([a, bNew, cNew, dNew, eNew, fNew, gNew]))
        self.assertEquals(set(bNew.query.recurse_all_components),
                          set([bNew, dNew, eNew]))
        self.assertEquals(set(cNew.query.recurse_all_components),
                          set([cNew, fNew, gNew]))
        self.assertEquals(set(dNew.query.recurse_all_components), set([dNew]))
        self.assertEquals(set(eNew.query.recurse_all_components), set([eNew]))
        self.assertEquals(set(fNew.query.recurse_all_components), set([fNew]))
        self.assertEquals(set(gNew.query.recurse_all_components), set([gNew]))