class StateStreamTestCase(unittest.TestCase): object = None # should be set in subclass setUp def setUpForObject(self, obj): # pylint: disable=attribute-defined-outside-init self.object = obj self.updates = [] self.st = SubscriptionTester() def send(value): self.updates.extend(json.loads(value)) self.stream = StateStreamInner(send, self.object, 'urlroot', subscription_context=self.st.context) def getUpdates(self): # pylint: disable=attribute-defined-outside-init self.st.advance() self.stream._flush() # warning: implementation poking u = self.updates self.updates = [] return u
class StateStreamTestCase(unittest.TestCase): object = None # should be set in subclass setUp def setUpForObject(self, obj): # pylint: disable=attribute-defined-outside-init self.object = obj self.updates = [] self.st = SubscriptionTester() def send(value): if isinstance(value, unicode): self.updates.extend(json.loads(value)) elif isinstance(value, bytes): self.updates.append(['actually_binary', value]) self.stream = StateStreamInner(send, self.object, 'urlroot', subscription_context=self.st.context) def getUpdates(self): # pylint: disable=attribute-defined-outside-init self.st.advance() u = self.updates self.updates = [] return u
class StateStreamTestCase(unittest.TestCase): object = None # should be set in subclass setUp def setUpForObject(self, obj): # pylint: disable=attribute-defined-outside-init self.object = obj self.updates = [] self.st = SubscriptionTester() def send(value): self.updates.extend(json.loads(value)) self.stream = StateStreamInner( send, self.object, 'urlroot', subscription_context=self.st.context) def getUpdates(self): # pylint: disable=attribute-defined-outside-init self.st.advance() self.stream._flush() # warning: implementation poking u = self.updates self.updates = [] return u
def setUpForObject(self, obj): # pylint: disable=attribute-defined-outside-init self.object = obj self.updates = [] self.st = SubscriptionTester() def send(value): self.updates.extend(json.loads(value)) self.stream = StateStreamInner(send, self.object, 'urlroot', subscription_context=self.st.context)
def setUpForObject(self, obj): # pylint: disable=attribute-defined-outside-init self.object = obj self.updates = [] self.st = SubscriptionTester() def send(value): if isinstance(value, unicode): self.updates.extend(json.loads(value)) elif isinstance(value, bytes): self.updates.append(['actually_binary', value]) self.stream = StateStreamInner(send, self.object, 'urlroot', subscription_context=self.st.context)
def setUpForObject(self, obj): # pylint: disable=attribute-defined-outside-init self.object = obj self.updates = [] self.st = SubscriptionTester() def send(value): self.updates.extend(json.loads(value)) self.stream = StateStreamInner( send, self.object, 'urlroot', subscription_context=self.st.context)
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': {}, }, })
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)