rdobuilder 7906f7
diff -rU3 greenlet-2.0.2-orig/src/greenlet/tests/leakcheck.py greenlet-2.0.2/src/greenlet/tests/leakcheck.py
rdobuilder 7906f7
--- greenlet-2.0.2-orig/src/greenlet/tests/leakcheck.py	2023-01-28 15:19:12.000000000 +0100
rdobuilder 7906f7
+++ greenlet-2.0.2/src/greenlet/tests/leakcheck.py	2023-06-14 17:49:32.395412453 +0200
rdobuilder 7906f7
@@ -30,39 +30,7 @@
rdobuilder 7906f7
 from functools import wraps
rdobuilder 7906f7
 import unittest
rdobuilder 7906f7
 
rdobuilder 7906f7
-
rdobuilder 7906f7
-import objgraph
rdobuilder 7906f7
-
rdobuilder 7906f7
-# graphviz 0.18 (Nov 7 2021), available only on Python 3.6 and newer,
rdobuilder 7906f7
-# has added type hints (sigh). It wants to use ``typing.Literal`` for
rdobuilder 7906f7
-# some stuff, but that's only available on Python 3.9+. If that's not
rdobuilder 7906f7
-# found, it creates a ``unittest.mock.MagicMock`` object and annotates
rdobuilder 7906f7
-# with that. These are GC'able objects, and doing almost *anything*
rdobuilder 7906f7
-# with them results in an explosion of objects. For example, trying to
rdobuilder 7906f7
-# compare them for equality creates new objects. This causes our
rdobuilder 7906f7
-# leakchecks to fail, with reports like:
rdobuilder 7906f7
-#
rdobuilder 7906f7
-# greenlet.tests.leakcheck.LeakCheckError: refcount increased by [337, 1333, 343, 430, 530, 643, 769]
rdobuilder 7906f7
-# _Call          1820      +546
rdobuilder 7906f7
-# dict           4094       +76
rdobuilder 7906f7
-# MagicProxy      585       +73
rdobuilder 7906f7
-# tuple          2693       +66
rdobuilder 7906f7
-# _CallList        24        +3
rdobuilder 7906f7
-# weakref        1441        +1
rdobuilder 7906f7
-# function       5996        +1
rdobuilder 7906f7
-# type            736        +1
rdobuilder 7906f7
-# cell            592        +1
rdobuilder 7906f7
-# MagicMock         8        +1
rdobuilder 7906f7
-#
rdobuilder 7906f7
-# To avoid this, we *could* filter this type of object out early. In
rdobuilder 7906f7
-# principle it could leak, but we don't use mocks in greenlet, so it
rdobuilder 7906f7
-# doesn't leak from us. However, a further issue is that ``MagicMock``
rdobuilder 7906f7
-# objects have subobjects that are also GC'able, like ``_Call``, and
rdobuilder 7906f7
-# those create new mocks of their own too. So we'd have to filter them
rdobuilder 7906f7
-# as well, and they're not public. That's OK, we can workaround the
rdobuilder 7906f7
-# problem by being very careful to never compare by equality or other
rdobuilder 7906f7
-# user-defined operators, only using object identity or other builtin
rdobuilder 7906f7
-# functions.
rdobuilder 7906f7
+# Edited for Fedora to avoid missing dependency
rdobuilder 7906f7
 
rdobuilder 7906f7
 RUNNING_ON_GITHUB_ACTIONS = os.environ.get('GITHUB_ACTIONS')
rdobuilder 7906f7
 RUNNING_ON_TRAVIS = os.environ.get('TRAVIS') or RUNNING_ON_GITHUB_ACTIONS
rdobuilder 7906f7
@@ -74,53 +42,15 @@
rdobuilder 7906f7
 ONLY_FAILING_LEAKCHECKS = os.environ.get('GREENLET_ONLY_FAILING_LEAKCHECKS')
rdobuilder 7906f7
 
