예제 #1
0
    def test_internals_1 (self):
        test = NotifyTestObject ()

        condition     = Condition (False)
        not_condition = ~condition

        self.assert_(not not_condition._has_signal ())

        not_condition.changed.connect (test.simple_handler)
        self.assert_(not_condition._has_signal ())

        def set_state_true ():
            condition.state = True

        condition.with_changes_frozen (set_state_true)

        condition.state = False

        not_condition.changed.disconnect (test.simple_handler)
        self.collect_garbage ()
        self.assert_(not not_condition._has_signal ())

        not_condition.changed.connect (test.simple_handler)
        self.assert_(not_condition._has_signal ())

        condition.state = True

        test.assert_results (False, True, False)
예제 #2
0
    def test_garbage_collection_binary (self):
        for _operator in (operator.__and__, operator.__or__, operator.__xor__):
            test = NotifyTestObject ()

            condition1       = Condition (True)
            condition2       = Condition (False)
            binary_condition = _operator (condition1, condition2)

            binary_condition.store (test.simple_handler)
            binary_condition = weakref.ref (binary_condition)

            del condition1
            self.collect_garbage ()

            self.assertNotEqual (binary_condition (), None)

            condition2.state = True

            del condition2
            self.collect_garbage ()

            self.assertEqual (binary_condition (), None)

            expected_results = []
            for state1, state2 in ((True, False), (True, True)):
                if not expected_results or expected_results[-1] != _operator (state1, state2):
                    expected_results.append (_operator (state1, state2))

            test.assert_results (*expected_results)
예제 #3
0
    def test_garbage_collection_if_else (self):
        test              = NotifyTestObject ()

        condition1        = Condition (False)
        condition2        = Condition (False)
        condition3        = Condition (True)
        if_else_condition = condition1.if_else (condition2, condition3)

        if_else_condition.store (test.simple_handler)
        if_else_condition = weakref.ref (if_else_condition)

        del condition2
        self.collect_garbage ()

        self.assertNotEqual (if_else_condition (), None)

        condition3.state = False

        del condition1
        self.collect_garbage ()

        self.assertNotEqual (if_else_condition (), None)

        condition3.state = True

        del condition3
        self.collect_garbage ()

        self.assertEqual    (if_else_condition (), None)
        test.assert_results (True, False, True)
예제 #4
0
    def test_garbage_collection_binary(self):
        for _operator in (operator.__and__, operator.__or__, operator.__xor__):
            test = NotifyTestObject()

            condition1 = Condition(True)
            condition2 = Condition(False)
            binary_condition = _operator(condition1, condition2)

            binary_condition.store(test.simple_handler)
            binary_condition = weakref.ref(binary_condition)

            del condition1
            self.collect_garbage()

            self.assertNotEqual(binary_condition(), None)

            condition2.state = True

            del condition2
            self.collect_garbage()

            self.assertEqual(binary_condition(), None)

            expected_results = []
            for state1, state2 in ((True, False), (True, True)):
                if not expected_results or expected_results[-1] != _operator(
                        state1, state2):
                    expected_results.append(_operator(state1, state2))

            test.assert_results(*expected_results)
예제 #5
0
파일: logical.py 프로젝트: brmed/py-notify
    def initialize(self):
        self.__condition1 = Condition(False)
        self.__condition2 = Condition(False)
        self.__condition3 = Condition(False)
        self.__condition4 = Condition(False)
        self.__condition5 = Condition(False)

        self.__compound_condition = ((self.__condition1
                                      & self.__condition2).if_else(
                                          self.__condition3, self.__condition4
                                          | ~self.__condition5))
        self.__compound_condition.changed.connect(_ignoring_handler)
예제 #6
0
    def test_if_else_2 (self):
        test = NotifyTestObject ()

        condition1 = Condition (False)
        condition2 = Condition (False)
        condition3 = Condition (True)

        if_else_condition = condition1.if_else (condition2, condition3)
        if_else_condition.store (test.simple_handler)

        condition1.state = True

        test.assert_results (True, False)
