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

        import test_widgets_c

        sw = StringWriter()
        assembly = Assembly(sw)

        widgetFactory.get('MyAssembly_B')(assembly,
                                          assembly.model({}, 'MyAssembly_B'),
                                          {})
        ex = StringWriter()
        ex.write('Widget E\n')
        ex.write('Attr1: \n')
        ex.write('Attr2: \n')
        ex.write('Container A [\n')
        ex.write('  aaa\n')
        ex.write('  aaa\n')
        ex.write('  aaa\n')
        ex.write('  ,\n')
        ex.write('  bbb\n')
        ex.write('  bbb\n')
        ex.write('  bbb\n')
        ex.write('] Container A\n')
        ex.write('Container B [\n')
        ex.write('] Container B\n')
        ex.write('End widget E\n')

        self.assertEqual(ex.__str__(), sw.__str__())
Exemplo n.º 2
0
    def test_widget_factory_my_assembly_a(self):

        import test_widgets_c

        self.assertTrue('MyWidget_E' in widgetFactory.get_widget_names())
        self.assertTrue('MyWidget_F' in widgetFactory.get_widget_names())
        self.assertTrue('MyAssembly_A' in widgetFactory.get_widget_names())
        self.assertTrue('MyAssembly_B' in widgetFactory.get_widget_names())
        self.assertTrue('MyAssembly_C' in widgetFactory.get_widget_names())

        sw = StringWriter()
        assembly = Assembly(sw)

        assembly.get_widget('MyAssembly_A')(assembly,
                                            assembly.model({}, 'MyAssembly_A'),
                                            {})
        ex = StringWriter()
        ex.write('Widget E\n')
        ex.write('Attr1: \n')
        ex.write('Attr2: \n')
        ex.write('Container A [\n')
        ex.write('] Container A\n')
        ex.write('Container B [\n')
        ex.write('] Container B\n')
        ex.write('End widget E\n')

        self.assertEqual(ex.__str__(), sw.__str__())
Exemplo n.º 3
0
    def test_assembly_model_with_kw(self):
        import test_widgets_a

        sw = StringWriter()
        assembly = Assembly(sw)

        testA = TestClassA(attr1='a1', attr2='a2', attr3='a3', attr4='a4')

        model = assembly.model(testA,
                               'MyWidget_A',
                               attr1='A1',
                               attr2='A2',
                               attr5='A5')

        self.assertNotEqual(None, model)

        self.assertTrue(hasattr(model, 'attr1'))
        self.assertTrue(hasattr(model, 'attr2'))
        self.assertTrue(hasattr(model, 'attr3'))
        self.assertTrue(hasattr(model, 'attr4'))
        self.assertTrue(hasattr(model, 'attr5'))
        self.assertFalse(hasattr(model, 'attr6'))

        self.assertEqual('A1', model.attr1())
        self.assertEqual('A2', model.attr2())
        self.assertEqual('a3', model.attr3())
        self.assertEqual('a4', model.attr4())
        self.assertEqual('A5', model.attr5())
Exemplo n.º 4
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.º 5
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__())
Exemplo n.º 6
0
    def test_widget_factory_my_assembly_d(self):

        self.maxDiff = None

        import test_widgets_a, test_widgets_b, test_widgets_c

        sw = StringWriter()
        assembly = Assembly(sw)

        testB1 = TestClassB(attr1='B1.1',
                            attr2='B1.2',
                            attr3='B1.3',
                            attr4='B1.4')
        testB2 = TestClassB(attr1='B2.1',
                            attr2='B2.2',
                            attr3='B2.3',
                            attr4='B2.4')
        testA = TestClassA(attr1='A1',
                           attr2='A2',
                           attr3=[testB1, testB2],
                           attr4=testB2)

        widgetFactory.get('MyAssembly_D')(assembly,
                                          assembly.model({},
                                                         'MyAssembly_D',
                                                         attr1='a1',
                                                         attr2='a2',
                                                         attr3=testA), {})
        ex = StringWriter()
        ex.write('Widget E\n')
        ex.write('Attr1: a1\n')
        ex.write('Attr2: a2\n')
        ex.write('Container A [\n')
        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')
        ex.write('  ,\n')
        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')
        ex.write('] Container A\n')
        ex.write('Container B [\n')
        ex.write('  Widget F\n')
        ex.write('  Attr1: A1\n')
        ex.write('  Attr2: A2\n')
        ex.write('  Container A [\n')
        ex.write('    Widget C\n')
        ex.write('      Attr1: B1.1\n')
        ex.write('      Attr2: B1.2\n')
        ex.write('    End widget C\n')
        ex.write('    ,\n')
        ex.write('    Widget C\n')
        ex.write('      Attr1: B2.1\n')
        ex.write('      Attr2: B2.2\n')
        ex.write('    End widget C\n')
        ex.write('  ] Container A\n')
        ex.write('  Container B [\n')
        ex.write('    Widget D\n')
        ex.write('      Attr1: A1\n')
        ex.write('      Attr2: A2\n')
        ex.write('    End widget D\n')
        ex.write('  ] Container B\n')
        ex.write('  End widget F\n')
        ex.write('] Container B\n')
        ex.write('End widget E\n')

        self.assertEqual(ex.__str__(), sw.__str__())