rdobuilder 7906f7
 def ignores_leakcheck(func):
rdobuilder 7906f7
-    """
rdobuilder 7906f7
-    Ignore the given object during leakchecks.
rdobuilder 7906f7
-
rdobuilder 7906f7
-    Can be applied to a method, in which case the method will run, but
rdobuilder 7906f7
-    will not be subject to leak checks.
rdobuilder 7906f7
-
rdobuilder 7906f7
-    If applied to a class, the entire class will be skipped during leakchecks. This
rdobuilder 7906f7
-    is intended to be used for classes that are very slow and cause problems such as
rdobuilder 7906f7
-    test timeouts; typically it will be used for classes that are subclasses of a base
rdobuilder 7906f7
-    class and specify variants of behaviour (such as pool sizes).
rdobuilder 7906f7
-    """
rdobuilder 7906f7
-    func.ignore_leakcheck = True
rdobuilder 7906f7
     return func
rdobuilder 7906f7
 
rdobuilder 7906f7
 def fails_leakcheck(func):
rdobuilder 7906f7
-    """
rdobuilder 7906f7
-    Mark that the function is known to leak.
rdobuilder 7906f7
-    """
rdobuilder 7906f7
-    func.fails_leakcheck = True
rdobuilder 7906f7
-    if SKIP_FAILING_LEAKCHECKS:
rdobuilder 7906f7
-        func = unittest.skip("Skipping known failures")(func)
rdobuilder 7906f7
     return func
rdobuilder 7906f7
 
rdobuilder 7906f7
 class LeakCheckError(AssertionError):
rdobuilder 7906f7
     pass
rdobuilder 7906f7
 
rdobuilder 7906f7
-if hasattr(sys, 'getobjects'):
rdobuilder 7906f7
-    # In a Python build with ``--with-trace-refs``, make objgraph
rdobuilder 7906f7
-    # trace *all* the objects, not just those that are tracked by the
rdobuilder 7906f7
-    # GC
rdobuilder 7906f7
-    class _MockGC(object):
rdobuilder 7906f7
-        def get_objects(self):
rdobuilder 7906f7
-            return sys.getobjects(0) # pylint:disable=no-member
rdobuilder 7906f7
-        def __getattr__(self, name):
rdobuilder 7906f7
-            return getattr(gc, name)
rdobuilder 7906f7
-    objgraph.gc = _MockGC()
rdobuilder 7906f7
-    fails_strict_leakcheck = fails_leakcheck
rdobuilder 7906f7
-else:
rdobuilder 7906f7
-    def fails_strict_leakcheck(func):
rdobuilder 7906f7
-        """
rdobuilder 7906f7
-        Decorator for a function that is known to fail when running
rdobuilder 7906f7
-        strict (``sys.getobjects()``) leakchecks.
rdobuilder 7906f7
-
rdobuilder 7906f7
-        This type of leakcheck finds all objects, even those, such as
rdobuilder 7906f7
-        strings, which are not tracked by the garbage collector.
rdobuilder 7906f7
-        """
rdobuilder 7906f7
-        return func
rdobuilder 7906f7
+fails_strict_leakcheck = fails_leakcheck
rdobuilder 7906f7
 
rdobuilder 7906f7
 class ignores_types_in_strict_leakcheck(object):
rdobuilder 7906f7
     def __init__(self, types):
rdobuilder 7906f7
@@ -129,190 +59,5 @@
rdobuilder 7906f7
         func.leakcheck_ignore_types = self.types
rdobuilder 7906f7
         return func
rdobuilder 7906f7
 