예제 #7
0
    def test_not (self):
        test = NotifyTestObject ()

        condition = Condition (False)

        not_condition = ~condition
        not_condition.store (test.simple_handler)
        self.assertEqual (not_condition.state, True)

        condition.state = True
        self.assertEqual (not_condition.state, False)

        test.assert_results (True, False)
예제 #8
0
    def test_not(self):
        test = NotifyTestObject()

        condition = Condition(False)

        not_condition = ~condition
        not_condition.store(test.simple_handler)
        self.assertEqual(not_condition.state, True)

        condition.state = True
        self.assertEqual(not_condition.state, False)

        test.assert_results(True, False)
예제 #9
0
    def test_watcher_condition_1(self):
        test = NotifyTestObject()

        watcher = WatcherCondition()
        watcher.store(test.simple_handler)

        condition = Condition(True)
        watcher.watch(condition)

        self.assert_(watcher.watched_condition is condition)

        condition.state = False

        test.assert_results(False, True, False)
예제 #10
0
    def test_watcher_condition_1 (self):
        test = NotifyTestObject ()

        watcher = WatcherCondition ()
        watcher.store (test.simple_handler)

        condition = Condition (True)
        watcher.watch (condition)

        self.assert_(watcher.watched_condition is condition)

        condition.state = False

        test.assert_results (False, True, False)
예제 #11
0
    def test_garbage_collection_if_else(self):
        test = NotifyTestObject()

        condition1 = Condition(False)
        condition2 = Condition(False)
        condition3 = Condition(True)
        if_else_condition = condition1.if_else(condition2, condition3)

        if_else_condition.store(test.simple_handler)
        if_else_condition = weakref.ref(if_else_condition)

        del condition2
        self.collect_garbage()

        self.assertNotEqual(if_else_condition(), None)

        condition3.state = False

        del condition1
        self.collect_garbage()

        self.assertNotEqual(if_else_condition(), None)

        condition3.state = True

        del condition3
        self.collect_garbage()

        self.assertEqual(if_else_condition(), None)
        test.assert_results(True, False, True)
예제 #12
0
    def test_referenced_signal(self):
        test = NotifyTestObject()

        condition = Condition(False)
        signal = (~condition).changed
        signal.connect(test.simple_handler)

        condition.state = True

        # This must not change anything.  But current (at the time of test addition)
        # implementation destroys the `not' condition despite the reference to its signal.
        signal.disconnect(test.simple_handler)
        signal.connect(test.simple_handler)

        condition.state = False

        test.assert_results(False, True)
예제 #13
0
    def test_referenced_signal (self):
        test = NotifyTestObject ()

        condition = Condition (False)
        signal    = (~condition).changed
        signal.connect (test.simple_handler)

        condition.state = True

        # This must not change anything.  But current (at the time of test addition)
        # implementation destroys the `not' condition despite the reference to its signal.
        signal.disconnect (test.simple_handler)
        signal.connect    (test.simple_handler)

        condition.state = False

        test.assert_results (False, True)
예제 #14
0
    def test_watcher_condition_2(self):
        test = NotifyTestObject()

        condition1 = Condition(True)
        condition2 = Condition(False)
        condition3 = Condition(False)

        watcher = WatcherCondition(condition1)
        watcher.store(test.simple_handler)

        watcher.watch(condition2)
        watcher.watch(condition3)
        watcher.watch(None)

        self.assert_(watcher.watched_condition is None)

        # Last two watch() calls must not change watcher's state.
        test.assert_results(True, False)
