예제 #1
0
    def getPossibleConverters(self):
        """Get a Dictionary ot available Converters."""
        try:
            diagramTypes = Registry.getKind(self.graphname()).registration()
        except RuntimeError:
            diagramTypes = []
        ret = [{
            'name':
            ' ',
            'sources': [{
                'name': ' ',
                'converters': [{
                    'name': _useDefaultConverter
                }]
            }]
        }]

        for dt in diagramTypes:
            sources = []
            for source in ICRegistry.getSources(dt.name):
                converters = [{
                    'name': conv
                } for conv in ICRegistry.getConverters(dt.name, source)]
                sources.append({'name': source, 'converters': converters})
            ret.append({'name': dt.name, 'sources': sources})
        return ret
예제 #2
0
    def test_6register(self):
        """Test register(converter)."""
        d1 = DiagramType1.name
        d2 = DiagramType2.name
        s1 = DataSource1.name
        s2 = DataSource2.name
        n = NoConverter
        c1 = Converter1
        c2 = Converter2
        c3 = Converter3
        c4 = Converter4
        c42 = Converter4
        c5 = Converter5

        ICRegistry._clear()
        self.assertRaises(RuntimeError, ICRegistry.register, n)
        self.failUnless(ICRegistry.register(c1), 'reg c1')
        self.assertEqual([], ICRegistry.getTypes(), 'get c1')
        self.assertRaises(RuntimeError, ICRegistry.register, c2)
        self.assertRaises(RuntimeError, ICRegistry.register, c3)
        self.failUnless(ICRegistry.register(c4), 'reg c4')
        self.assertEqual([d1], ICRegistry.getTypes(), 'get c4 typ')
        self.assertEqual([s1], ICRegistry.getSources(d1), 'get c4 src')
        self.assertEqual([c4.name], ICRegistry.getConverters(d1, s1),
                         'get c4 conv')
        self.assertRaises(RuntimeError, ICRegistry.register, c4)
        self.assertRaises(RuntimeError, ICRegistry.register, c42)
        self.assertEqual([d1], ICRegistry.getTypes(), 'get c4 typ 3rd')
        self.assertEqual([s1], ICRegistry.getSources(d1), 'get c4 src 3rd')
        self.assertEqual([c4.name], ICRegistry.getConverters(d1, s1),
                         'get c4 conv 3rd')
        self.failUnless(ICRegistry.register(c5), 'reg c5')
        self.assertEqual([d1, d2], ICRegistry.getTypes(), 'get c5 typ')
        res = ICRegistry.getSources(d1)
        res.sort()
        self.assertEqual([s1, s2], res, 'get c5 d1 src')
        self.assertEqual([s2], ICRegistry.getSources(d2), 'get c5 d2 src')
        self.assertEqual([c4.name, c5.name], ICRegistry.getConverters(d1, s1),
                         'get c5 d1s1 conv')
        self.assertEqual([c5.name], ICRegistry.getConverters(d1, s2),
                         'get c5 d1s2 conv')
예제 #3
0
    def test_4_registerSource(self):
        """Test of _registerSource(...) and getSource(...)"""
        d = DiagramType1
        e = DiagramType2
        n = NoDataSource
        a = DataSource1
        b = DataSource1
        c = DataSource2

        ICRegistry._clear()

        self.assertEqual([], ICRegistry.getSources(d.name),
                         'get from empty Registry')
        self.failUnless(ICRegistry._registerType(d))
        self.assertEqual([], ICRegistry.getSources(d.name),
                         'get from empty Type')
        self.assertEqual([], ICRegistry.getSources(e.name),
                         'get from not registered Type')
        self.assertRaises(RuntimeError, ICRegistry._registerSource, d, n)
        self.failUnless(ICRegistry._registerSource(d, a), 'reg one')
        self.failIf(ICRegistry._registerSource(d, a), 'reg one 2nd time')
        self.failIf(ICRegistry._registerSource(d, b), 'reg one 3rd time')
        self.assertEqual([a.name], ICRegistry.getSources(d.name), 'get one')
        self.assertEqual([a.name], ICRegistry.getSources(d.name), 'get one2')
        self.assertEqual([], ICRegistry.getSources(e.name),
                         'get not registered Type 2')
        self.failUnless(ICRegistry._registerSource(e, a), 'reg two two')
        self.failIf(ICRegistry._registerSource(e, a), 'reg two two 2nd')
        self.failIf(ICRegistry._registerSource(e, b), 'reg two two 3rd')
        self.assertEqual([a.name], ICRegistry.getSources(e.name), 'get two')
        self.assertEqual([a.name], ICRegistry.getSources(e.name), 'get two2')
        self.assertEqual([a.name], ICRegistry.getSources(d.name), 'get one3')
        self.failUnless(ICRegistry._registerSource(d, c), 'reg tri')
        self.failIf(ICRegistry._registerSource(d, c), 'reg tri 2nd')
        res1 = ICRegistry.getSources(d.name)
        res1.sort()
        self.assertEqual([a.name, c.name], res1, 'get tri %s' % res1)
        res2 = ICRegistry.getSources(d.name)
        res2.sort()
        self.assertEqual([a.name, c.name], res2, 'get tri2')
        self.assertEqual([a.name], ICRegistry.getSources(e.name), 'get two3')