Esempio n. 1
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. 2
0
    def test_changes_frozen_6 (self):
        test     = NotifyTestObject ()
        variable = Variable ()

        variable.changed.connect (test.simple_handler)

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

        test.assert_results (2)
Esempio n. 3
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. 4
0
    def test_changes_frozen_6(self):
        test = NotifyTestObject()
        variable = Variable()

        variable.changed.connect(test.simple_handler)

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

        test.assert_results(2)
Esempio n. 5
0
    def test_transformation_1 (self):
        variable = Variable (0)
        floor    = variable.transform (math.floor)

        self.assertEqual (floor.value, 0)
        self.assert_(not floor.mutable)

        variable.value = 10.5
        self.assertEqual (floor.value, 10)

        variable.value = 15
        self.assertEqual (floor.value, 15)
Esempio n. 6
0
    def test_predicate_2 (self):
        test = NotifyTestObject ()

        variable = Variable (0)
        variable.predicate (lambda value: 0 <= value < 10).store (test.simple_handler)

        variable.value = 5
        variable.value = 15
        variable.value = -1
        variable.value = 9
        variable.value = 3

        test.assert_results (True, False, True)
Esempio n. 7
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. 8
0
    def test_changes_frozen_7 (self):
        test     = NotifyTestObject ()
        variable = Variable ()

        variable.changed.connect (test.simple_handler)

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

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

        variable.changed.connect(test.simple_handler)

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

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

        variable = Variable (0)
        variable.transform (math.floor).store (test.simple_handler)

        variable.value = 5
        variable.value = 5.6
        variable.value = 15.7
        variable.value = 16
        variable.value = 16.5
        variable.value = 16.2

        test.assert_results (0, 5, 15, 16)
Esempio n. 11
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. 12
0
    def test_predicate_1 (self):
        variable        = Variable (0)
        is_single_digit = variable.predicate (lambda value: 0 <= value < 10)

        self.assert_(is_single_digit)
        self.assert_(not is_single_digit.mutable)

        variable.value = -5
        self.assert_(not is_single_digit)

        variable.value = 9
        self.assert_(is_single_digit)

        variable.value = 100
        self.assert_(not is_single_digit)
Esempio n. 13
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. 14
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. 15
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. 16
0
    def test_is_true (self):
        variable = Variable (0)
        is_true  = variable.is_true ()

        self.assert_(not is_true)

        variable.value = 'string'
        self.assert_(is_true)

        variable.value = []
        self.assert_(not is_true)

        variable.value = None
        self.assert_(not is_true)

        variable.value = 25
        self.assert_(is_true)
Esempio n. 17
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. 18
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. 19
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. 20
0
    def test_watcher_variable_1 (self):
        test = NotifyTestObject ()

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

        variable = Variable ('abc')
        watcher.watch (variable)

        self.assert_(watcher.watched_variable is variable)

        variable.value = 60

        test.assert_results (None, 'abc', 60)
Esempio n. 21
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)
Esempio n. 22
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)