예제 #15
0
    def test_derivation_slots (self):
        DerivedCondition = AbstractCondition.derive_type ('DerivedCondition')
        self.assertRaises (AttributeError,
                           self.non_existing_attribute_setter (DerivedCondition ()))

        DerivedCondition = AbstractStateTrackingCondition.derive_type ('DerivedCondition')
        self.assertRaises (AttributeError,
                           self.non_existing_attribute_setter (DerivedCondition (False)))

        DerivedCondition = Condition.derive_type ('DerivedCondition')
        self.assertRaises (AttributeError,
                           self.non_existing_attribute_setter (DerivedCondition (False)))
예제 #16
0
파일: base.py 프로젝트: brmed/py-notify
    def test_internals_1(self):
        test = NotifyTestObject()

        condition = Condition(False)
        not_condition = ~condition

        self.assert_(not not_condition._has_signal())

        not_condition.changed.connect(test.simple_handler)
        self.assert_(not_condition._has_signal())

        def set_state_true():
            condition.state = True

        condition.with_changes_frozen(set_state_true)

        condition.state = False

        not_condition.changed.disconnect(test.simple_handler)
        self.collect_garbage()
        self.assert_(not not_condition._has_signal())

        not_condition.changed.connect(test.simple_handler)
        self.assert_(not_condition._has_signal())

        condition.state = True

        test.assert_results(False, True, False)
예제 #17
0
    def test_signal_garbage_collection(self):
        test = NotifyTestObject()
        condition1 = Condition(True)
        condition2 = ~condition1

        condition2.changed.connect(test.simple_handler)

        # We also assume that `Not's condition signal can be weakly referenced, but I
        # don't see other way...
        signal = weakref.ref(condition2.changed)

        condition1.state = False
        test.assert_results(True)

        condition1 = weakref.ref(condition1)
        condition2 = weakref.ref(condition2)

        self.collect_garbage()

        self.assertEqual(condition1(), None)
        self.assertEqual(condition2(), None)
        self.assertEqual(signal(), None)
예제 #18
0
    def test_signal_garbage_collection (self):
        test       = NotifyTestObject ()
        condition1 = Condition (True)
        condition2 = ~condition1

        condition2.changed.connect (test.simple_handler)

        # We also assume that `Not's condition signal can be weakly referenced, but I
        # don't see other way...
        signal = weakref.ref (condition2.changed)

        condition1.state = False
        test.assert_results (True)

        condition1 = weakref.ref (condition1)
        condition2 = weakref.ref (condition2)

        self.collect_garbage ()

        self.assertEqual (condition1 (), None)
        self.assertEqual (condition2 (), None)
        self.assertEqual (signal     (), None)
예제 #19
0
    def test_xor(self):
        test = NotifyTestObject()

        condition1 = Condition(False)
        condition2 = Condition(False)

        xor_condition = condition1 ^ condition2
        xor_condition.store(test.simple_handler)
        self.assertEqual(xor_condition.state, False)

        condition1.state = True
        condition2.state = False
        self.assertEqual(xor_condition.state, True)

        condition1.state = False
        condition2.state = True
        self.assertEqual(xor_condition.state, True)

        condition1.state = True
        condition2.state = True
        self.assertEqual(xor_condition.state, False)

        test.assert_results(False, True, False, True, False)
예제 #20
0
    def test_garbage_collection_signal_referenced_1(self):
        condition1 = Condition(True)
        condition2 = ~condition1
        signal = condition2.changed

        condition2 = weakref.ref(condition2)

        self.collect_garbage()

        self.assertNotEqual(condition2(), None)

        del condition1
        self.collect_garbage()

        self.assertEqual(condition2(), None)
예제 #21
0
    def test_derivation_slots(self):
        DerivedCondition = AbstractCondition.derive_type('DerivedCondition')
        self.assertRaises(
            AttributeError,
            self.non_existing_attribute_setter(DerivedCondition()))

        DerivedCondition = AbstractStateTrackingCondition.derive_type(
            'DerivedCondition')
        self.assertRaises(
            AttributeError,
            self.non_existing_attribute_setter(DerivedCondition(False)))

        DerivedCondition = Condition.derive_type('DerivedCondition')
        self.assertRaises(
            AttributeError,
            self.non_existing_attribute_setter(DerivedCondition(False)))
