예제 #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
파일: 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)
예제 #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_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)
예제 #5
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)
예제 #6
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)
예제 #7
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)
예제 #8
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)
예제 #9
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)
예제 #10
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)
예제 #11
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)
예제 #12
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)
예제 #13
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)
예제 #14
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)
예제 #15
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)
예제 #16
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)
예제 #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_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)
예제 #21
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)
예제 #22
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)