mirror of
https://github.com/tahoe-lafs/tahoe-lafs.git
synced 2025-01-19 03:06:33 +00:00
Merge remote-tracking branch 'origin/master' into 3988-failing-test-http
This commit is contained in:
commit
ab300c090a
1
newsfragments/3989.installation
Normal file
1
newsfragments/3989.installation
Normal file
@ -0,0 +1 @@
|
||||
tenacity is no longer a dependency.
|
@ -58,7 +58,6 @@ let
|
||||
pytest
|
||||
pytest-timeout
|
||||
pytest-twisted
|
||||
tenacity
|
||||
testtools
|
||||
towncrier
|
||||
];
|
||||
|
1
setup.py
1
setup.py
@ -413,7 +413,6 @@ setup(name="tahoe-lafs", # also set in __init__.py
|
||||
"beautifulsoup4",
|
||||
"html5lib",
|
||||
"junitxml",
|
||||
"tenacity",
|
||||
# Pin old version until
|
||||
# https://github.com/paramiko/paramiko/issues/1961 is fixed.
|
||||
"paramiko < 2.9",
|
||||
|
@ -4,18 +4,13 @@ Tests for allmydata.util.iputil.
|
||||
Ported to Python 3.
|
||||
"""
|
||||
|
||||
from __future__ import absolute_import
|
||||
from __future__ import division
|
||||
from __future__ import print_function
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from future.utils import PY2, native_str
|
||||
if PY2:
|
||||
from builtins import filter, map, zip, ascii, chr, hex, input, next, oct, open, pow, round, super, bytes, dict, list, object, range, str, max, min # noqa: F401
|
||||
from __future__ import annotations
|
||||
|
||||
import os, socket
|
||||
import gc
|
||||
from functools import wraps
|
||||
|
||||
from typing import TypeVar, Callable
|
||||
from testtools.matchers import (
|
||||
MatchesAll,
|
||||
IsInstance,
|
||||
@ -25,8 +20,6 @@ from testtools.matchers import (
|
||||
|
||||
from twisted.trial import unittest
|
||||
|
||||
from tenacity import retry, stop_after_attempt
|
||||
|
||||
from foolscap.api import Tub
|
||||
|
||||
from allmydata.util import iputil, gcutil
|
||||
@ -39,6 +32,43 @@ from .common import (
|
||||
SyncTestCase,
|
||||
)
|
||||
|
||||
T = TypeVar("T", contravariant=True)
|
||||
U = TypeVar("U", covariant=True)
|
||||
|
||||
def retry(stop: Callable[[], bool]) -> Callable[[Callable[[T], U]], Callable[[T], U]]:
|
||||
"""
|
||||
Call a function until the predicate says to stop or the function stops
|
||||
raising an exception.
|
||||
|
||||
:param stop: A callable to call after the decorated function raises an
|
||||
exception. The decorated function will be called again if ``stop``
|
||||
returns ``False``.
|
||||
|
||||
:return: A decorator function.
|
||||
"""
|
||||
def decorate(f: Callable[[T], U]) -> Callable[[T], U]:
|
||||
@wraps(f)
|
||||
def decorator(self: T) -> U:
|
||||
while True:
|
||||
try:
|
||||
return f(self)
|
||||
except Exception:
|
||||
if stop():
|
||||
raise
|
||||
return decorator
|
||||
return decorate
|
||||
|
||||
def stop_after_attempt(limit: int) -> Callable[[], bool]:
|
||||
"""
|
||||
Stop after ``limit`` calls.
|
||||
"""
|
||||
counter = 0
|
||||
def check():
|
||||
nonlocal counter
|
||||
counter += 1
|
||||
return counter < limit
|
||||
return check
|
||||
|
||||
class ListenOnUsed(unittest.TestCase):
|
||||
"""Tests for listenOnUnused."""
|
||||
|
||||
@ -127,7 +157,7 @@ class GetLocalAddressesSyncTests(SyncTestCase):
|
||||
IsInstance(list),
|
||||
AllMatch(
|
||||
MatchesAll(
|
||||
IsInstance(native_str),
|
||||
IsInstance(str),
|
||||
MatchesPredicate(
|
||||
lambda addr: socket.inet_pton(socket.AF_INET, addr),
|
||||
"%r is not an IPv4 address.",
|
||||
|
Loading…
Reference in New Issue
Block a user