From ed7a657722610ee05d24a6b522e4ab3a18b71da2 Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Fri, 24 Feb 2023 20:21:32 -0500 Subject: [PATCH] Move complexity tests to their own module. --- tests/_support.py | 9 +++++++++ tests/test_complexity.py | 24 ++++++++++++++++++++++++ tests/test_zipp.py | 14 -------------- 3 files changed, 33 insertions(+), 14 deletions(-) create mode 100644 tests/_support.py create mode 100644 tests/test_complexity.py 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 1f4d20b..adebfe2 100644 --- a/tests/test_zipp.py +++ b/tests/test_zipp.py @@ -5,15 +5,12 @@ import tempfile import shutil import pickle -import string import sys import unittest import zipfile -import big_o import jaraco.itertools from jaraco.functools import compose -from more_itertools import consume import zipp @@ -334,17 +331,6 @@ def test_joinpath_constant_time(self): # Check the file iterated all items assert entries.count == self.HUGE_ZIPFILE_NUM_ENTRIES - 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 - @pass_alpharep def test_read_does_not_close(self, alpharep): alpharep = self.zipfile_ondisk(alpharep)