rdobuilder 7906f7
-class _RefCountChecker(object):
rdobuilder 7906f7
-
rdobuilder 7906f7
-    # Some builtin things that we ignore
rdobuilder 7906f7
-    # XXX: Those things were ignored by gevent, but they're important here,
rdobuilder 7906f7
-    # presumably.
rdobuilder 7906f7
-    IGNORED_TYPES = () #(tuple, dict, types.FrameType, types.TracebackType)
rdobuilder 7906f7
-
rdobuilder 7906f7
-    def __init__(self, testcase, function):
rdobuilder 7906f7
-        self.testcase = testcase
rdobuilder 7906f7
-        self.function = function
rdobuilder 7906f7
-        self.deltas = []
rdobuilder 7906f7
-        self.peak_stats = {}
rdobuilder 7906f7
-        self.ignored_types = ()
rdobuilder 7906f7
-
rdobuilder 7906f7
-        # The very first time we are called, we have already been
rdobuilder 7906f7
-        # self.setUp() by the test runner, so we don't need to do it again.
rdobuilder 7906f7
-        self.needs_setUp = False
rdobuilder 7906f7
-
rdobuilder 7906f7
-    def _include_object_p(self, obj):
rdobuilder 7906f7
-        # pylint:disable=too-many-return-statements
rdobuilder 7906f7
-        #
rdobuilder 7906f7
-        # See the comment block at the top. We must be careful to
rdobuilder 7906f7
-        # avoid invoking user-defined operations.
rdobuilder 7906f7
-        if obj is self:
rdobuilder 7906f7
-            return False
rdobuilder 7906f7
-        kind = type(obj)
rdobuilder 7906f7
-        # ``self._include_object_p == obj`` returns NotImplemented
rdobuilder 7906f7
-        # for non-function objects, which causes the interpreter
rdobuilder 7906f7
-        # to try to reverse the order of arguments...which leads
rdobuilder 7906f7
-        # to the explosion of mock objects. We don't want that, so we implement
rdobuilder 7906f7
-        # the check manually.
rdobuilder 7906f7
-        if kind == type(self._include_object_p):
rdobuilder 7906f7
-            try:
rdobuilder 7906f7
-                # pylint:disable=not-callable
rdobuilder 7906f7
-                exact_method_equals = self._include_object_p.__eq__(obj)
rdobuilder 7906f7
-            except AttributeError:
rdobuilder 7906f7
-                # Python 2.7 methods may only have __cmp__, and that raises a
rdobuilder 7906f7
-                # TypeError for non-method arguments
rdobuilder 7906f7
-                # pylint:disable=no-member
rdobuilder 7906f7
-                exact_method_equals = self._include_object_p.__cmp__(obj) == 0
rdobuilder 7906f7
-
rdobuilder 7906f7
-            if exact_method_equals is not NotImplemented and exact_method_equals:
rdobuilder 7906f7
-                return False
rdobuilder 7906f7
-
rdobuilder 7906f7
-        # Similarly, we need to check identity in our __dict__ to avoid mock explosions.
rdobuilder 7906f7
-        for x in self.__dict__.values():
rdobuilder 7906f7
-            if obj is x:
rdobuilder 7906f7
-                return False
rdobuilder 7906f7
-
rdobuilder 7906f7
-
rdobuilder 7906f7
-        if kind in self.ignored_types or kind in self.IGNORED_TYPES:
rdobuilder 7906f7
-            return False
rdobuilder 7906f7
-
rdobuilder 7906f7
-        return True
rdobuilder 7906f7
-
rdobuilder 7906f7
-    def _growth(self):
rdobuilder 7906f7
-        return objgraph.growth(limit=None, peak_stats=self.peak_stats,
rdobuilder 7906f7
-                               filter=self._include_object_p)
rdobuilder 7906f7
-
rdobuilder 7906f7
-    def _report_diff(self, growth):
rdobuilder 7906f7
-        if not growth:
rdobuilder 7906f7
-            return "<Unable to calculate growth>"
rdobuilder 7906f7
-
rdobuilder 7906f7
-        lines = []
rdobuilder 7906f7
-        width = max(len(name) for name, _, _ in growth)
rdobuilder 7906f7
-        for name, count, delta in growth:
rdobuilder 7906f7
-            lines.append('%-*s%9d %+9d' % (width, name, count, delta))
rdobuilder 7906f7
-
rdobuilder 7906f7
-        diff = '\n'.join(lines)
rdobuilder 7906f7
-        return diff
rdobuilder 7906f7
-
rdobuilder 7906f7
-
rdobuilder 7906f7
-    def _run_test(self, args, kwargs):
rdobuilder 7906f7
-        gc_enabled = gc.isenabled()
rdobuilder 7906f7
-        gc.disable()
rdobuilder 7906f7
-
rdobuilder 7906f7
-        if self.needs_setUp:
rdobuilder 7906f7
-            self.testcase.setUp()
rdobuilder 7906f7
-            self.testcase.skipTearDown = False
rdobuilder 7906f7
-        try:
rdobuilder 7906f7
-            self.function(self.testcase, *args, **kwargs)
rdobuilder 7906f7
-        finally:
rdobuilder 7906f7
-            self.testcase.tearDown()
rdobuilder 7906f7
-            self.testcase.doCleanups()
rdobuilder 7906f7
-            self.testcase.skipTearDown = True
rdobuilder 7906f7
-            self.needs_setUp = True
rdobuilder 7906f7
-            if gc_enabled:
rdobuilder 7906f7
-                gc.enable()
rdobuilder 7906f7
-
rdobuilder 7906f7
-    def _growth_after(self):
rdobuilder 7906f7
-        # Grab post snapshot
rdobuilder 7906f7
-        if 'urlparse' in sys.modules:
rdobuilder 7906f7
-            sys.modules['urlparse'].clear_cache()
rdobuilder 7906f7
-        if 'urllib.parse' in sys.modules:
rdobuilder 7906f7
-            sys.modules['urllib.parse'].clear_cache()
rdobuilder 7906f7
-
rdobuilder 7906f7
-        return self._growth()
rdobuilder 7906f7
-
rdobuilder 7906f7
-    def _check_deltas(self, growth):
rdobuilder 7906f7
-        # Return false when we have decided there is no leak,
rdobuilder 7906f7
-        # true if we should keep looping, raises an assertion
rdobuilder 7906f7
-        # if we have decided there is a leak.
rdobuilder 7906f7
-
rdobuilder 7906f7
-        deltas = self.deltas
rdobuilder 7906f7
-        if not deltas:
rdobuilder 7906f7
-            # We haven't run yet, no data, keep looping
rdobuilder 7906f7
-            return True
rdobuilder 7906f7
-
rdobuilder 7906f7
-        if gc.garbage:
rdobuilder 7906f7
-            raise LeakCheckError("Generated uncollectable garbage %r" % (gc.garbage,))
rdobuilder 7906f7
-
rdobuilder 7906f7
-
rdobuilder 7906f7
-        # the following configurations are classified as "no leak"
rdobuilder 7906f7
-        # [0, 0]
rdobuilder 7906f7
-        # [x, 0, 0]
rdobuilder 7906f7
-        # [... a, b, c, d]  where a+b+c+d = 0
rdobuilder 7906f7
-        #
rdobuilder 7906f7
-        # the following configurations are classified as "leak"
rdobuilder 7906f7
-        # [... z, z, z]  where z > 0
rdobuilder 7906f7
-
rdobuilder 7906f7
-        if deltas[-2:] == [0, 0] and len(deltas) in (2, 3):
rdobuilder 7906f7
-            return False
rdobuilder 7906f7
-
rdobuilder 7906f7
-        if deltas[-3:] == [0, 0, 0]:
rdobuilder 7906f7
-            return False
rdobuilder 7906f7
-
rdobuilder 7906f7
-        if len(deltas) >= 4 and sum(deltas[-4:]) == 0:
rdobuilder 7906f7
-            return False
rdobuilder 7906f7
-
rdobuilder 7906f7
-        if len(deltas) >= 3 and deltas[-1] > 0 and deltas[-1] == deltas[-2] and deltas[-2] == deltas[-3]:
rdobuilder 7906f7
-            diff = self._report_diff(growth)
rdobuilder 7906f7
-            raise LeakCheckError('refcount increased by %r\n%s' % (deltas, diff))
rdobuilder 7906f7
-
rdobuilder 7906f7
-        # OK, we don't know for sure yet. Let's search for more
rdobuilder 7906f7
-        if sum(deltas[-3:]) <= 0 or sum(deltas[-4:]) <= 0 or deltas[-4:].count(0) >= 2:
rdobuilder 7906f7
-            # this is suspicious, so give a few more runs
rdobuilder 7906f7
-            limit = 11
rdobuilder 7906f7
-        else:
rdobuilder 7906f7
-            limit = 7
rdobuilder 7906f7
-        if len(deltas) >= limit:
rdobuilder 7906f7
-            raise LeakCheckError('refcount increased by %r\n%s'
rdobuilder 7906f7
-                                 % (deltas,
rdobuilder 7906f7
-                                    self._report_diff(growth)))
rdobuilder 7906f7
-
rdobuilder 7906f7
-        # We couldn't decide yet, keep going
rdobuilder 7906f7
-        return True
rdobuilder 7906f7
-
rdobuilder 7906f7
-    def __call__(self, args, kwargs):
rdobuilder 7906f7
-        for _ in range(3):
rdobuilder 7906f7
-            gc.collect()
rdobuilder 7906f7
-
rdobuilder 7906f7
-        expect_failure = getattr(self.function, 'fails_leakcheck', False)
rdobuilder 7906f7
-        if expect_failure:
rdobuilder 7906f7
-            self.testcase.expect_greenlet_leak = True
rdobuilder 7906f7
-        self.ignored_types = getattr(self.function, "leakcheck_ignore_types", ())
rdobuilder 7906f7
-
rdobuilder 7906f7
-        # Capture state before; the incremental will be
rdobuilder 7906f7
-        # updated by each call to _growth_after
rdobuilder 7906f7
-        growth = self._growth()
rdobuilder 7906f7
-
rdobuilder 7906f7
-        try:
rdobuilder 7906f7
-            while self._check_deltas(growth):
rdobuilder 7906f7
-                self._run_test(args, kwargs)
rdobuilder 7906f7
-
rdobuilder 7906f7
-                growth = self._growth_after()
rdobuilder 7906f7
-
rdobuilder 7906f7
-                self.deltas.append(sum((stat[2] for stat in growth)))
rdobuilder 7906f7
-        except LeakCheckError:
rdobuilder 7906f7
-            if not expect_failure:
rdobuilder 7906f7
-                raise
rdobuilder 7906f7
-        else:
rdobuilder 7906f7
-            if expect_failure:
rdobuilder 7906f7
-                raise LeakCheckError("Expected %s to leak but it did not." % (self.function,))
rdobuilder 7906f7
-
rdobuilder 7906f7
 def wrap_refcount(method):
rdobuilder 7906f7
-    if getattr(method, 'ignore_leakcheck', False) or SKIP_LEAKCHECKS:
rdobuilder 7906f7
-        return method
rdobuilder 7906f7
-
rdobuilder 7906f7
-    @wraps(method)
rdobuilder 7906f7
-    def wrapper(self, *args, **kwargs): # pylint:disable=too-many-branches
rdobuilder 7906f7
-        if getattr(self, 'ignore_leakcheck', False):
rdobuilder 7906f7
-            raise unittest.SkipTest("This class ignored during leakchecks")
rdobuilder 7906f7
-        if ONLY_FAILING_LEAKCHECKS and not getattr(method, 'fails_leakcheck', False):
rdobuilder 7906f7
-            raise unittest.SkipTest("Only running tests that fail leakchecks.")
rdobuilder 7906f7
-        return _RefCountChecker(self, method)(args, kwargs)
rdobuilder 7906f7
-
rdobuilder 7906f7
-    return wrapper
rdobuilder 7906f7
+    return method