Пример #1
0
    def test_interface_ports(self):
        # Selector with multiple levels:
        i = Interface('/foo[0:4]')
        i['/foo[0:2]', 'interface'] = 0
        i['/foo[2:4]', 'interface'] = 1
        j = Interface('/foo[2:4]')
        j['/foo[2:4]', 'interface'] = 1

        # Test returning result as Interface:
        assert_frame_equal(i.interface_ports(1).data, j.data)

        # Test returning result as list of tuples:
        self.assertItemsEqual(i.interface_ports(1, True),
                              j.data.index.tolist())

        # Selector with single level:
        i = Interface('/[foo,bar,baz]')
        i['/[foo,bar]', 'interface'] = 0
        i['/baz', 'interface'] = 1
        j = Interface('/baz')
        j['/baz', 'interface'] = 1

        # Test returning result as Interface:
        assert_frame_equal(i.interface_ports(1).data, j.data)

        # Test returning result as list of tuples:
        self.assertItemsEqual(i.interface_ports(1, True),
                              j.data.index.tolist())
Пример #2
0
    def test_out_ports(self):
        # Selector with multiple levels:
        i = Interface('/foo[0:2]')
        i['/foo[0]'] = [0, 'in', 'spike']
        i['/foo[1]'] = [1, 'out', 'spike']
        df = pd.DataFrame([(1, 'out', 'spike')],
                          pd.MultiIndex.from_tuples([('foo', 1)],
                                                    names=['0', '1']),
                          ['interface', 'io', 'type'],
                          dtype=object)

        # Test returning result as Interface:
        assert_frame_equal(i.out_ports(1).data, df)

        # Test returning result as list of tuples:
        self.assertItemsEqual(i.out_ports(1, True), df.index.tolist())

        # Selector with single level:
        i = Interface('/[foo,bar]')
        i['/foo'] = [0, 'in', 'spike']
        i['/bar'] = [1, 'out', 'spike']
        df = pd.DataFrame([(1, 'out', 'spike')],
                          pd.MultiIndex.from_tuples([('bar', )], names=['0']),
                          ['interface', 'io', 'type'],
                          dtype=object)

        # Test returning result as Interface:
        assert_frame_equal(i.out_ports(1).data, df)

        # Test returning result as list of tuples:
        self.assertItemsEqual(i.out_ports(1, True), df.index.tolist())
Пример #3
0
    def test_to_selectors(self):
        # Selector with multiple levels:
        i = Interface('/foo[0:4]')
        i['/foo[0:2]', 'interface'] = 0
        i['/foo[2:4]', 'interface'] = 1
        self.assertSequenceEqual(i.to_selectors(0),
                                 ['/foo[0]',
                                  '/foo[1]'])
        self.assertSequenceEqual(i.to_selectors(),
                                 ['/foo[0]',
                                  '/foo[1]',
                                  '/foo[2]',
                                  '/foo[3]'])

        # Selector with single level:
        i = Interface('/[foo,bar,baz]')
        i['/foo', 'interface'] = 0
        i['/bar', 'interface'] = 0
        i['/baz', 'interface'] = 1
        self.assertSequenceEqual(i.to_selectors(0),
                                 ['/foo', 
                                  '/bar'])
        self.assertSequenceEqual(i.to_selectors(), 
                                 ['/foo', 
                                  '/bar',
                                  '/baz'])
Пример #4
0
 def test_io_inv(self):
     i = Interface('/foo[0:4]')
     i['/foo[0:2]', 'interface', 'io'] = [0, 'out']
     i['/foo[2:4]', 'interface', 'io'] = [1, 'in']
     j = Interface('/foo[0:4]')
     j['/foo[0:2]', 'interface', 'io'] = [0, 'in']
     j['/foo[2:4]', 'interface', 'io'] = [1, 'out']
     assert_frame_equal(i.data, j.io_inv.data)
Пример #5
0
 def test_is_compatible_with_nulls_types(self):
     i = Interface('/foo[0:3]')
     i['/foo[0:2]'] = [0, 'out', 'gpot']
     i['/foo[2]', 'interface'] = 0
     j = Interface('/foo[0:3]')
     j['/foo[0:2]'] = [1, 'in', 'gpot']
     j['/foo[2]', 'interface'] = 1
     assert i.is_compatible(0, j, 1)
