-
-
Notifications
You must be signed in to change notification settings - Fork 404
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2166 from sopel-irc/announce-py3-dict.keys
announce: make `_chunks()` helper safe against more input types Cherry-picked from master: b38a5d6
- Loading branch information
Showing
2 changed files
with
45 additions
and
3 deletions.
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,32 @@ | ||
"""Tests for Sopel's ``announce`` plugin""" | ||
from __future__ import generator_stop | ||
|
||
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],) |