示例#1
0
	def test_cleanup_called_on_exception(self):
		calls = random.randint(1, 10)
		cleanup = mock.Mock()
		self.set_to_fail(times=calls)
		retry_call(self.attempt, retries=calls, cleanup=cleanup, trap=Exception)
		assert cleanup.call_count == calls
		assert cleanup.called_with()
示例#2
0
 def test_infinite_retries(self):
     self.set_to_fail(times=999)
     cleanup = mock.Mock()
     retry_call(self.attempt,
                retries=float('inf'),
                cleanup=cleanup,
                trap=Exception)
     assert cleanup.call_count == 999
示例#3
0
	def test_retry_call_fails(self):
		"""
		Failing more than the number of retries should
		raise the underlying error.
		"""
		self.set_to_fail(times=3)
		with pytest.raises(ValueError) as res:
			retry_call(self.attempt, retries=2, trap=ValueError)
		assert str(res.value) == 'Failed!'
示例#4
0
 def test_retry_call_fails(self):
     """
     Failing more than the number of retries should
     raise the underlying error.
     """
     self.set_to_fail(times=3)
     with pytest.raises(ValueError) as res:
         retry_call(self.attempt, retries=2, trap=ValueError)
     assert str(res.value) == 'Failed!'
示例#5
0
 def test_cleanup_called_on_exception(self):
     calls = random.randint(1, 10)
     cleanup = mock.Mock()
     self.set_to_fail(times=calls)
     retry_call(self.attempt,
                retries=calls,
                cleanup=cleanup,
                trap=Exception)
     assert cleanup.call_count == calls
     assert cleanup.called_with()
示例#6
0
 def test_with_arg(self):
     self.set_to_fail(times=0)
     arg = mock.Mock()
     bound = functools.partial(self.attempt, arg)
     res = retry_call(bound)
     assert res == 'Success'
     assert arg.touch.called
示例#7
0
    def acquire(self):
        """
        Attempt to acquire the lock every `delay` seconds until the
        lock is acquired or until `timeout` has expired.

        Raises FileLockTimeout if the timeout is exceeded.

        Errors opening the lock file (other than if it exists) are
        passed through.
        """
        self.lock = retry_call(
            self._attempt,
            retries=float('inf'),
            trap=zc.lockfile.LockError,
            cleanup=functools.partial(self._check_timeout, timing.Stopwatch()),
        )
示例#8
0
	def test_retry_call_succeeds(self):
		self.set_to_fail(times=2)
		res = retry_call(self.attempt, retries=2, trap=ValueError)
		assert res == "Success"
示例#9
0
	def test_retry_exception_superclass(self):
		self.set_to_fail(times=2)
		res = retry_call(self.attempt, retries=2, trap=Exception)
		assert res == "Success"
示例#10
0
	def test_retry_multiple_exceptions(self):
		self.set_to_fail(times=2)
		errors = ValueError, NameError
		res = retry_call(self.attempt, retries=2, trap=errors)
		assert res == "Success"
示例#11
0
 def test_default_does_not_retry(self):
     self.set_to_fail(times=1)
     with pytest.raises(ValueError):
         retry_call(self.attempt, trap=Exception)
示例#12
0
	def test_default_traps_nothing(self):
		self.set_to_fail(times=1)
		with pytest.raises(ValueError):
			retry_call(self.attempt, retries=1)
示例#13
0
 def test_default_traps_nothing(self):
     self.set_to_fail(times=1)
     with pytest.raises(ValueError):
         retry_call(self.attempt, retries=1)
示例#14
0
 def test_retry_exception_superclass(self):
     self.set_to_fail(times=2)
     res = retry_call(self.attempt, retries=2, trap=Exception)
     assert res == "Success"
示例#15
0
 def test_retry_multiple_exceptions(self):
     self.set_to_fail(times=2)
     errors = ValueError, NameError
     res = retry_call(self.attempt, retries=2, trap=errors)
     assert res == "Success"
示例#16
0
	def test_default_does_not_retry(self):
		self.set_to_fail(times=1)
		with pytest.raises(ValueError):
			retry_call(self.attempt, trap=Exception)
示例#17
0
 def test_retry_call_succeeds(self):
     self.set_to_fail(times=2)
     res = retry_call(self.attempt, retries=2, trap=ValueError)
     assert res == "Success"