fix generator tests (multiple yields must be called with an if random.

This commit is contained in:
Dave Halter
2014-08-06 12:45:38 +02:00
parent 23c39eff9a
commit e7e7bd29e8
2 changed files with 23 additions and 13 deletions

View File

@@ -7,10 +7,12 @@ possible for the auto completion.
def next(iterator, default=None):
if random.choice([0, 1]):
if hasattr("next"):
return iterator.next()
else:
return iterator.__next__()
else:
return default

View File

@@ -2,7 +2,9 @@
# yield statement
# -----------------
def gen():
if random.choice([0, 1]):
yield 1
else:
yield ""
gen_exe = gen()
@@ -27,7 +29,9 @@ next(gen_ret())
# generators should not be indexable
# -----------------
def get(param):
if random.choice([0, 1]):
yield 1
else:
yield ""
#? []
@@ -43,7 +47,9 @@ for a in get():
class Get():
def __iter__(self):
if random.choice([0, 1]):
yield 1
else:
yield ""
b = []
@@ -98,7 +104,7 @@ for c in Counter(3, 8):
# tuples
# -----------------
def gen():
if a:
if random.choice([0,1]):
yield 1, ""
else:
yield 2, 1.0
@@ -112,8 +118,10 @@ b
def simple():
if random.choice([0, 1]):
yield 1
yield ''
else:
yield ""
a, b = simple()
#? int()