-
-
Notifications
You must be signed in to change notification settings - Fork 405
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
announce: make
_chunks()
helper safe against more input types
Especially `dict_keys` objects, which is how py3 handles `dict.keys()` (vs. being a subscriptable iterable in py2). Added a test, too, because let's not have this plugin bite us again. NOTE: Replaced the new test file's `__future__` imports with those appropriate for py2, and added the magic "coding" comment expected by our 7.x style checker rules. Backported from d915136.
- Loading branch information
Showing
2 changed files
with
42 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
# coding=utf-8 | ||
"""Tests for Sopel's ``announce`` plugin""" | ||
from __future__ import absolute_import, division, print_function, unicode_literals | ||
|
||
from sopel.modules import announce | ||
|
||
|
||
def test_chunks(): | ||
"""Test the `_chunks` helper for functionality and compatibility.""" | ||
# list input | ||
items = ['list', 'of', 'items', 'to', 'chunk'] | ||
r = list(announce._chunks(items, 2)) | ||
|
||
assert len(r) == 3 | ||
assert r[0] == tuple(items[:2]) | ||
assert r[1] == tuple(items[2:4]) | ||
assert r[2] == tuple(items[4:]) | ||
|
||
# tuple input | ||
items = ('tuple', 'of', 'items') | ||
r = list(announce._chunks(items, 3)) | ||
|
||
assert len(r) == 1 | ||
assert r[0] == items | ||
|
||
# dict keys input | ||
keys = {'one': True, 'two': True, 'three': True}.keys() | ||
items = list(keys) | ||
r = list(announce._chunks(keys, 1)) | ||
|
||
assert len(r) == 3 | ||
for idx in range(len(items)): | ||
assert r[idx] == (items[idx],) |