Esempio n. 1
0
    def test_garbage_collection_3(self):
        test = NotifyTestObject()

        variable = Variable()

        condition1 = variable.is_true()
        condition2 = ~condition1
        condition2.store(test.simple_handler)

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

        self.collect_garbage()
        self.assertNotEqual(condition1(), None)
        self.assertNotEqual(condition2(), None)

        self.collect_garbage()
        variable.value = 10

        condition2().changed.disconnect(test.simple_handler)

        self.collect_garbage()

        self.assertEqual(condition1(), None)
        self.assertEqual(condition2(), None)

        variable = weakref.ref(variable)
        self.collect_garbage()

        self.assertEqual(variable(), None)

        test.assert_results(True, False)
Esempio n. 2
0
    def test_synchronizing_1(self):
        test = NotifyTestObject()

        variable1 = Variable()
        variable2 = Variable()

        variable1.value = 100
        variable2.value = 200

        variable1.changed.connect(test.simple_handler)

        with variable1.synchronizing(variable2):
            variable2.value = 300

        variable2.value = 400

        test.assert_results(200, 300)
Esempio n. 3
0
    def test_synchronizing_2(self):
        test = NotifyTestObject()

        variable1 = Variable()
        variable2 = Variable()

        variable1.value = 100
        variable2.value = 200

        variable1.changed.connect(test.simple_handler)

        with nested(ignoring_exceptions(), variable1.synchronizing(variable2)):
            variable2.value = 300
            raise Exception

        variable2.value = 400

        test.assert_results(200, 300)
Esempio n. 4
0
    def test_with_changes_frozen_1(self):
        test = NotifyTestObject()
        variable = Variable()

        variable.changed.connect(test.simple_handler)
        variable.with_changes_frozen(lambda: None)

        # Must not emit `changed' signal: no changes at all.
        test.assert_results()
Esempio n. 5
0
    def test_changes_frozen_2(self):
        test = NotifyTestObject()
        variable = Variable()

        variable.changed.connect(test.simple_handler)

        with variable.changes_frozen():
            variable.value = 1

        test.assert_results(1)
Esempio n. 6
0
    def test_storing_1(self):
        test = NotifyTestObject()

        variable = Variable()
        variable.value = 100

        with variable.storing(test.simple_handler):
            variable.value = 200

        variable.value = 300

        test.assert_results(100, 200)
Esempio n. 7
0
    def test_changes_frozen_4(self):
        test = NotifyTestObject()
        variable = Variable()

        variable.changed.connect(test.simple_handler)

        with variable.changes_frozen():
            variable.value = 1
            variable.value = None

        # Must not emit: value returned to original.
        test.assert_results()
Esempio n. 8
0
    def test_with_changes_frozen_3(self):
        test = NotifyTestObject()
        variable = Variable()

        variable.changed.connect(test.simple_handler)

        def do_changes():
            variable.value = 1
            variable.value = 2

        variable.with_changes_frozen(do_changes)

        test.assert_results(2)
Esempio n. 9
0
    def test_storing_2(self):
        test = NotifyTestObject()

        variable = Variable()
        variable.value = 100

        with nested(ignoring_exceptions(),
                    variable.storing(test.simple_handler)):
            variable.value = 200
            raise Exception

        variable.value = 300

        test.assert_results(100, 200)
Esempio n. 10
0
    def test_with_changes_frozen_7(self):
        test = NotifyTestObject()
        variable = Variable()

        variable.changed.connect(test.simple_handler)

        def do_changes_1():
            def do_changes_2():
                variable.value = 1

            variable.with_changes_frozen(do_changes_2)

            variable.value = None

        variable.with_changes_frozen(do_changes_1)

        # Must not emit: value returned to original.
        test.assert_results()
Esempio n. 11
0
    def test_garbage_collection_1(self):
        test = NotifyTestObject()

        variable = Variable()

        condition = variable.is_true()
        condition.store(test.simple_handler)
        condition = weakref.ref(condition)

        # This must not collect the `is_true' condition, even though it is not directly
        # referenced at all.
        self.collect_garbage()
        self.assertNotEqual(condition(), None)

        self.collect_garbage()
        variable.value = 10

        # This makes condition `unused' and it must become available to garbage collector
        # again.
        del variable
        self.collect_garbage()

        self.assertEqual(condition(), None)
        test.assert_results(False, True)