Beispiel #1
0
class TestPersistenceChangeDetector(unittest.TestCase):
    def setUp(self):
        self.st = SubscriptionTester()
        self.o = ValueAndBlockSpecimen(ValueAndBlockSpecimen(ExportedState()))
        self.calls = 0
        self.d = PersistenceChangeDetector(
            self.o, self.__callback, subscription_context=self.st.context)

    def __callback(self):
        self.calls += 1

    def test_1(self):
        self.assertEqual(self.d.get(), {
            'value': 'initial',
            'block': {
                'value': 'initial',
                'block': {},
            },
        })
        self.assertEqual(0, self.calls)
        self.o.set_value('one')
        self.assertEqual(0, self.calls)
        self.st.advance()
        self.assertEqual(1, self.calls)
        self.o.set_value('two')
        self.st.advance()
        self.assertEqual(1, self.calls)  # only fires once
        self.assertEqual(self.d.get(), {
            u'value': 'two',
            u'block': {
                u'value': 'initial',
                u'block': {},
            },
        })
        self.st.advance()
        self.assertEqual(1, self.calls)
        self.o.get_block().set_value('three')  # pylint: disable=no-member
        self.st.advance()
        self.assertEqual(2, self.calls)
        self.assertEqual(self.d.get(), {
            u'value': 'two',
            u'block': {
                u'value': 'three',
                u'block': {},
            },
        })
Beispiel #2
0
class TestPersistenceChangeDetector(unittest.TestCase):
    def setUp(self):
        self.st = SubscriptionTester()
        self.o = ValueAndBlockSpecimen(ValueAndBlockSpecimen(ExportedState()))
        self.calls = 0
        self.d = PersistenceChangeDetector(self.o, self.__callback, subscription_context=self.st.context)
    
    def __callback(self):
        self.calls += 1
    
    def test_1(self):
        self.assertEqual(self.d.get(), {
            'value': 'initial',
            'block': {
                'value': 'initial',
                'block': {},
            },
        })
        self.assertEqual(0, self.calls)
        self.o.set_value('one')
        self.assertEqual(0, self.calls)
        self.st.advance()
        self.assertEqual(1, self.calls)
        self.o.set_value('two')
        self.st.advance()
        self.assertEqual(1, self.calls)  # only fires once
        self.assertEqual(self.d.get(), {
            u'value': 'two',
            u'block': {
                u'value': 'initial',
                u'block': {},
            },
        })
        self.st.advance()
        self.assertEqual(1, self.calls)
        self.o.get_block().set_value('three')  # pylint: disable=no-member
        self.st.advance()
        self.assertEqual(2, self.calls)
        self.assertEqual(self.d.get(), {
            u'value': 'two',
            u'block': {
                u'value': 'three',
                u'block': {},
            },
        })
 def setUp(self):
     self.st = SubscriptionTester()
     self.o = ValueAndBlockSpecimen(ValueAndBlockSpecimen(ExportedState()))
     self.calls = 0
     self.d = PersistenceChangeDetector(self.o, self.__callback, subscription_context=self.st.context)
Beispiel #4
0
 def setUp(self):
     self.st = SubscriptionTester()
     self.o = ValueAndBlockSpecimen(ValueAndBlockSpecimen(ExportedState()))
     self.calls = 0
     self.d = PersistenceChangeDetector(self.o, self.__callback, subscription_context=self.st.context)