Пример #6
0
 def test_is_compatible_both_dirs_types(self):
     i = Interface('/foo[0:4]')
     i['/foo[0:2]'] = [0, 'out', 'gpot']
     i['/foo[2:4]'] = [0, 'in', 'spike']
     j = Interface('/foo[0:4]')
     j['/foo[0:2]'] = [1, 'in', 'gpot']
     j['/foo[2:4]'] = [1, 'out', 'spike']
     assert i.is_compatible(0, j, 1)
Пример #7
0
 def test_is_compatible_both_dirs(self):
     i = Interface('/foo[0:4]')
     i['/foo[0:2]', 'interface', 'io'] = [0, 'out']
     i['/foo[2:4]', 'interface', 'io'] = [0, 'in']
     j = Interface('/foo[0:4]')
     j['/foo[0:2]', 'interface', 'io'] = [1, 'in']
     j['/foo[2:4]', 'interface', 'io'] = [1, 'out']
     assert i.is_compatible(0, j, 1)
Пример #8
0
 def test_interface_ports(self):
     i = Interface('/foo[0:4]')
     i['/foo[0:2]', 'interface'] = 0
     i['/foo[2:4]', 'interface'] = 1
     j = Interface('/foo[2:4]')
     j['/foo[2:4]', 'interface'] = 1
     assert_frame_equal(i.interface_ports(1).data, j.data)
     assert_index_equal(i.interface_ports(1).index, j.index)
Пример #9
0
 def test_spike_ports(self):
     i = Interface('/foo[0:6]')
     i['/foo[0]'] = [0, 'in', 'spike']
     i['/foo[1:3]'] = [0, 'out', 'spike']
     i['/foo[3]'] = [0, 'in', 'gpot']
     i['/foo[4:6]'] = [0, 'out', 'gpot']
     j = Interface('/foo[0:3]')
     j['/foo[0]'] = [0, 'in', 'spike']
     j['/foo[1:3]'] = [0, 'out', 'spike']
     assert_frame_equal(i.spike_ports(0).data, j.data)
     assert_index_equal(i.spike_ports(0).index, j.index)
Пример #10
0
    def test_is_compatible_both_dirs(self):
        """
        It should be possible to define compatible interfaces containing both
        input and output ports.
        """

        i = Interface('/foo[0:4]')
        i['/foo[0:2]', 'interface', 'io'] = [0, 'out']
        i['/foo[2:4]', 'interface', 'io'] = [0, 'in']
        j = Interface('/foo[0:4]')
        j['/foo[0:2]', 'interface', 'io'] = [1, 'in']
        j['/foo[2:4]', 'interface', 'io'] = [1, 'out']
        assert i.is_compatible(0, j, 1)
Пример #11
0
    def test_is_compatible_both_dirs_types(self):
        """
        It should be possible to define compatible interfaces containing both
        input and output ports with specified types.
        """

        i = Interface('/foo[0:4]')
        i['/foo[0:2]'] = [0, 'out', 'gpot']
        i['/foo[2:4]'] = [0, 'in', 'spike']
        j = Interface('/foo[0:4]')
        j['/foo[0:2]'] = [1, 'in', 'gpot']
        j['/foo[2:4]'] = [1, 'out', 'spike']
        assert i.is_compatible(0, j, 1)
Пример #12
0
    def test_is_compatible_with_nulls(self):
        """
        Interfaces can be compatible even if some of their ports do not have a
        set input or output status.
        """

        i = Interface('/foo[0:3]')
        i['/foo[0:2]', 'interface', 'io'] = [0, 'out']
        i['/foo[2]', 'interface'] = 0
        j = Interface('/foo[0:3]')
        j['/foo[0:2]', 'interface', 'io'] = [1, 'in']
        j['/foo[2]', 'interface'] = 1
        assert i.is_compatible(0, j, 1)
Пример #13
0
    def test_is_compatible_with_nulls_types(self):
        """
        Interfaces can be compatible even if some of their ports do not have a
        set type.
        """

        i = Interface('/foo[0:3]')
        i['/foo[0:2]'] = [0, 'out', 'gpot']
        i['/foo[2]', 'interface'] = 0
        j = Interface('/foo[0:3]')
        j['/foo[0:2]'] = [1, 'in', 'gpot']
        j['/foo[2]', 'interface'] = 1
        assert i.is_compatible(0, j, 1)
