Esempio n. 1
0
class StateStreamTestCase(unittest.TestCase):
    object = None  # should be set in subclass setUp
    
    def setUpForObject(self, obj):
        self.object = obj
        self.updates = []
        self.poller = Poller()
        
        def send(value):
            self.updates.extend(json.loads(value))
        
        self.stream = StateStreamInner(
            send,
            self.object,
            'urlroot',
            lambda: None,  # TODO test noteDirty or make it unnecessary
            poller=self.poller)
    
    def getUpdates(self):
        # warning: implementation poking
        self.poller.poll()
        self.stream._flush()
        u = self.updates
        self.updates = []
        return u
Esempio n. 2
0
class StateStreamTestCase(unittest.TestCase):
    object = None  # should be set in subclass setUp

    def setUpForObject(self, obj):
        self.object = obj
        self.updates = []
        self.poller = Poller()

        def send(value):
            self.updates.extend(json.loads(value))

        self.stream = StateStreamInner(
            send,
            self.object,
            'urlroot',
            lambda: None,  # TODO test noteDirty or make it unnecessary
            poller=self.poller)

    def getUpdates(self):
        # warning: implementation poking
        self.poller.poll()
        self.stream._flush()
        u = self.updates
        self.updates = []
        return u
Esempio n. 3
0
 def setUpForObject(self, obj):
     self.object = obj
     self.updates = []
     self.poller = Poller()
     
     def send(value):
         self.updates.extend(json.loads(value))
     
     self.stream = StateStreamInner(send, self.object, 'urlroot', poller=self.poller)
Esempio n. 4
0
    def setUpForObject(self, obj):
        self.object = obj
        self.updates = []
        self.poller = Poller()

        def send(value):
            self.updates.extend(json.loads(value))

        self.stream = StateStreamInner(
            send,
            self.object,
            'urlroot',
            lambda: None,  # TODO test noteDirty or make it unnecessary
            poller=self.poller)
Esempio n. 5
0
 def setUpForObject(self, obj):
     self.object = obj
     self.updates = []
     self.poller = Poller()
     
     def send(value):
         self.updates.extend(json.loads(value))
     
     self.stream = StateStreamInner(send, self.object, 'urlroot', poller=self.poller)
Esempio n. 6
0
 def setUpForObject(self, obj):
     self.object = obj
     self.updates = []
     self.poller = Poller()
     
     def send(value):
         self.updates.extend(json.loads(value))
     
     self.stream = StateStreamInner(
         send,
         self.object,
         'urlroot',
         lambda: None,  # TODO test noteDirty or make it unnecessary
         poller=self.poller)
Esempio n. 7
0
 def setUp(self):
     self.poller = Poller()
     self.cells = PollerCellsSpecimen()
Esempio n. 8
0
class TestPoller(unittest.TestCase):
    def setUp(self):
        self.poller = Poller()
        self.cells = PollerCellsSpecimen()
    
    def test_trivial(self):
        cell = self.cells.state()['foo']
        called = [0]
        
        def callback():
            called[0] += 1
        
        sub = self.poller.subscribe(cell, callback)
        self.assertEqual(0, called[0], 'initial')
        self.poller.poll()
        self.assertEqual(0, called[0], 'noop poll')
        self.cells.set_foo('a')
        self.assertEqual(0, called[0], 'after set')
        self.poller.poll()
        self.assertEqual(1, called[0], 'poll after set')
        
        sub.unsubscribe()
        self.cells.set_subscribable('b')
        self.poller.poll()
        self.assertEqual(1, called[0], 'no poll after unsubscribe')
    
    def test_subscription_support(self):
        cell = self.cells.state()['subscribable']
        called = [0]
        
        def callback():
            called[0] += 1
        
        sub = self.poller.subscribe(cell, callback)
        self.assertEqual(0, self.poller._Poller__targets.count_keys(), 'no polling')
        self.assertEqual(0, called[0], 'initial')
        self.cells.set_subscribable('a')
        self.assertEqual(0, called[0], 'after set')
        self.assertEqual('a', self.cells.get_subscribable())
        self.poller.poll()
        self.assertEqual(1, called[0], 'poll after set')
        
        sub.unsubscribe()
        self.cells.set_subscribable('b')
        self.poller.poll()
        self.assertEqual(1, called[0], 'no poll after unsubscribe')
Esempio n. 9
0
 def setUp(self):
     self.poller = Poller()
     self.cells = PollerCellsSpecimen()
Esempio n. 10
0
class TestPoller(unittest.TestCase):
    def setUp(self):
        self.poller = Poller()
        self.cells = PollerCellsSpecimen()
    
    def test_trivial(self):
        cell = self.cells.state()['foo']
        called = [0]
        
        def callback():
            called[0] += 1
        
        sub = self.poller.subscribe(cell, callback)
        self.assertEqual(0, called[0], 'initial')
        self.poller.poll()
        self.assertEqual(0, called[0], 'noop poll')
        self.cells.set_foo('a')
        self.assertEqual(0, called[0], 'after set')
        self.poller.poll()
        self.assertEqual(1, called[0], 'poll after set')
        
        sub.unsubscribe()
        self.cells.set_subscribable('b')
        self.poller.poll()
        self.assertEqual(1, called[0], 'no poll after unsubscribe')
    
    def test_subscription_support(self):
        cell = self.cells.state()['subscribable']
        called = [0]
        
        def callback():
            called[0] += 1
        
        sub = self.poller.subscribe(cell, callback)
        self.assertEqual(0, self.poller._Poller__targets.count_keys(), 'no polling')
        self.assertEqual(0, called[0], 'initial')
        self.cells.set_subscribable('a')
        self.assertEqual(0, called[0], 'after set')
        self.assertEqual('a', self.cells.get_subscribable())
        self.poller.poll()
        self.assertEqual(1, called[0], 'poll after set')
        
        sub.unsubscribe()
        self.cells.set_subscribable('b')
        self.poller.poll()
        self.assertEqual(1, called[0], 'no poll after unsubscribe')