def test_add_controller(self):
        root = Controller.RootController('root')

        controller = Controller.ContainerController('test', root, None)
        self.assertEqual(len(controller._controllers), 0)
        controller.add_controller('sub', controller)
        self.assertEqual(len(controller._controllers), 1)
 def test_add_controller(self):
     with self.assertRaises(Exception):
         root = Controller.RootController('root')
         controller = Controller.BoolController('test', root,
                                                TestValueInterface(), None,
                                                True)
         controller.add_controller('test', controller)
Exemple #3
0
    def test_model_to_view(self):
        root = Controller.RootController('root')
        value_interface = TestValueInterface()
        optional_interface = TestOptionalInterface()
        list_instance_factory = TestListInstanceFactory()

        controller = Controller.ListController('test', root, value_interface,
                                               None, list_instance_factory, 0)

        with self.assertRaises(AssertionError):
            controller.model_to_view({})

        controller = Controller.ListController('test', root, value_interface,
                                               optional_interface,
                                               list_instance_factory, 0)

        controller.model_to_view({})
        self.assertFalse(optional_interface.val)

        controller.model_to_view({'test': []})
        self.assertEqual(value_interface.val, '0')
        self.assertEqual(len(list_instance_factory.instances), 0)
        self.assertTrue(optional_interface.val)

        controller.model_to_view({'test': ['1', '2', '3']})
        self.assertEqual(value_interface.val, '3')
        self.assertEqual(len(list_instance_factory.instances), 3)
        self.assertTrue(optional_interface.val)
        self.assertEqual(list_instance_factory.values[0].val, '1')
        self.assertEqual(list_instance_factory.values[1].val, '2')
        self.assertEqual(list_instance_factory.values[2].val, '3')
    def test_model_to_view_value(self):
        root = Controller.RootController('root')
        value_interface = TestValueInterface()
        optional_interface_container = TestOptionalInterface()
        optional_interface_value = TestOptionalInterface()

        container = Controller.ContainerController('test', root, None)
        Controller.ValueController('test', container, value_interface, None,
                                   Converter.Str(0, 'default'))
        container.model_to_view({'test': {'test': 'test'}})
        self.assertEqual(value_interface.val, 'test')

        container = Controller.ContainerController(
            'test', root, optional_interface_container)
        Controller.ValueController('test', container, value_interface,
                                   optional_interface_value,
                                   Converter.Str(0, 'default'))
        container.model_to_view({'test': {'test': 'test'}})
        self.assertTrue(optional_interface_container.val)
        self.assertTrue(optional_interface_value.val)

        container.model_to_view({'test': {}})
        self.assertTrue(optional_interface_container.val)
        self.assertFalse(optional_interface_value.val)

        container.model_to_view({})
        self.assertFalse(optional_interface_container.val)

        container = Controller.ContainerController('test', root, None)
        container2 = Controller.ContainerController('test2', container, None)
        Controller.ValueController('test', container2, value_interface, None,
                                   Converter.Str(0, 'default'))
        container.model_to_view({'test': {'test2': {'test': 'test'}}})
        self.assertEqual(value_interface.val, 'test')
Exemple #5
0
    def test_model_to_view(self):
        root = Controller.RootController('root')
        value_interface = TestBitstringInterface()
        optional_interface = TestOptionalInterface()

        controller = Controller.BitstringController('test', root,
                                                    value_interface, None, 5)
        with self.assertRaises(AssertionError):
            controller.model_to_view({})

        controller = Controller.BitstringController('test', root,
                                                    value_interface,
                                                    optional_interface, 6)

        controller.model_to_view({})
        self.assertFalse(optional_interface.val)

        with self.assertRaises(AssertionError):
            controller.model_to_view({'test': (b'\x00', 7)})

        controller.model_to_view({'test': (b'\x33', 6)})
        self.assertListEqual(value_interface.values, [0, 1, 4, 5])

        controller = Controller.BitstringController('test', root,
                                                    value_interface,
                                                    optional_interface, 22)

        controller.model_to_view({'test': (b'\x82\x81\x81', 22)})
        self.assertListEqual(value_interface.values, [1, 7, 8, 15, 16])
    def test_model_to_view(self):
        root = Controller.RootController('root')
        value_interface = TestValueInterface()
        optional_interface = TestOptionalInterface()

        controller = Controller.ValueController('test', root, value_interface,
                                                None,
                                                Converter.Str(0, 'default'))
        controller.model_to_view({'test': 'new'})
        self.assertEqual(value_interface.val, 'new')

        controller.model_to_view('new2')
        self.assertEqual(value_interface.val, 'new2')

        with self.assertRaises(AssertionError):
            controller.model_to_view({})

        controller = Controller.ValueController('test', root, value_interface,
                                                optional_interface,
                                                Converter.Str(0, 'default'))
        controller.model_to_view({'test': 'new'})
        self.assertEqual(value_interface.val, 'new')
        self.assertTrue(optional_interface.val)

        controller.model_to_view({})
        self.assertFalse(optional_interface.val)
