Skip to content

Commit

Permalink
Merge pull request #28 from sgaynetdinov/fix_raise_stop_iteration
Browse files Browse the repository at this point in the history
Fix raise error StopIteration
  • Loading branch information
sgaynetdinov authored Jan 5, 2020
2 parents 39a0382 + a5e7a96 commit 555c6f2
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
12 changes: 12 additions & 0 deletions tests/test_fetch.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import io

import pytest

import vk
from vk.fetch import Session
from vk.users import User


def test_url_open(mocker):
Expand Down Expand Up @@ -29,3 +32,12 @@ def test_upload_photo():
assert b'Content-Type: application/octet-stream' in data
assert b'Python developer and blogger.' in data
assert boundary.encode() in data

def test_fetch_items_stop_iteration(mocker):
fetch = mocker.patch('vk.fetch.Session.fetch')
fetch.return_value = {'items': []}

got = Session().fetch_items('test', User.from_json, 10)

with pytest.raises(StopIteration):
next(got)
2 changes: 1 addition & 1 deletion vk/fetch.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def fetch_items(self, method_name, constructor_from_json, count, **params):
items = res['items']

if not items:
raise StopIteration
return None

for i in items:
yield constructor_from_json(self, i)
Expand Down

0 comments on commit 555c6f2

Please sign in to comment.