diff --git a/CHANGES.rst b/CHANGES.rst index fec3e60..345e70f 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -1,3 +1,9 @@ +v3.15.0 +======= + +* gh-102209: ``test_implied_dirs_performance`` now tests + measures the time complexity experimentally. + v3.14.0 ======= 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/_support.py b/tests/_support.py new file mode 100644 index 0000000..1afdf3b --- /dev/null +++ b/tests/_support.py @@ -0,0 +1,9 @@ +import importlib +import unittest + + +def import_or_skip(name): + try: + return importlib.import_module(name) + except ImportError: # pragma: no cover + raise unittest.SkipTest(f'Unable to import {name}') diff --git a/tests/test_complexity.py b/tests/test_complexity.py new file mode 100644 index 0000000..4021041 --- /dev/null +++ b/tests/test_complexity.py @@ -0,0 +1,24 @@ +import unittest +import string + +import zipp +from jaraco.functools import compose +from more_itertools import consume + +from ._support import import_or_skip + + +big_o = import_or_skip('big_o') + + +class TestComplexity(unittest.TestCase): + def test_implied_dirs_performance(self): + 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 <= big_o.complexities.Linear diff --git a/tests/test_zipp.py b/tests/test_zipp.py index 9761e11..adebfe2 100644 --- a/tests/test_zipp.py +++ b/tests/test_zipp.py @@ -5,19 +5,16 @@ import tempfile import shutil import pickle -import string import sys import unittest import zipfile import jaraco.itertools from jaraco.functools import compose -from more_itertools import consume import zipp from ._test_params import parameterize, Invoked -from ._func_timeout_compat import set_timeout def add_dirs(zf): @@ -334,11 +331,6 @@ 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)) - @pass_alpharep def test_read_does_not_close(self, alpharep): alpharep = self.zipfile_ondisk(alpharep)