Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Fix StopIteration exception related issue #115

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Apr 26, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions rethinkdb/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -243,10 +243,16 @@ def __init__(self, *seq, **opts):

def __iter__(self):
itr = iter(self.seq)
for sub in next(itr):
yield sub

try:
for sub in next(itr):
yield sub
except StopIteration:
return

for token in itr:
for sub in self.intsp:
yield sub

for sub in token:
yield sub
46 changes: 46 additions & 0 deletions tests/integration/test_date_and_time.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import pytest
from copy import deepcopy
from tests.helpers import IntegrationTestCaseBase


@pytest.mark.integration
class TestDateAndTime(IntegrationTestCaseBase):
def setup_method(self):
super(TestDateAndTime, self).setup_method()
self.table_name = 'test_now'
self.r.table_create(self.table_name).run(self.conn)

self.expected_insert_response = {
'deleted': 0,
'errors': 0,
'inserted': 1,
'replaced': 0,
'skipped': 0,
'unchanged': 0,
}

@staticmethod
def compare_seconds(a, b):
"""
During the tests, the milliseconds are a little different, so we need to look at the results in seconds.
"""
def second_precision(dt):
return str(dt).split('.')[0]

assert second_precision(a) == second_precision(b)

def test_insert_with_now(self):
now = self.r.now()
insert_data = {
'id': 1,
'name': 'Captain America',
'real_name': 'Steven Rogers',
'universe': 'Earth-616',
'created_at': now
}

response = self.r.table(self.table_name).insert(insert_data).run(self.conn)
document = self.r.table(self.table_name).get(1).run(self.conn)

assert response == self.expected_insert_response
self.compare_seconds(document['created_at'], self.r.now().run(self.conn))
13 changes: 13 additions & 0 deletions tests/test_date_and_time.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import pytest
from mock import call, patch, ANY, Mock
from rethinkdb import r, ast


@pytest.mark.unit
class TestNow(object):
def setup_method(self):
pass

def test_get_now(self):
now = r.now()
assert type(now) == ast.Now