예제 #22
0
    def test_mutable(self):
        # This also stresses usage algorithm, as a bonus.
        mutable_condition = Condition(False)
        not_condition = ~mutable_condition
        and_condition = not_condition & mutable_condition
        or_condition = and_condition | not_condition
        xor_condition = or_condition ^ and_condition
        if_else_condition = or_condition.if_else(mutable_condition,
                                                 or_condition)

        self.assert_(mutable_condition.mutable)
        self.assert_(not not_condition.mutable)
        self.assert_(not and_condition.mutable)
        self.assert_(not or_condition.mutable)
        self.assert_(not xor_condition.mutable)
        self.assert_(not if_else_condition.mutable)
예제 #23
0
    def test_if_else_2(self):
        test = NotifyTestObject()

        condition1 = Condition(False)
        condition2 = Condition(False)
        condition3 = Condition(True)

        if_else_condition = condition1.if_else(condition2, condition3)
        if_else_condition.store(test.simple_handler)

        condition1.state = True

        test.assert_results(True, False)
예제 #24
0
    def test_xor (self):
        test = NotifyTestObject ()

        condition1 = Condition (False)
        condition2 = Condition (False)

        xor_condition = condition1 ^ condition2
        xor_condition.store (test.simple_handler)
        self.assertEqual (xor_condition.state, False)

        condition1.state = True
        condition2.state = False
        self.assertEqual (xor_condition.state, True)

        condition1.state = False
        condition2.state = True
        self.assertEqual (xor_condition.state, True)

        condition1.state = True
        condition2.state = True
        self.assertEqual (xor_condition.state, False)

        test.assert_results (False, True, False, True, False)
예제 #25
0
    def test_garbage_collection_signal_referenced_2(self):
        test = NotifyTestObject()
        condition1 = Condition(True)
        condition2 = ~condition1
        signal = condition2.changed

        signal.connect(test.simple_handler)

        condition2 = weakref.ref(condition2)

        self.collect_garbage()

        self.assertNotEqual(condition2(), None)

        signal.disconnect(test.simple_handler)

        self.collect_garbage()

        self.assertNotEqual(condition2(), None)

        del signal
        self.collect_garbage()

        self.assertEqual(condition2(), None)
예제 #26
0
파일: base.py 프로젝트: brmed/py-notify
 def test_derivation_module(self):
     self.assertEqual(
         Condition.derive_type('Test').__module__,
         type(self).__module__)
예제 #27
0
    def test_set(self):
        test = NotifyTestObject()

        condition = Condition(False)
        condition.changed.connect(test.simple_handler)

        condition.state = True
        self.assertEqual(condition.state, True)
        self.assertEqual(condition.get(), True)

        condition.state = 1
        self.assertEqual(condition.state, True)
        self.assertEqual(condition.get(), True)

        condition.state = 0
        self.assertEqual(condition.state, False)
        self.assertEqual(condition.get(), False)

        condition.state = False
        self.assertEqual(condition.state, False)
        self.assertEqual(condition.get(), False)

        condition.set('yes')
        self.assertEqual(condition.state, True)
        self.assertEqual(condition.get(), True)

        condition.set(True)
        self.assertEqual(condition.state, True)
        self.assertEqual(condition.get(), True)

        condition.set(False)
        self.assertEqual(condition.state, False)
        self.assertEqual(condition.get(), False)

        condition.set(None)
        self.assertEqual(condition.state, False)
        self.assertEqual(condition.get(), False)

        test.assert_results(True, False, True, False)
