Ejemplo n.º 1
0
    def test_5_registerConverter(self):
        """Test _registerConverter(...) and getConverters(...)."""
        d1 = DiagramType1
        d2 = DiagramType2
        s1 = DataSource1
        s2 = DataSource2
        n = NoConverter
        a = Converter1
        b = Converter1
        c = Converter2

        ICRegistry._clear()
        self.assertEqual([], ICRegistry.getConverters(d1.name, s1.name),
                         'get empty reg')
        self.failUnless(ICRegistry._registerType(d1))
        self.assertEqual([], ICRegistry.getConverters(d1.name, s1.name),
                         'get empty type')
        self.failUnless(ICRegistry._registerSource(d1, s1))
        self.assertEqual([], ICRegistry.getConverters(d1.name, s1.name),
                         'get empty src')
        self.assertRaises(RuntimeError, ICRegistry._registerConverter, d2, s1,
                          n)
        self.failUnless(ICRegistry._registerConverter(d2, s1, a), 'reg 21a')
        self.failIf(ICRegistry._registerConverter(d2, s1, a), 'reg 21a 2nd')
        self.failIf(ICRegistry._registerConverter(d2, s1, b), 'reg 21a 3rd')
        self.assertEqual([], ICRegistry.getConverters(d1.name, s1.name),
                         'get empty src2')
        self.assertEqual([a.name], ICRegistry.getConverters(d2.name, s1.name),
                         'get 21')
        self.assertEqual([a.name], ICRegistry.getConverters(d2.name, s1.name),
                         'get 21 2nd')
        self.failUnless(ICRegistry._registerConverter(d2, s2, a), 'reg 22a')
        self.failIf(ICRegistry._registerConverter(d2, s2, a), 'reg 22a 2nd')
        self.failUnless(ICRegistry._registerConverter(d1, s2, a), 'reg 12a')
        self.assertEqual([a.name], ICRegistry.getConverters(d2.name, s1.name),
                         'get 21 3rd')
        self.failUnless(ICRegistry._registerConverter(d2, s1, c), 'reg 21c')
        self.assertEqual([a.name, c.name],
                         ICRegistry.getConverters(d2.name, s1.name),
                         'get 21 4th')
        self.assertEqual([a.name], ICRegistry.getConverters(d1.name, s2.name),
                         'get 12')
        self.assertEqual([], ICRegistry.getConverters(d1.name, s1.name),
                         'get 11')
Ejemplo n.º 2
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')