Пример #14
0
    def test_get_common_ports_unequal_num_levels(self):
        # Without type, some with only one level:
        i = Interface('/foo[0:6],/bar')
        i['/*', 'interface'] = 0
        j = Interface('/bar,/baz')
        j['/*', 'interface'] = 0
        assert i.get_common_ports(0, j, 0, 'spike') == []
        self.assertItemsEqual(i.get_common_ports(0, j, 0), [('bar', )])

        # Without type, more than one level:
        i = Interface('/foo[0:6],/bar[0:2]/baz')
        i['/*', 'interface'] = 0
        j = Interface('/foo[3:9]')
        j['/*', 'interface'] = 0
        assert i.get_common_ports(0, j, 0, 'spike') == []
        self.assertItemsEqual(i.get_common_ports(0, j, 0), [('foo', 3),
                                                            ('foo', 4),
                                                            ('foo', 5)])

        # With type, some with only one level:
        i = Interface('/foo[0:6],/bar,/baz')
        i['/foo[3,4],/bar', 'interface', 'type'] = [0, 'spike']
        j = Interface('/bar,/baz,/qux')
        j['/bar,/baz', 'interface', 'type'] = [0, 'spike']
        self.assertItemsEqual(i.get_common_ports(0, j, 0, 'spike'),
                              [('bar', )])

        # With type, more than one level:
        i = Interface('/foo[0:6],/bar[0:2]/baz')
        i['/foo[3,4]', 'interface', 'type'] = [0, 'spike']
        j = Interface('/foo[3:9]')
        j['/foo[3,4]', 'interface', 'type'] = [0, 'spike']
        self.assertItemsEqual(i.get_common_ports(0, j, 0, 'spike'),
                              [('foo', 3), ('foo', 4)])
Пример #15
0
    def test_get_common_ports(self):
        # Without type, single level:
        i = Interface('/foo,/bar,/baz')
        i['/*', 'interface'] = 0
        j = Interface('/bar,/baz,/qux')
        j['/*', 'interface'] = 0
        assert i.get_common_ports(0, j, 0, 'spike') == []
        self.assertItemsEqual(i.get_common_ports(0, j, 0), [('bar', ),
                                                            ('baz', )])

        # Without type, multiple levels:
        i = Interface('/foo[0:6]')
        i['/*', 'interface'] = 0
        j = Interface('/foo[3:9]')
        j['/*', 'interface'] = 0
        assert i.get_common_ports(0, j, 0, 'spike') == []
        self.assertItemsEqual(i.get_common_ports(0, j, 0), [('foo', 3),
                                                            ('foo', 4),
                                                            ('foo', 5)])

        # With type, single level:
        i = Interface('/foo,/bar,/baz')
        i['/foo,/bar', 'interface', 'type'] = [0, 'spike']
        j = Interface('/bar,/baz,/qux')
        j['/bar,/baz', 'interface', 'type'] = [0, 'spike']
        self.assertItemsEqual(i.get_common_ports(0, j, 0, 'spike'),
                              [('bar', )])

        # With type, multiple levels:
        i = Interface('/foo[0:6]')
        i['/foo[3,4]', 'interface', 'type'] = [0, 'spike']
        j = Interface('/foo[3:9]')
        j['/foo[3,4]', 'interface', 'type'] = [0, 'spike']
        self.assertItemsEqual(i.get_common_ports(0, j, 0, 'spike'),
                              [('foo', 3), ('foo', 4)])
Пример #16
0
    def test_spike_ports(self):
        i = Interface('/foo[0:6]')
        i['/foo[0]'] = [0, 'in', 'spike']
        i['/foo[1:3]'] = [0, 'out', 'spike']
        i['/foo[3]'] = [0, 'in', 'gpot']
        i['/foo[4:6]'] = [0, 'out', 'gpot']
        j = Interface('/foo[0:3]')
        j['/foo[0]'] = [0, 'in', 'spike']
        j['/foo[1:3]'] = [0, 'out', 'spike']

        # Return result as Interface:
        assert_frame_equal(i.spike_ports(0).data, j.data)

        # Test returning result as list of tuples:
        self.assertItemsEqual(i.spike_ports(0, True), j.data.index.tolist())
Пример #17
0
 def test_equals(self):
     i = Interface('/foo[0:2],/bar[0:2]')
     i['/foo[0]'] = [0, 'in', 'gpot']
     i['/bar[0]'] = [0, 'out', 'gpot']
     i['/foo[1]'] = [1, 'in', 'spike']
     i['/bar[1]'] = [1, 'out', 'spike']
     j = Interface('/foo[0:2],/bar[0:2]')
     j['/foo[0]'] = [0, 'in', 'gpot']
     j['/bar[0]'] = [0, 'out', 'gpot']
     j['/foo[1]'] = [1, 'in', 'spike']
     j['/bar[1]'] = [1, 'out', 'spike']
     assert i.equals(j)
     assert j.equals(i)
     j['/foo[0]'] = [0, 'in', 'spike']
     assert not i.equals(j)
     assert not j.equals(i)
