Skip to content

Commit efd62ee

Browse files
gabor-borosasakatida
authored andcommitted
Fix StopIteration exception related issue (#115)
* Fix issue #110 * Add unit and integration tests for r.now() * Fix indentation
1 parent 0143634 commit efd62ee

File tree

3 files changed

+67
-2
lines changed

3 files changed

+67
-2
lines changed

rethinkdb/errors.py

+8-2
Original file line numberDiff line numberDiff line change
@@ -243,10 +243,16 @@ def __init__(self, *seq, **opts):
243243

244244
def __iter__(self):
245245
itr = iter(self.seq)
246-
for sub in next(itr):
247-
yield sub
246+
247+
try:
248+
for sub in next(itr):
249+
yield sub
250+
except StopIteration:
251+
return
252+
248253
for token in itr:
249254
for sub in self.intsp:
250255
yield sub
256+
251257
for sub in token:
252258
yield sub
+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import pytest
2+
from copy import deepcopy
3+
from tests.helpers import IntegrationTestCaseBase
4+
5+
6+
@pytest.mark.integration
7+
class TestDateAndTime(IntegrationTestCaseBase):
8+
def setup_method(self):
9+
super(TestDateAndTime, self).setup_method()
10+
self.table_name = 'test_now'
11+
self.r.table_create(self.table_name).run(self.conn)
12+
13+
self.expected_insert_response = {
14+
'deleted': 0,
15+
'errors': 0,
16+
'inserted': 1,
17+
'replaced': 0,
18+
'skipped': 0,
19+
'unchanged': 0,
20+
}
21+
22+
@staticmethod
23+
def compare_seconds(a, b):
24+
"""
25+
During the tests, the milliseconds are a little different, so we need to look at the results in seconds.
26+
"""
27+
def second_precision(dt):
28+
return str(dt).split('.')[0]
29+
30+
assert second_precision(a) == second_precision(b)
31+
32+
def test_insert_with_now(self):
33+
now = self.r.now()
34+
insert_data = {
35+
'id': 1,
36+
'name': 'Captain America',
37+
'real_name': 'Steven Rogers',
38+
'universe': 'Earth-616',
39+
'created_at': now
40+
}
41+
42+
response = self.r.table(self.table_name).insert(insert_data).run(self.conn)
43+
document = self.r.table(self.table_name).get(1).run(self.conn)
44+
45+
assert response == self.expected_insert_response
46+
self.compare_seconds(document['created_at'], self.r.now().run(self.conn))

tests/test_date_and_time.py

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import pytest
2+
from mock import call, patch, ANY, Mock
3+
from rethinkdb import r, ast
4+
5+
6+
@pytest.mark.unit
7+
class TestNow(object):
8+
def setup_method(self):
9+
pass
10+
11+
def test_get_now(self):
12+
now = r.now()
13+
assert type(now) == ast.Now

0 commit comments

Comments
 (0)