Пример #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"