Exemplo n.º 1
0
    def test_widget_factory_b(self):

        import test_widgets_b

        self.assertTrue('MyWidget_C' in widgetFactory.get_widget_names())
        self.assertTrue('MyWidget_D' in widgetFactory.get_widget_names())

        sw = StringWriter()
        assembly = Assembly(sw)

        widgetFactory.get('MyWidget_C')(assembly,
                                        assembly.model({}, 'MyWidget_C'), {},
                                        last=True)
        ex = StringWriter()
        ex.write('Widget C\n')
        ex.write('  Attr1: None\n')
        ex.write('  Attr2: None\n')
        ex.write('End widget C\n')
        self.assertEqual(ex.__str__(), sw.__str__())

        sw = StringWriter()
        assembly = Assembly(sw)
        assembly._indent_str = '    '
        widgetFactory.get('MyWidget_D')(assembly,
                                        assembly.model({}, 'MyWidget_D'), {},
                                        last=True)
        ex = StringWriter()
        ex.write('Widget D\n')
        ex.write('    Attr1: None\n')
        ex.write('    Attr2: None\n')
        ex.write('End widget D\n')
        self.assertEqual(ex.__str__(), sw.__str__())

        sw = StringWriter()
        assembly = Assembly(sw)
        assembly._indent_str = '    '
        testA = TestClassA(attr1='a1', attr2='a2', attr3='a3', attr4='a4')
        widgetFactory.get('MyWidget_D')(assembly,
                                        assembly.model(testA, 'MyWidget_D'),
                                        {},
                                        last=True)
        ex = StringWriter()
        ex.write('Widget D\n')
        ex.write('    Attr1: a1\n')
        ex.write('    Attr2: a2\n')
        ex.write('End widget D\n')
        self.assertEqual(ex.__str__(), sw.__str__())
Exemplo n.º 2
0
    def test_widget_factory_a(self):

        import test_widgets_a

        sw = StringWriter()
        assembly = Assembly(sw)

        self.assertTrue(
            'MyWidget_A' in assembly.widgetFactory.get_widget_names())
        self.assertTrue(
            'MyWidget_B' in assembly.widgetFactory.get_widget_names())

        self.assertEqual(['attr2', 'attr3', 'attr4', 'attr5'],
                         assembly.widgetFactory.get_attributes('MyWidget_A'))
        self.assertEqual(['attr1', 'attr2', 'attr3', 'attr4'],
                         assembly.widgetFactory.get_attributes('MyWidget_B'))

        assembly.get_widget('MyWidget_A')(assembly,
                                          assembly.model({}, 'MyWidget_A'), {},
                                          last=True)
        ex = StringWriter()
        ex.write('aaa\n')
        ex.write('  bbb\n')
        ex.write('  bbb\n')
        ex.write('    ccc\n')
        ex.write('    ccc\n')
        ex.write('  bbb\n')
        ex.write('  bbb\n')
        ex.write('aaa\n')
        self.assertEqual(ex.__str__(), sw.__str__())

        sw = StringWriter()
        assembly = Assembly(sw)
        assembly._indent_str = '    '
        assembly.get_widget('MyWidget_B')(assembly,
                                          assembly.model({}, 'MyWidget_B'), {},
                                          last=True)
        ex = StringWriter()
        ex.write('AAA\n')
        ex.write('    BBB\n')
        ex.write('    BBB\n')
        ex.write('        CCC\n')
        ex.write('        CCC\n')
        ex.write('    BBB\n')
        ex.write('    BBB\n')
        ex.write('AAA\n')
        self.assertEqual(ex.__str__(), sw.__str__())