From 8c0a745c85f98365f81c4d006648f2c0c49c31ac Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Fri, 24 Feb 2023 18:47:46 -0500 Subject: [PATCH] Measure the complexity directly using the big-O library. Fixes python/cpython#102209. --- setup.cfg | 2 +- tests/_context.py | 30 ------------------------------ tests/_func_timeout_compat.py | 8 -------- tests/test_zipp.py | 14 ++++++++++---- 4 files changed, 11 insertions(+), 43 deletions(-) delete mode 100644 tests/_context.py delete mode 100644 tests/_func_timeout_compat.py diff --git a/setup.cfg b/setup.cfg index 313f466..f7832d2 100644 --- a/setup.cfg +++ b/setup.cfg @@ -46,9 +46,9 @@ testing = # local jaraco.itertools - func-timeout jaraco.functools more_itertools + big-O docs = # upstream diff --git a/tests/_context.py b/tests/_context.py deleted file mode 100644 index 348798a..0000000 --- a/tests/_context.py +++ /dev/null @@ -1,30 +0,0 @@ -import contextlib -import time - - -class DeadlineExceeded(Exception): - pass - - -class TimedContext(contextlib.ContextDecorator): - """ - A context that will raise DeadlineExceeded if the - max duration is reached during the execution. - - >>> TimedContext(1)(time.sleep)(.1) - >>> TimedContext(0)(time.sleep)(.1) - Traceback (most recent call last): - ... - tests._context.DeadlineExceeded: (..., 0) - """ - - def __init__(self, max_duration: int): - self.max_duration = max_duration - - def __enter__(self): - self.start = time.monotonic() - - def __exit__(self, *err): - duration = time.monotonic() - self.start - if duration > self.max_duration: - raise DeadlineExceeded(duration, self.max_duration) diff --git a/tests/_func_timeout_compat.py b/tests/_func_timeout_compat.py deleted file mode 100644 index b1f2b26..0000000 --- a/tests/_func_timeout_compat.py +++ /dev/null @@ -1,8 +0,0 @@ -try: - from func_timeout import func_set_timeout as set_timeout -except ImportError: # pragma: no cover - # provide a fallback that doesn't actually time out - from ._context import TimedContext as set_timeout - - -__all__ = ['set_timeout'] diff --git a/tests/test_zipp.py b/tests/test_zipp.py index 9761e11..597f979 100644 --- a/tests/test_zipp.py +++ b/tests/test_zipp.py @@ -10,6 +10,7 @@ import unittest import zipfile +import big_o import jaraco.itertools from jaraco.functools import compose from more_itertools import consume @@ -17,7 +18,6 @@ import zipp from ._test_params import parameterize, Invoked -from ._func_timeout_compat import set_timeout def add_dirs(zf): @@ -334,10 +334,16 @@ def test_joinpath_constant_time(self): # Check the file iterated all items assert entries.count == self.HUGE_ZIPFILE_NUM_ENTRIES - @set_timeout(3) def test_implied_dirs_performance(self): - data = ['/'.join(string.ascii_lowercase + str(n)) for n in range(10000)] - consume(zipp.CompleteDirs._implied_dirs(data)) + best, others = big_o.big_o( + compose(consume, zipp.CompleteDirs._implied_dirs), + lambda size: [ + '/'.join(string.ascii_lowercase + str(n)) for n in range(size) + ], + max_n=1000, + min_n=1, + ) + assert best.__class__ is big_o.complexities.Linear @pass_alpharep def test_read_does_not_close(self, alpharep):