Example #1
0
 def test_derivation_11 (self):
     # Test that derivation with keyword slot or property raises.
     self.assertRaises (ValueError, lambda: AbstractVariable.derive_type ('DerivedVariable',
                                                                          object = 'or'))
     self.assertRaises (ValueError, lambda: AbstractVariable.derive_type ('DerivedVariable',
                                                                          object   = '__class',
                                                                          property = 'class'))
Example #2
0
    def test_derivation_slots (self):
        DerivedVariable = AbstractVariable.derive_type ('DerivedVariable')
        self.assertRaises (AttributeError, self.non_existing_attribute_setter (DerivedVariable ()))

        DerivedVariable = AbstractValueTrackingVariable.derive_type ('DerivedVariable')
        self.assertRaises (AttributeError, self.non_existing_attribute_setter (DerivedVariable ()))

        DerivedVariable = Variable.derive_type ('DerivedVariable')
        self.assertRaises (AttributeError, self.non_existing_attribute_setter (DerivedVariable ()))
Example #3
0
    def test_derived_variable_changes_frozen_1 (self):
        DerivedVariable = AbstractVariable.derive_type ('DerivedVariable',
                                                        getter = lambda variable: x)
        test         = NotifyTestObject ()
        x            = 1
        variable     = DerivedVariable ()

        variable.store (test.simple_handler)

        with variable.changes_frozen ():
            x = 2

        # Though we never call _value_changed(), changes_frozen() promises to call it
        # itself in such cases.
        test.assert_results (1, 2)
Example #4
0
    def test_derived_variable_changes_frozen_1(self):
        DerivedVariable = AbstractVariable.derive_type(
            'DerivedVariable', getter=lambda variable: x)
        test = NotifyTestObject()
        x = 1
        variable = DerivedVariable()

        variable.store(test.simple_handler)

        with variable.changes_frozen():
            x = 2

        # Though we never call _value_changed(), changes_frozen() promises to call it
        # itself in such cases.
        test.assert_results(1, 2)
Example #5
0
    def test_with_derived_variable_changes_frozen_1 (self):
        DerivedVariable = AbstractVariable.derive_type ('DerivedVariable',
                                                        getter = lambda variable: values['x'])
        test            = NotifyTestObject ()
        values          = { 'x': 1 }
        variable        = DerivedVariable ()

        variable.store (test.simple_handler)

        def do_changes (values):
            values['x'] = 2

        variable.with_changes_frozen (do_changes, values)

        # Though we never call _value_changed(), with_changes_frozen() promises to call it
        # itself in such cases.
        test.assert_results (1, 2)
Example #6
0
    def test_derivation_10 (self):
        def set_value (list, value):
            list[0] = value

        DerivedVariable = AbstractVariable.derive_type ('DerivedVariable',
                                                        object = '__list', property = 'list',
                                                        getter = lambda list: list[0],
                                                        setter = set_value)

        a = DerivedVariable ([123])

        self.assertEqual (a.value, 123)

        a.value = 'foo'

        self.assertEqual (a.value, 'foo')
        self.assertEqual (a.list,  ['foo'])
Example #7
0
    def test_with_derived_variable_changes_frozen_1(self):
        DerivedVariable = AbstractVariable.derive_type(
            'DerivedVariable', getter=lambda variable: values['x'])
        test = NotifyTestObject()
        values = {'x': 1}
        variable = DerivedVariable()

        variable.store(test.simple_handler)

        def do_changes(values):
            values['x'] = 2

        variable.with_changes_frozen(do_changes, values)

        # Though we never call _value_changed(), with_changes_frozen() promises to call it
        # itself in such cases.
        test.assert_results(1, 2)