Пример #18
0
    def test_is_compatible_subsets_with_null_types(self):
        """
        Interfaces that both share a subset of compatible ports can be deemed
        compatible by setting the `allow_subsets` option of the compatibility
        test even when the types are null.
        """

        i = Interface('/foo[0:6]')
        i['/foo[0:3]'] = [0, 'out']
        i['/foo[3:6]'] = [0, 'out']
        j = Interface('/foo[0:6]')
        j['/foo[0:2]'] = [1, 'in']
        j['/foo[3:5]'] = [1, 'in']
        k = Interface('/foo[0:6]')
        assert i.is_compatible(0, j, 1, True)
        assert i.is_compatible(0, k, 1, True) == False
Пример #19
0
 def test_to_tuples_multi_levels(self):
     i = Interface('/foo[0:4]')
     i['/foo[0:2]', 'interface'] = 0
     i['/foo[2:4]', 'interface'] = 1
     self.assertSequenceEqual(i.to_tuples(0), [('foo', 0), ('foo', 1)])
     self.assertSequenceEqual(i.to_tuples(), [('foo', 0), ('foo', 1),
                                              ('foo', 2), ('foo', 3)])
Пример #20
0
 def test_which_int_set(self):
     i = Interface('/foo[0:4]')
     i['/foo[0]', 'interface', 'io'] = [0, 'out']
     i['/foo[1]', 'interface', 'io'] = [0, 'in']
     i['/foo[2]', 'interface', 'io'] = [1, 'in']
     i['/foo[3]', 'interface', 'io'] = [1, 'out']
     assert i.which_int('/foo[0:2]') == {0}
     assert i.which_int('/foo[0:4]') == {0, 1}
Пример #21
0
 def test_to_tuples_single_level(self):
     i = Interface('[0:4]')
     i['[0:2]', 'interface'] = 0
     i['[2:4]', 'interface'] = 1
     self.assertSequenceEqual(i.to_tuples(0),
                              [(0,), (1,)])
     self.assertSequenceEqual(i.to_tuples(),
                              [(0,), (1,), (2,), (3,)])
Пример #22
0
    def test_to_tuples(self):
        i = Interface('/foo[0:4]')
        i['/foo[0:2]', 'interface'] = 0
        i['/foo[2:4]', 'interface'] = 1
        self.assertSequenceEqual(i.to_tuples(0),
                                 [('foo', 0), 
                                  ('foo', 1)])
        self.assertSequenceEqual(i.to_tuples(), 
                                 [('foo', 0), 
                                  ('foo', 1),
                                  ('foo', 2),
                                  ('foo', 3)])

        i = Interface('[0:4]')
        i['[0:2]', 'interface'] = 0
        i['[2:4]', 'interface'] = 1
        self.assertSequenceEqual(i.to_tuples(0),
                                 [(0,), (1,)])
        self.assertSequenceEqual(i.to_tuples(),
                                 [(0,), (1,), (2,), (3,)])
Пример #23
0
 def test_to_selectors(self):
     i = Interface('/foo[0:4]')
     i['/foo[0:2]', 'interface'] = 0
     i['/foo[2:4]', 'interface'] = 1
     self.assertSequenceEqual(i.to_selectors(0),
                              ['/foo[0]', 
                               '/foo[1]'])
     self.assertSequenceEqual(i.to_selectors(), 
                              ['/foo[0]', 
                               '/foo[1]',
                               '/foo[2]',
                               '/foo[3]'])
Пример #24
0
 def test_from_graph(self):
     i = Interface('/foo[0:3]')
     i['/foo[0]'] = [0, 'in', 'gpot']
     i['/foo[1]'] = [0, 'out', 'gpot']
     i['/foo[2]'] = [0, 'out', 'spike']
     g = nx.Graph()
     g.add_node('/foo[0]', interface=0, io='in', type='gpot')
     g.add_node('/foo[1]', interface=0, io='out', type='gpot')
     g.add_node('/foo[2]', interface=0, io='out', type='spike')
     ig = Interface.from_graph(g)
     assert_index_equal(i.data.index, ig.data.index)
     assert_frame_equal(i.data, ig.data)
