Skip to content

Commit 6ad406d

Browse files
committed
-
1 parent 1a17f08 commit 6ad406d

File tree

18 files changed

+317
-51
lines changed

18 files changed

+317
-51
lines changed

source_py2/python_toolbox/logic_tools.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ def all_equivalent(iterable, relation=operator.eq, assume_reflexive=True,
6363

6464

6565
misc_tools.limit_positional_arguments(3)
66-
def get_equivalence_classes(iterable, key=None, container=set,
66+
def get_equivalence_classes(iterable, key=None, container=set,
6767
use_ordered_dict=False, sort_ordered_dict=False):
6868
'''
6969
Divide items in `iterable` to equivalence classes, using the key function.

source_py2/test_python_toolbox/test_address_tools/test_describe.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ def test_bad_module_name():
246246
def test_function_in_something():
247247
'''Test `describe` doesn't fail when describing `{1: sum}`.'''
248248
if python_toolbox.__version_info__ <= (0, 7, 0, 'release'):
249-
raise nose.SkipTest("This test doesn't pass in `python_toolbox`"
249+
raise nose.SkipTest("This test doesn't pass in `python_toolbox` "
250250
"version 0.7.0 and below.")
251251
assert describe({1: sum}) == '{1: sum}'
252252
assert describe((sum, sum, list, chr)) == '(sum, sum, list, chr)'

source_py2/test_python_toolbox/test_address_tools/test_resolve.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from python_toolbox.address_tools import describe, resolve
99

1010

11-
# Class tree we'll try to some resolvings on:
11+
# Class tree we'll try to do some resolvings on:
1212
class A(object):
1313
def method(self):
1414
pass

source_py2/test_python_toolbox/test_combi/test_perm_space.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,11 @@ def test_perm_spaces():
7676
# Testing hashing:
7777
pure_perm_space_dict = {pure_0a: 'a', pure_0b: 'b',
7878
pure_0c: 'c', pure_0d: 'd',}
79+
(single_value,) = pure_perm_space_dict.values()
7980
assert len(pure_perm_space_dict) == 1 # They're all the same
8081
assert pure_perm_space_dict[pure_0a] == pure_perm_space_dict[pure_0b] == \
81-
pure_perm_space_dict[pure_0c] == pure_perm_space_dict[pure_0d] == 'd'
82+
pure_perm_space_dict[pure_0c] == pure_perm_space_dict[pure_0d] == \
83+
single_value
8284

8385
assert None not in pure_0a # Because, damn.
8486
assert PermSpace('meow')[0] not in pure_0a
@@ -106,7 +108,8 @@ def test_perm_spaces():
106108
assert not (first_perm != first_perm)
107109
assert first_perm == first_perm
108110
assert first_perm
109-
assert {pure_0a[4]: 1, pure_0b[4]: 2, pure_0c[4]: 3,} == {pure_0d[4]: 3,}
111+
assert tuple({pure_0a[4]: 1, pure_0b[4]: 2, pure_0c[4]: 3,}.keys()) == \
112+
(pure_0d[4], )
110113

111114

112115
assert some_perm.inverse == ~ some_perm

source_py2/test_python_toolbox/test_cute_iter_tools/test_iterate_overlapping_subsequences.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ def test_various_lengths():
4747
((0, 1, 2, 3), (1, 2, 3, 4), (2, 3, 4, 5), (3, 4, 5, 6))
4848
assert tuple(iterate_overlapping_subsequences(xrange(7), length=5)) == \
4949
((0, 1, 2, 3, 4), (1, 2, 3, 4, 5), (2, 3, 4, 5, 6))
50+
assert tuple(iterate_overlapping_subsequences(range(7), length=1)) == \
51+
tuple(range(7))
5052

5153
assert tuple(iterate_overlapping_subsequences(xrange(7), length=4,
5254
wrap_around=True)) == ((0, 1, 2, 3), (1, 2, 3, 4), (2, 3, 4, 5),
@@ -145,7 +147,10 @@ def assert_garbage_collected(indexes):
145147
assert_garbage_collected((0, 1, 2, 3, 4, 5, 6))
146148

147149

148-
150+
def test_short_iterables():
151+
assert tuple(iterate_overlapping_subsequences([1])) == ()
152+
assert tuple(iterate_overlapping_subsequences([1], length=7)) == ()
153+
149154

150155

151156

source_py2/test_python_toolbox/test_cute_profile/shared.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ def call_and_check_if_profiled(f):
2222

2323
segments_found = [(segment in output) for segment in segments]
2424

25-
if not logic_tools.all_equal(segments_found):
25+
if not logic_tools.all_equivalent(segments_found):
2626
raise Exception("Some segments were found, but some weren't; can't "
2727
"know if this was a profiled call or not. Possibly "
2828
"some of our segments are wrong.")
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# Copyright 2009-2015 Ram Rachum.
2+
# This program is distributed under the MIT license.
3+
4+
from python_toolbox import cute_testing
5+
6+
from python_toolbox import dict_tools
7+
8+
9+
def test():
10+
assert dict_tools.reverse({'one': 1, 'two': 2, 'three': 3}) == \
11+
{1: 'one', 2: 'two', 3: 'three'}
12+
assert dict_tools.reverse({}) == {}
13+
with cute_testing.RaiseAssertor():
14+
dict_tools.reverse({1: 0, 2: 0})
15+
with cute_testing.RaiseAssertor():
16+
dict_tools.reverse({1: []})

source_py2/test_python_toolbox/test_emitting/test_emitter.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,8 @@
44

55

66
def test():
7-
''' '''
87
emitter_1 = emitting.Emitter()
9-
emitter_2 = emitting.Emitter(inputs=(emitter_1,))
8+
emitter_2 = emitting.Emitter(inputs=emitter_1) # Single item without tuple
109
emitter_0 = emitting.Emitter(outputs=(emitter_1,))
1110

1211
@misc_tools.set_attributes(call_counter=0)

source_py2/test_python_toolbox/test_future_tools/__init__.py

Whitespace-only changes.
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# Copyright 2009-2015 Ram Rachum.
2+
# This program is distributed under the MIT license.
3+
4+
import concurrent.futures
5+
import time
6+
7+
from python_toolbox import future_tools
8+
9+
10+
def test():
11+
12+
def sleep_and_return(seconds):
13+
time.sleep(seconds)
14+
return seconds
15+
16+
17+
with future_tools.CuteThreadPoolExecutor(10) as executor:
18+
assert isinstance(executor, future_tools.CuteThreadPoolExecutor)
19+
assert tuple(executor.filter(lambda x: (x % 2 == 0), range(10))) == \
20+
tuple(range(0, 10, 2))
21+
assert sorted(executor.filter(lambda x: (x % 2 == 0), range(10),
22+
timeout=10**5, as_completed=True)) == \
23+
list(range(0, 10, 2))
24+
assert tuple(executor.filter(
25+
lambda x: (sleep_and_return(x) % 2 == 0), range(9, -1, -1),
26+
as_completed=True)) == tuple(range(0, 10, 2))
27+
28+
29+
assert tuple(executor.map(lambda x: x % 3, range(10))) == \
30+
(0, 1, 2, 0, 1, 2, 0, 1, 2, 0)
31+
assert sorted(executor.map(lambda x: x % 3, range(10),
32+
timeout=10**5, as_completed=True)) == \
33+
[0, 0, 0, 0, 1, 1, 1, 2, 2, 2]
34+
35+
assert tuple(executor.map(sleep_and_return, range(9, -1, -1),
36+
as_completed=True)) == tuple(range(10))
37+
38+
39+
40+

0 commit comments

Comments
 (0)