Exemple #7
0
    def test_add_controller(self):
        root = Controller.RootController('root')
        value_interface = TestValueInterface()

        controller = Controller.ChoiceController('test', root, value_interface, None, TestChoiceInstanceFactory(), 'choice')
        controller.add_controller('sub', controller)
        self.assertEqual(controller._controller, controller)
 def test_add_controller(self):
     with self.assertRaises(Exception):
         root = Controller.RootController('root')
         controller = Controller.ValueController('test', root,
                                                 TestValueInterface(), None,
                                                 Converter.Str(0, ''))
         controller.add_controller('test', controller)
    def test_nullController(self):
        root = Controller.RootController('root')

        controller = Controller.NullController('Test', root, None)

        with self.assertRaises(Exception):
            controller.add_controller('Test', root)
    def test_view_to_model_list(self):
        root = Controller.RootController('root')
        list_value_interface = TestValueInterface()
        value_interface = TestValueInterface()
        list_instance_factory = TestListInstanceFactory()

        container = Controller.ContainerController('test', root, None)
        list_controller = Controller.ListController('test_list', container,
                                                    list_value_interface, None,
                                                    list_instance_factory, 0)

        self.assertEqual(container.view_to_model(), {'test_list': []})

        list_value_interface.val = 1
        list_controller.event_handler()
        list_instance_factory.values[0].val = 1

        self.assertEqual(container.view_to_model(), {'test_list': [1]})

        container.model_to_view({'test': {'test_list': [1]}})
        self.assertEqual(list_value_interface.val, '1')
        self.assertEqual(len(list_instance_factory.instances), 1)
        self.assertEqual(list_instance_factory.values[0].val, 1)

        Controller.ValueController('test_val', container, value_interface,
                                   None, Converter.Str(0, 'default'))
        value_interface.val = 'test'
        self.assertEqual(container.view_to_model(), {
            'test_list': [1],
            'test_val': 'test'
        })
    def test_init(self):
        root = Controller.RootController('root')
        value_interface = TestValueInterface()

        Controller.BoolController('test', root, value_interface, None, True)
        self.assertTrue(value_interface.val)

        Controller.BoolController('test', root, value_interface, None, False)
        self.assertFalse(value_interface.val)
Exemple #12
0
    def test_add_controller(self):
        root = Controller.RootController('root')
        value_interface = TestValueInterface()

        controller = Controller.ListController('test', root,
                                               value_interface, None,
                                               TestListInstanceFactory(), 0)
        self.assertEqual(len(controller._controllers), 0)
        controller.add_controller('sub', controller)
        self.assertEqual(len(controller._controllers), 1)
Exemple #13
0
    def test_event_handlers(self):
        root = Controller.RootController('root')
        value_interface = TestValueInterface()
        optional_interface = TestOptionalInterface()
        choice_instance_factory = TestChoiceInstanceFactory()

        controller = Controller.ChoiceController('test', root, value_interface, optional_interface, choice_instance_factory, 'choice')

        value_interface.val = 'choice2'
        controller.event_handler()
        self.assertEqual(choice_instance_factory.member, 'choice2')
    def test_view_to_model(self):
        root = Controller.RootController('root')
        value_interface = TestValueInterface()
        optional_interface = TestOptionalInterface()

        controller = Controller.BoolController('test', root, value_interface,
                                               optional_interface, False)
        value_interface.val = 'True'
        optional_interface.val = True
        self.assertTrue(controller.view_to_model())

        optional_interface.val = False
        self.assertIsNone(controller.view_to_model())
Exemple #15
0
    def test_init(self):
        root = Controller.RootController('root')
        value_interface = TestValueInterface()
        optional_interface = TestOptionalInterface()

        Controller.ListController('test', root, value_interface, None,
                                  TestListInstanceFactory(), 1)
        self.assertEqual(value_interface.val, '1')

        value_interface.val = 42
        Controller.ListController('test', root,
                                  value_interface, optional_interface,
                                  TestListInstanceFactory(), 0)
        self.assertEqual(value_interface.val, 42)