예제 #28
0
    def test_if_else_1 (self):
        test = NotifyTestObject ()

        condition1 = Condition (False)
        condition2 = Condition (False)
        condition3 = Condition (False)

        if_else_condition = condition1.if_else (condition2, condition3)
        if_else_condition.store (test.simple_handler)
        self.assertEqual (if_else_condition.state, False)

        condition1.state = False
        condition2.state = False
        condition3.state = True
        self.assertEqual (if_else_condition.state, True)

        condition1.state = False
        condition2.state = True
        condition3.state = False
        self.assertEqual (if_else_condition.state, False)

        condition1.state = False
        condition2.state = True
        condition3.state = True
        self.assertEqual (if_else_condition.state, True)

        condition1.state = True
        condition2.state = False
        condition3.state = False
        self.assertEqual (if_else_condition.state, False)

        condition1.state = True
        condition2.state = False
        condition3.state = True
        self.assertEqual (if_else_condition.state, False)

        condition1.state = True
        condition2.state = True
        condition3.state = False
        self.assertEqual (if_else_condition.state, True)

        condition1.state = True
        condition2.state = True
        condition3.state = True
        self.assertEqual (if_else_condition.state, True)

        test.assert_results (False, True, False, True, False, True)
예제 #29
0
    def test_set (self):
        test = NotifyTestObject ()

        condition = Condition (False)
        condition.changed.connect (test.simple_handler)

        condition.state = True
        self.assertEqual (condition.state,  True)
        self.assertEqual (condition.get (), True)

        condition.state = 1
        self.assertEqual (condition.state,  True)
        self.assertEqual (condition.get (), True)

        condition.state = 0
        self.assertEqual (condition.state,  False)
        self.assertEqual (condition.get (), False)

        condition.state = False
        self.assertEqual (condition.state,  False)
        self.assertEqual (condition.get (), False)

        condition.set ('yes')
        self.assertEqual (condition.state,  True)
        self.assertEqual (condition.get (), True)

        condition.set (True)
        self.assertEqual (condition.state,  True)
        self.assertEqual (condition.get (), True)

        condition.set (False)
        self.assertEqual (condition.state,  False)
        self.assertEqual (condition.get (), False)

        condition.set (None)
        self.assertEqual (condition.state,  False)
        self.assertEqual (condition.get (), False)

        test.assert_results (True, False, True, False)
예제 #30
0
 def test_derivation_module (self):
     self.assertEqual (Condition.derive_type ('Test').__module__, type (self).__module__)
예제 #31
0
    def test_if_else_1(self):
        test = NotifyTestObject()

        condition1 = Condition(False)
        condition2 = Condition(False)
        condition3 = Condition(False)

        if_else_condition = condition1.if_else(condition2, condition3)
        if_else_condition.store(test.simple_handler)
        self.assertEqual(if_else_condition.state, False)

        condition1.state = False
        condition2.state = False
        condition3.state = True
        self.assertEqual(if_else_condition.state, True)

        condition1.state = False
        condition2.state = True
        condition3.state = False
        self.assertEqual(if_else_condition.state, False)

        condition1.state = False
        condition2.state = True
        condition3.state = True
        self.assertEqual(if_else_condition.state, True)

        condition1.state = True
        condition2.state = False
        condition3.state = False
        self.assertEqual(if_else_condition.state, False)

        condition1.state = True
        condition2.state = False
        condition3.state = True
        self.assertEqual(if_else_condition.state, False)

        condition1.state = True
        condition2.state = True
        condition3.state = False
        self.assertEqual(if_else_condition.state, True)

        condition1.state = True
        condition2.state = True
        condition3.state = True
        self.assertEqual(if_else_condition.state, True)

        test.assert_results(False, True, False, True, False, True)
예제 #32
0
    def test_watcher_condition_error_3(self):
        condition = Condition(True)
        watcher = WatcherCondition(condition)

        self.assertRaises(ValueError, lambda: watcher.watch(watcher))
        self.assert_(watcher.watched_condition is condition)