Пример #25
0
    def test_data_select(self):
        # Selector with multiple levels:
        i = Interface('/foo[0:3]')
        i['/foo[0]', 'interface', 'io'] = [0, 'in']
        i['/foo[1:3]', 'interface', 'io'] = [0, 'out']
        j = i.data_select(lambda x: x['io'] != 'in')
        assert_index_equal(j.data.index,
                           pd.MultiIndex.from_tuples([('foo', 1), ('foo', 2)]))

        # Selector with single level:
        i = Interface('/[foo,bar,baz]')
        i['/[foo,bar]', 'interface', 'io'] = [0, 'in']
        i['/baz', 'interface', 'io'] = [0, 'out']
        j = i.data_select(lambda x: x['io'] != 'in')
        assert_index_equal(j.data.index, pd.Index(['baz']))

        # Selectors with different numbers of levels:
        i = Interface('/a/b/c,/x/y')
        i['/a/b/c', 'interface', 'io'] = [0, 'in']
        j = i.data_select(lambda x: x['io'] != 'in')
        assert_index_equal(j.data.index,
                           pd.MultiIndex.from_tuples([('x', 'y', '')]))
Пример #26
0
    def test_is_compatible_sel_order(self):
        """
        Interfaces with individually compatible ports that are ordered in
        different ways should still be deemed compatible.
        """

        # Selectors with multiple levels:
        i = Interface('/foo[0:2],/bar[0:2]')
        i['/foo[0:2]', 'interface', 'io'] = [0, 'in']
        i['/bar[0:2]', 'interface', 'io'] = [0, 'out']
        j = Interface('/bar[0:2],/foo[0:2]')
        j['/bar[0:2]', 'interface', 'io'] = [1, 'in']
        j['/foo[0:2]', 'interface', 'io'] = [1, 'out']
        assert i.is_compatible(0, j, 1)

        # Selectors with single level:
        i = Interface('/foo,/bar,/baz,/qux')
        i['/[foo,bar]', 'interface', 'io'] = [0, 'in']
        i['/[baz,qux]', 'interface', 'io'] = [0, 'out']
        j = Interface('/bar,/foo,/qux,/baz')
        j['/[baz,qux]', 'interface', 'io'] = [1, 'in']
        j['/[foo,bar]', 'interface', 'io'] = [1, 'out']
        assert i.is_compatible(0, j, 1)
Пример #27
0
    def test_is_in_interfaces(self):
        # Selector with multiple levels:
        i = Interface('/foo[0:3]')
        i['/foo[0]', 'interface', 'io'] = [0, 'in']
        i['/foo[1:3]', 'interface', 'io'] = [0, 'out']
        assert i.is_in_interfaces('/foo[0:3]') == True
        assert i.is_in_interfaces('/foo[0:4]') == False
        assert i.is_in_interfaces('/foo') == False

        # Selector with single level:
        i = Interface('/[foo,bar]')
        i['/foo', 'interface', 'io'] = [0, 'in']
        i['/bar', 'interface', 'io'] = [1, 'out']
        assert i.is_in_interfaces('/foo') == True
        assert i.is_in_interfaces('/qux') == False

        # Selectors comprising identifiers with different numbers of levels
        i = Interface('/foo,/bar[0:3]')
        i['/foo', 'interface', 'io'] = [0, 'in']
        i['/bar[0:3]', 'interface', 'io'] = [1, 'out']
        assert i.is_in_interfaces('/foo') == True
        assert i.is_in_interfaces('/bar[0]') == True
        assert i.is_in_interfaces('/bar') == False
Пример #28
0
 def test_which_int_unset(self):
     i = Interface('/foo[0:4]')
     assert i.which_int('/foo[0:2]') == set()
Пример #29
0
 def test_is_compatible_one_dir_types(self):
     i = Interface('/foo[0:2]')
     i['/foo[0:2]'] = [0, 'out', 'spike']
     j = Interface('/foo[0:2]')
     j['/foo[0:2]'] = [1, 'in', 'spike']
     assert i.is_compatible(0, j, 1)
Пример #30
0
 def test_interface_ids(self):
     i = Interface('/foo[0:4]')
     i['/foo[0:2]', 'interface', 'io'] = [0, 'out']
     i['/foo[2:4]', 'interface', 'io'] = [1, 'in']
     assert i.interface_ids == set([0, 1])