Exemple #16
0
    def test_view_to_model(self):
        root = Controller.RootController('root')
        value_interface = TestBitstringInterface()
        optional_interface = TestOptionalInterface()

        controller = Controller.BitstringController('test', root,
                                                    value_interface,
                                                    optional_interface, 22)

        optional_interface.val = False
        self.assertIsNone(controller.view_to_model())

        optional_interface.val = True
        self.assertEqual(controller.view_to_model(), (b'\x00\x00\x00', 22))

        value_interface.values = [1, 7, 8, 15, 16]
        self.assertEqual(controller.view_to_model(), (b'\x82\x81\x01', 22))
Exemple #17
0
    def test_controller(self):
        root = Controller.RootController('root')

        controller = Controller.Controller('Test', root, None)

        with self.assertRaises(NotImplementedError):
            controller.add_controller('Error', root)

        with self.assertRaises(NotImplementedError):
            controller.model_to_view({})

        with self.assertRaises(NotImplementedError):
            controller.view_to_model()

        controller.optional_handler()

        self.assertEqual(str(controller), 'Test')
Exemple #18
0
    def test_view_to_model(self):
        root = Controller.RootController('root')
        value_interface = TestValueInterface()
        optional_interface = TestOptionalInterface()
        choice_instance_factory = TestChoiceInstanceFactory()

        controller = Controller.ChoiceController('test', root, value_interface, optional_interface, choice_instance_factory, 'choice')

        optional_interface.val = False
        self.assertIsNone(controller.view_to_model())

        optional_interface.val = True
        choice_instance_factory.value.val = '1'
        self.assertEqual(controller.view_to_model(), ('choice', '1'))

        optional_interface.val = True
        value_interface.val = 'choice2'
        choice_instance_factory.value.val = '2'
        self.assertEqual(controller.view_to_model(), ('choice2', '2'))
    def test_view_to_model(self):
        root = Controller.RootController('root')
        value_interface = TestValueInterface()
        optional_interface = TestOptionalInterface()

        controller = Controller.ValueController('test', root, value_interface,
                                                optional_interface,
                                                Converter.Str(0, 'default'))
        value_interface.val = 'new'
        optional_interface.val = True
        self.assertEqual('new', controller.view_to_model())

        optional_interface.val = False
        self.assertIsNone(controller.view_to_model())

        controller = Controller.ValueController('test', root,
                                                value_interface, None,
                                                Converter.Float(0.0, 1.0))
        value_interface.val = 'new'
        self.assertEqual(controller.view_to_model(), 0.0)
    def test_view_to_model_value(self):
        root = Controller.RootController('root')
        value_interface = TestValueInterface()
        optional_interface_container = TestOptionalInterface()
        optional_interface_value = TestOptionalInterface()

        container = Controller.ContainerController('test', root, None)
        Controller.ValueController('test', container, value_interface, None,
                                   Converter.Str(0, 'default'))
        value_interface.val = 'test'

        self.assertEqual(container.view_to_model(), {'test': 'test'})

        container = Controller.ContainerController(
            'test', root, optional_interface_container)
        Controller.ValueController('test', container, value_interface,
                                   optional_interface_value,
                                   Converter.Str(0, 'default'))

        optional_interface_value.val = True
        optional_interface_container.val = True
        self.assertEqual(container.view_to_model(), {'test': 'default'})

        optional_interface_value.val = False
        optional_interface_container.val = False
        self.assertIsNone(container.view_to_model())

        optional_interface_value.val = False
        optional_interface_container.val = True
        self.assertEqual(container.view_to_model(), {})

        container = Controller.ContainerController('test', root, None)
        container2 = Controller.ContainerController('test2', container, None)
        Controller.ValueController('test', container2, value_interface, None,
                                   Converter.Str(0, 'default'))

        value_interface.val = 'test'
        self.assertEqual(container.view_to_model(),
                         {'test2': {
                             'test': 'test'
                         }})
Exemple #21
0
    def test_model_to_view(self):
        root = Controller.RootController('root')
        value_interface = TestValueInterface()
        optional_interface = TestOptionalInterface()
        choice_instance_factory = TestChoiceInstanceFactory()

        controller = Controller.ChoiceController('test', root, value_interface, None, choice_instance_factory, 'choice')

        with self.assertRaises(AssertionError):
            controller.model_to_view({})

        controller = Controller.ChoiceController('test', root, value_interface, optional_interface, choice_instance_factory, 'choice')

        controller.model_to_view({})
        self.assertFalse(optional_interface.val)

        controller.model_to_view({'test': ('choice2', '2')})
        self.assertEqual(value_interface.val, 'choice2')
        self.assertEqual(choice_instance_factory.member, 'choice2')
        self.assertTrue(optional_interface.val)
        self.assertEqual(choice_instance_factory.value.val, '2')
