Skip to content

Commit f6227ad

Browse files
committed
Moved some tests utilities from 'test_zipfile/...' to the general 'support' folder
1 parent bde8284 commit f6227ad

File tree

5 files changed

+53
-56
lines changed

5 files changed

+53
-56
lines changed

Lib/test/support/itertools.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# from more_itertools v8.13.0
2+
def always_iterable(obj, base_type=(str, bytes)):
3+
if obj is None:
4+
return iter(())
5+
6+
if (base_type is not None) and isinstance(obj, base_type):
7+
return iter((obj,))
8+
9+
try:
10+
return iter(obj)
11+
except TypeError:
12+
return iter((obj,))
Lines changed: 39 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,39 @@
1-
import types
2-
import functools
3-
4-
from ._itertools import always_iterable
5-
6-
7-
def parameterize(names, value_groups):
8-
"""
9-
Decorate a test method to run it as a set of subtests.
10-
11-
Modeled after pytest.parametrize.
12-
"""
13-
14-
def decorator(func):
15-
@functools.wraps(func)
16-
def wrapped(self):
17-
for values in value_groups:
18-
resolved = map(Invoked.eval, always_iterable(values))
19-
params = dict(zip(always_iterable(names), resolved))
20-
with self.subTest(**params):
21-
func(self, **params)
22-
23-
return wrapped
24-
25-
return decorator
26-
27-
28-
class Invoked(types.SimpleNamespace):
29-
"""
30-
Wrap a function to be invoked for each usage.
31-
"""
32-
33-
@classmethod
34-
def wrap(cls, func):
35-
return cls(func=func)
36-
37-
@classmethod
38-
def eval(cls, cand):
39-
return cand.func() if isinstance(cand, cls) else cand
1+
import types
2+
import functools
3+
4+
from .itertools import always_iterable
5+
6+
7+
def parameterize(names, value_groups):
8+
"""
9+
Decorate a test method to run it as a set of subtests.
10+
11+
Modeled after pytest.parametrize.
12+
"""
13+
14+
def decorator(func):
15+
@functools.wraps(func)
16+
def wrapped(self):
17+
for values in value_groups:
18+
resolved = map(Invoked.eval, always_iterable(values))
19+
params = dict(zip(always_iterable(names), resolved))
20+
with self.subTest(**params):
21+
func(self, **params)
22+
23+
return wrapped
24+
25+
return decorator
26+
27+
28+
class Invoked(types.SimpleNamespace):
29+
"""
30+
Wrap a function to be invoked for each usage.
31+
"""
32+
33+
@classmethod
34+
def wrap(cls, func):
35+
return cls(func=func)
36+
37+
@classmethod
38+
def eval(cls, cand):
39+
return cand.func() if isinstance(cand, cls) else cand

Lib/test/test_strptime.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,11 @@
88
import sys
99
from test import support
1010
from test.support import skip_if_buggy_ucrt_strfptime, warnings_helper
11+
from test.support.parameterize import parameterize
1112
from datetime import date as datetime_date
1213

1314
import _strptime
1415

15-
from Lib.test.test_zipfile._path._test_params import parameterize
16-
1716

1817
class getlang_Tests(unittest.TestCase):
1918
"""Test _getlang"""

Lib/test/test_zipfile/_path/_itertools.py

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -29,20 +29,6 @@ def __next__(self):
2929
return result
3030

3131

32-
# from more_itertools v8.13.0
33-
def always_iterable(obj, base_type=(str, bytes)):
34-
if obj is None:
35-
return iter(())
36-
37-
if (base_type is not None) and isinstance(obj, base_type):
38-
return iter((obj,))
39-
40-
try:
41-
return iter(obj)
42-
except TypeError:
43-
return iter((obj,))
44-
45-
4632
# from more_itertools v9.0.0
4733
def consume(iterator, n=None):
4834
"""Advance *iterable* by *n* steps. If *n* is ``None``, consume it

Lib/test/test_zipfile/_path/test_path.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@
1010
import zipfile._path
1111

1212
from test.support.os_helper import temp_dir, FakePath
13+
from test.support.parameterize import parameterize, Invoked
1314

1415
from ._functools import compose
1516
from ._itertools import Counter
1617

17-
from ._test_params import parameterize, Invoked
1818

1919

2020
class jaraco:

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy