Skip to content

Commit

Permalink
Use an overlay object to make tests appear to use zipfile.Path to red…
Browse files Browse the repository at this point in the history
…uce diff with CPython.
  • Loading branch information
jaraco committed May 16, 2024
1 parent b754ab7 commit 9f0a0c8
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 67 deletions.
16 changes: 16 additions & 0 deletions tests/compat/overlay.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
"""
Expose zipp.Path as .zipfile.Path
"""

import importlib
import sys
import types

import zipp


zipfile = types.SimpleNamespace(**vars(importlib.import_module('zipfile')))
zipfile.Path = zipp.Path
zipfile._path = zipp

sys.modules[__name__ + '.zipfile'] = zipfile # type: ignore
9 changes: 4 additions & 5 deletions tests/test_complexity.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@
import re
import string
import unittest
import zipfile
from .compat.overlay import zipfile

import zipp
from jaraco.functools import compose
from more_itertools import consume

Expand All @@ -21,7 +20,7 @@ class TestComplexity(unittest.TestCase):
@pytest.mark.flaky
def test_implied_dirs_performance(self):
best, others = big_o.big_o(
compose(consume, zipp.CompleteDirs._implied_dirs),
compose(consume, zipfile._path.CompleteDirs._implied_dirs),
lambda size: [
'/'.join(string.ascii_lowercase + str(n)) for n in range(size)
],
Expand All @@ -30,7 +29,7 @@ def test_implied_dirs_performance(self):
)
assert best <= big_o.complexities.Linear

def make_zip_path(self, depth=1, width=1) -> zipp.Path:
def make_zip_path(self, depth=1, width=1):
"""
Construct a Path with width files at every level of depth.
"""
Expand All @@ -39,7 +38,7 @@ def make_zip_path(self, depth=1, width=1) -> zipp.Path:
for path, name in pairs:
zf.writestr(f"{path}{name}.txt", b'')
zf.filename = "big un.zip"
return zipp.Path(zf)
return zipfile.Path(zf)

@classmethod
def make_names(cls, width, letters=string.ascii_lowercase):
Expand Down
Loading

0 comments on commit 9f0a0c8

Please sign in to comment.