Skip to content

Commit 7b90fd1

Browse files
committed
-
1 parent 0d5b637 commit 7b90fd1

File tree

17 files changed

+139
-26
lines changed

17 files changed

+139
-26
lines changed

source_py2/python_toolbox/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,6 @@
1717
import python_toolbox.monkeypatch_envelopes
1818
import python_toolbox.monkeypatch_pathlib
1919

20-
__version_info__ = python_toolbox.version_info.VersionInfo(0, 6, 9)
20+
__version_info__ = python_toolbox.version_info.VersionInfo(0, 6, 10)
2121
__version__ = __version_info__.version_text
2222

source_py2/python_toolbox/misc_tools/misc_tools.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,7 @@ def repeat_getattr(thing, query):
304304
current = getattr(current, attribute_name)
305305
return current
306306

307+
307308
def set_attributes(**kwargs):
308309
'''
309310
Decorator to set attributes on a function.

source_py2/test_python_toolbox/test_address_tools/test_describe.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@ def test_on_locally_defined_class():
2727
# Testing for locally defined class:
2828

2929

30-
if python_toolbox.__version_info__ <= (0, 6, 9, 'release'):
30+
if python_toolbox.__version_info__ <= (0, 6, 10, 'release'):
3131
raise nose.SkipTest("This test doesn't pass in `python_toolbox` "
32-
"version 0.6.9 and below, because `describe` :"
32+
"version 0.6.10 and below, because `describe` :"
3333
"doesn't support nested classes yet.")
3434

3535
result = describe(A.B)
@@ -247,9 +247,9 @@ def test_bad_module_name():
247247

248248
def test_function_in_something():
249249
'''Test `describe` doesn't fail when describing `{1: sum}`.'''
250-
if python_toolbox.__version_info__ <= (0, 6, 9, 'release'):
250+
if python_toolbox.__version_info__ <= (0, 6, 10, 'release'):
251251
raise nose.SkipTest("This test doesn't pass in `python_toolbox`"
252-
"version 0.6.9 and below.")
252+
"version 0.6.10 and below.")
253253
assert describe({1: sum}) == '{1: sum}'
254254
assert describe((sum, sum, list, chr)) == '(sum, sum, list, chr)'
255255

source_py2/test_python_toolbox/test_caching/test_cache.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,19 +12,19 @@
1212

1313
from python_toolbox import caching
1414
from python_toolbox.caching import cache
15+
from python_toolbox import misc_tools
1516
from python_toolbox import temp_value_setting
1617
from python_toolbox import cute_testing
1718
from python_toolbox import gc_tools
1819

1920

21+
@misc_tools.set_attributes(i=0)
2022
def counting_func(a=1, b=2, *args, **kwargs):
2123
'''Function that returns a bigger number every time.'''
22-
if not hasattr(counting_func, 'i'):
23-
counting_func.i = 0
2424
try:
2525
return counting_func.i
2626
finally:
27-
counting_func.i = (counting_func.i + 1)
27+
counting_func.i += 1
2828

2929

3030
def test_basic():

source_py2/test_python_toolbox/test_caching/test_cached_property.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,18 @@
66
import nose
77

88
from python_toolbox import context_management
9+
from python_toolbox import misc_tools
910

1011
from python_toolbox.caching import cache, CachedType, CachedProperty
1112

1213

14+
@misc_tools.set_attributes(i=0)
1315
def counting_func(self):
1416
'''Return a bigger number every time.'''
15-
if not hasattr(counting_func, 'i'):
16-
counting_func.i = 0
1717
try:
1818
return counting_func.i
1919
finally:
20-
counting_func.i = (counting_func.i + 1)
20+
counting_func.i += 1
2121

2222

2323
def test():

source_py2/test_python_toolbox/test_context_management/test_external.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ def woohoo():
8585
self.assertEqual(state, [1, 42, 999])
8686

8787
def _create_contextmanager_attribs(self):
88-
if python_toolbox.__version_info__ <= (0, 6, 9, 'release'):
88+
if python_toolbox.__version_info__ <= (0, 6, 10, 'release'):
8989
raise nose.SkipTest
9090
def attribs(**kw):
9191
def decorate(func):
@@ -107,7 +107,7 @@ def test_contextmanager_attribs(self):
107107
@unittest2.skipIf(hasattr(sys, 'flags') and sys.flags.optimize >= 2,
108108
"Docstrings are omitted with -O2 and above")
109109
def test_contextmanager_doc_attrib(self):
110-
if python_toolbox.__version_info__ <= (0, 6, 9, 'release'):
110+
if python_toolbox.__version_info__ <= (0, 6, 10, 'release'):
111111
raise nose.SkipTest('Not sure what to do about this.')
112112
baz = self._create_contextmanager_attribs()
113113
self.assertEqual(baz.__doc__, "Whee!")
@@ -212,7 +212,7 @@ def method(self, a, b, c=None):
212212