Exemple #22
0
    def test_view_to_model(self):
        root = Controller.RootController('root')
        value_interface = TestValueInterface()
        optional_interface = TestOptionalInterface()
        list_instance_factory = TestListInstanceFactory()

        controller = Controller.ListController('test', root, value_interface,
                                               optional_interface,
                                               list_instance_factory, 0)

        optional_interface.val = False
        self.assertIsNone(controller.view_to_model())

        optional_interface.val = True
        self.assertEqual(controller.view_to_model(), [])

        value_interface.val = 2
        controller.event_handler()
        list_instance_factory.values[0].val = 1
        list_instance_factory.values[1].val = 2
        self.assertEqual(controller.view_to_model(), [1, 2])
    def test_init(self):
        root = Controller.RootController('root')
        value_interface = TestValueInterface()

        Controller.ValueController('test', root, value_interface, None,
                                   Converter.Str(0, 'default'))
        self.assertEqual(value_interface.val, 'default')

        Controller.ValueController('test', root, value_interface, None,
                                   Converter.Int(0, 12))
        self.assertEqual(value_interface.val, '12')

        Controller.ValueController('test', root, value_interface, None,
                                   Converter.Int(0, None))
        self.assertEqual(value_interface.val, '0')

        Controller.ValueController('test', root, value_interface, None,
                                   Converter.Int(12, None))
        self.assertEqual(value_interface.val, '12')

        Controller.ValueController('test', root, value_interface, None,
                                   Converter.Int(None, 12))
        self.assertEqual(value_interface.val, '12')

        Controller.ValueController('test', root, value_interface, None,
                                   Converter.Float(0.0, 12.1))
        self.assertEqual(value_interface.val, '12.1')

        Controller.ValueController('test', root, value_interface, None,
                                   Converter.Float(0.0, None))
        self.assertEqual(value_interface.val, '0.0')

        Controller.ValueController('test', root, value_interface, None,
                                   Converter.Float(12.1, None))
        self.assertEqual(value_interface.val, '12.1')

        Controller.ValueController('test', root, value_interface, None,
                                   Converter.Float(None, 12.1))
        self.assertEqual(value_interface.val, '12.1')
    def test_model_to_view(self):
        root = Controller.RootController('root')
        value_interface = TestValueInterface()
        optional_interface = TestOptionalInterface()

        controller = Controller.BoolController('test', root, value_interface,
                                               None, True)
        controller.model_to_view({'test': 'false'})
        self.assertEqual(value_interface.val, 'false')

        controller.model_to_view('True')
        self.assertEqual(value_interface.val, 'True')

        with self.assertRaises(AssertionError):
            controller.model_to_view({})

        controller = Controller.BoolController('test', root, value_interface,
                                               optional_interface, True)
        controller.model_to_view({'test': 'false'})
        self.assertEqual(value_interface.val, 'false')
        self.assertTrue(optional_interface.val)

        controller.model_to_view({})
        self.assertFalse(optional_interface.val)
Exemple #25
0
    def test_event_handlers(self):
        root = Controller.RootController('root')
        value_interface = TestValueInterface()
        optional_interface = TestOptionalInterface()
        list_instance_factory = TestListInstanceFactory()

        controller = Controller.ListController('test', root, value_interface,
                                               optional_interface,
                                               list_instance_factory, 0)
        self.assertEqual(len(list_instance_factory.instances), 0)

        value_interface.val = 2
        controller.event_handler()
        self.assertEqual(len(list_instance_factory.instances), 2)

        optional_interface.val = False
        controller.optional_handler()
        self.assertEqual(len(list_instance_factory.instances), 0)
        self.assertEqual(value_interface.val, 2)

        optional_interface.val = True
        controller.optional_handler()
        self.assertEqual(len(list_instance_factory.instances), 2)
        self.assertEqual(value_interface.val, 2)
Exemple #26
0
 def test_add_controller(self):
     with self.assertRaises(Exception):
         root = Controller.RootController('root')
         controller = Controller.BitstringController(
             'test', root, TestBitstringInterface(), None, 5)
         controller.add_controller('test', controller)
Exemple #27
0
    def test_init(self):
        root = Controller.RootController('root')
        value_interface = TestValueInterface()

        Controller.ChoiceController('test', root, value_interface, None, TestChoiceInstanceFactory(), 'choice')
        self.assertEqual(value_interface.val, 'choice')