def test_call(self):
     fn = Mock()
     _fn = blocking(fn)
     reader = Mock()
     timeout = 10
     message = _fn(reader, timeout)
     fn.assert_called_once_with(reader, timeout)
     self.assertEqual(message, fn.return_value)
Exemple #2
0
 def test_call(self):
     fn = Mock()
     _fn = blocking(fn)
     reader = Mock()
     timeout = 10
     message = _fn(reader, timeout)
     fn.assert_called_once_with(reader, timeout)
     self.assertEqual(message, fn.return_value)
 def test_call_blocking(self, sleep):
     fn = Mock(return_value=None)
     _fn = blocking(fn)
     reader = Mock()
     timeout = 10
     message = _fn(reader, timeout)
     self.assertEqual(message, None)
     total = 0.0
     for call in sleep.call_args_list:
         total += call[0][0]
     self.assertEqual(int(total), timeout)
     self.assertEqual(fn.call_count, 43)
Exemple #4
0
 def test_call_blocking(self, sleep):
     fn = Mock(return_value=None)
     _fn = blocking(fn)
     reader = Mock()
     timeout = 10
     message = _fn(reader, timeout)
     self.assertEqual(message, None)
     total = 0.0
     for call in sleep.call_args_list:
         total += call[0][0]
     self.assertEqual(int(total), timeout)
     self.assertEqual(fn.call_count, 43)
Exemple #5
0
 def test_delay(self, sleep):
     received = [None, None, Mock()]
     fn = Mock(side_effect=received)
     _fn = blocking(fn)
     reader = Mock()
     timeout = 10
     message = _fn(reader, timeout)
     self.assertEqual(
         fn.call_args_list,
         [((reader, float(timeout)), {}),
          ((reader, float(timeout - DELAY)), {}),
          ((reader, float(timeout - (DELAY +
                                     (DELAY * DELAY_MULTIPLIER)))), {})])
     self.assertEqual(sleep.call_args_list,
                      [((DELAY, ), {}), ((DELAY * DELAY_MULTIPLIER, ), {})])
     self.assertEqual(message, received[-1])
 def test_delay(self, sleep):
     received = [
         None,
         None,
         Mock()]
     fn = Mock(side_effect=received)
     _fn = blocking(fn)
     reader = Mock()
     timeout = 10
     message = _fn(reader, timeout)
     self.assertEqual(
         fn.call_args_list,
         [
             ((reader, float(timeout)), {}),
             ((reader, float(timeout - DELAY)), {}),
             ((reader, float(timeout - (DELAY + (DELAY * DELAY_MULTIPLIER)))), {})
         ])
     self.assertEqual(
         sleep.call_args_list,
         [
             ((DELAY,), {}),
             ((DELAY * DELAY_MULTIPLIER,), {})
         ])
     self.assertEqual(message, received[-1])