예제 #1
0
 def test_poll_simple(self):
     """Poll runs the given function and calls the processor with those results."""
     with mock.patch('twisted.internet.reactor', self.clock):
         self.cleanup_loop = poll(1, self.t, self.p)
         called_with = self.p.call_args[0][0]
         self.assertIsInstance(called_with, defer.Deferred)
         called_with.addCallback(lambda x: self.assertEqual(x, 'abc'))
예제 #2
0
    def test_poll_passes_args_and_kwargs_to_target(self):
        """Poll passes extra args/kwargs to the target function."""
        def target(*args, **kwargs):
            self.assertTupleEqual(args, (1, "2", {3: 4}), "Poll target must be passed args")
            self.assertDictEqual(kwargs, {'a': 'b', 'c': 0xD}, "Poll target must be passed kwargs")

        self.cleanup_loop = poll(1, target, lambda x: x, 1, "2", {3: 4}, a='b', c=0xD)
예제 #3
0
 def test_poll_simple(self):
     """Poll runs the given function and calls the processor with those results."""
     with mock.patch('twisted.internet.reactor', self.clock):
         self.cleanup_loop = poll(1, self.t, self.p)
         called_with = self.p.call_args[0][0]
         self.assertIsInstance(called_with, defer.Deferred)
         called_with.addCallback(lambda x: self.assertEqual(x, 'abc'))
예제 #4
0
 def test_poll_repeats_calls_at_correct_intervals(self):
     """"""
     with mock.patch('twisted.internet.reactor', self.clock):
         time = 3
         self.cleanup_loop = poll(time, self.t, self.p)
         self.clock.advance(time)
         self.clock.advance(time)
         self.assertEqual(self.t.call_count, 3)
         self.assertEqual(self.p.call_count, 3)
예제 #5
0
 def test_poll_repeats_calls_at_correct_intervals(self):
     """"""
     with mock.patch('twisted.internet.reactor', self.clock):
         time = 3
         self.cleanup_loop = poll(time, self.t, self.p)
         self.clock.advance(time)
         self.clock.advance(time)
         self.assertEqual(self.t.call_count, 3)
         self.assertEqual(self.p.call_count, 3)
예제 #6
0
    def test_poll_passes_args_and_kwargs_to_target(self):
        """Poll passes extra args/kwargs to the target function."""
        def target(*args, **kwargs):
            self.assertTupleEqual(args, (1, "2", {
                3: 4
            }), "Poll target must be passed args")
            self.assertDictEqual(kwargs, {
                'a': 'b',
                'c': 0xD
            }, "Poll target must be passed kwargs")

        self.cleanup_loop = poll(1,
                                 target,
                                 lambda x: x,
                                 1,
                                 "2", {3: 4},
                                 a='b',
                                 c=0xD)
예제 #7
0
 def startService(self):
     super(ForexConverterService, self).startService()
     if not self.updater:
         self.updater = utils.poll(5 * 60, self.update_rates, lambda x: x)
예제 #8
0
 def startService(self):
     super(ForexConverterService, self).startService()
     if not self.updater:
         self.updater = utils.poll(5 * 60, self.update_rates, lambda x: x)