213213

214214
def test_typo_enter(self):
215-
if python_toolbox.__version_info__ <= (0, 6, 9, 'release'):
215+
if python_toolbox.__version_info__ <= (0, 6, 10, 'release'):
216216
raise nose.SkipTest
217217
class MyContextManager(ContextManager):
218218
def __unter__(self):
@@ -226,7 +226,7 @@ def __exit__(self, *exc):
226226

227227

228228
def test_typo_exit(self):
229-
if python_toolbox.__version_info__ <= (0, 6, 9, 'release'):
229+
if python_toolbox.__version_info__ <= (0, 6, 10, 'release'):
230230
raise nose.SkipTest
231231
class MyContextManager(ContextManager):
232232
def __enter__(self):
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Copyright 2009-2014 Ram Rachum.
2+
# This program is distributed under the MIT license.
3+
4+
import collections
5+
6+
from python_toolbox.cute_iter_tools import call_until_exception
7+
8+
9+
def test():
10+
11+
assert list(call_until_exception(collections.deque(range(7)).popleft,
12+
IndexError)) == list(range(7))
13+

source_py2/test_python_toolbox/test_cute_iter_tools/test_double_filter.py

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
# Copyright 2009-2014 Ram Rachum.
22
# This program is distributed under the MIT license.
33

4+
from python_toolbox import nifty_collections
5+
46
from python_toolbox.cute_iter_tools import double_filter
57

68

@@ -12,7 +14,20 @@ def test_double_filter():
1214
assert tuple(second_iterable) == tuple(xrange(1, 20, 2))
1315

1416
(first_iterable, second_iterable) = \
15-
double_filter(lambda value: value % 3 == 0, xrange(20))
16-
assert tuple(first_iterable) == tuple(xrange(0, 20, 3))
17-
assert tuple(second_iterable) == tuple(i for i in xrange(20) if i % 3 != 0)
17+
double_filter(lambda value: value % 3 == 0, range(20))
18+
assert tuple(first_iterable) == tuple(range(0, 20, 3))
19+
assert tuple(second_iterable) == tuple(i for i in range(20) if i % 3 != 0)
20+
21+
(first_lazy_tuple, second_lazy_tuple) = \
22+
double_filter(lambda value: value % 3 == 0, range(20), lazy_tuple=True)
23+
24+
assert isinstance(first_lazy_tuple, nifty_collections.LazyTuple)
25+
assert isinstance(second_lazy_tuple, nifty_collections.LazyTuple)
26+
assert first_lazy_tuple.collected_data == \
27+
second_lazy_tuple.collected_data == []
28+
29+
assert first_lazy_tuple == nifty_collections.LazyTuple(range(0, 20, 3))
30+
assert second_lazy_tuple == nifty_collections.LazyTuple(
31+
i for i in range(20) if i % 3 != 0
32+
)
1833

source_py2/test_python_toolbox/test_cute_iter_tools/test_enumerate.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33

44
'''Testing module for `cute_iter_tools.enumerate`.'''
55

6+
7+
from python_toolbox import nifty_collections
68
from python_toolbox import cute_iter_tools
79

810

@@ -18,4 +20,13 @@ def test():
1820
for i, j in cute_iter_tools.enumerate(range(5, 0 -1), reverse_index=True):
1921
assert i == j
2022

23+
lazy_tuple = cute_iter_tools.enumerate(range(5, 0 -1), reverse_index=True,
24+
lazy_tuple=True)
2125

26+
assert isinstance(lazy_tuple, nifty_collections.LazyTuple)
27+
assert not lazy_tuple.collected_data
28+
29+
for i, j in lazy_tuple:
30+
assert i == j
31+
32+
assert lazy_tuple.exhausted

source_py2/test_python_toolbox/test_cute_iter_tools/test_fill.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
import itertools
55
import types
66

7+
from python_toolbox import nifty_collections
8+
79
from python_toolbox.cute_iter_tools import fill
810

911

@@ -17,4 +19,10 @@ def test():
1719
assert fill(range(4), fill_value_maker=iter(range(10)).next, length=7,
1820
sequence_type=tuple) == (0, 1, 2, 3, 0, 1, 2)
1921

22+
lazy_tuple = fill(range(4), fill_value='Meow', length=7, lazy_tuple=True)
23+
24+
assert isinstance(lazy_tuple, nifty_collections.LazyTuple)
25+
assert not lazy_tuple.collected_data
26+
27+
assert lazy_tuple == (0, 1, 2, 3, 'Meow', 'Meow', 'Meow')
2028

0 commit comments

Comments
 (0)