Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
C
cpython
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
Batuhan Osman TASKAYA
cpython
Commits
ea2e97a0
Kaydet (Commit)
ea2e97a0
authored
Haz 24, 2001
tarafından
Tim Peters
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
New tests to provoke SyntaxErrors unique to generators. Minor fiddling
of other tests.
üst
08bba953
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
81 additions
and
2 deletions
+81
-2
test_generators.py
Lib/test/test_generators.py
+81
-2
No files found.
Lib/test/test_generators.py
Dosyayı görüntüle @
ea2e97a0
...
...
@@ -14,13 +14,16 @@ Let's try a simple generator:
1
>>> g.next()
2
"Falling off the end" stops the generator:
>>> g.next()
Traceback (most recent call last):
File "<stdin>", line 1, in ?
File "<stdin>", line 2, in g
StopIteration
"return" stops the generator:
"return"
also
stops the generator:
>>> def f():
... yield 1
...
...
@@ -443,11 +446,87 @@ arguments are iterable -- a LazyList is the same as a generator to times().
[400, 405, 432, 450, 480, 486, 500, 512, 540, 576, 600, 625, 640, 648, 675]
"""
# syntax_tests mostly provokes SyntaxErrors.
syntax_tests
=
"""
>>> def f():
... return 22
... yield 1
Traceback (most recent call last):
...
SyntaxError: 'return' with argument inside generator (<string>, line 2)
>>> def f():
... yield 1
... return 22
Traceback (most recent call last):
...
SyntaxError: 'return' with argument inside generator (<string>, line 3)
"return None" is not the same as "return" in a generator:
>>> def f():
... yield 1
... return None
Traceback (most recent call last):
...
SyntaxError: 'return' with argument inside generator (<string>, line 3)
This one is fine:
>>> def f():
... yield 1
... return
>>> def f():
... try:
... yield 1
... finally:
... pass
Traceback (most recent call last):
...
SyntaxError: 'yield' not allowed in a 'try' block with a 'finally' clause (<string>, line 3)
>>> def f():
... try:
... try:
... 1/0
... except ZeroDivisionError:
... yield 666 # bad because *outer* try has finally
... except:
... pass
... finally:
... pass
Traceback (most recent call last):
...
SyntaxError: 'yield' not allowed in a 'try' block with a 'finally' clause (<string>, line 6)
But this is fine:
>>> def f():
... try:
... try:
... yield 12
... 1/0
... except ZeroDivisionError:
... yield 666
... except:
... try:
... x = 12
... finally:
... yield 12
... except:
... return
>>> list(f())
[12, 666]
"""
__test__
=
{
"tut"
:
tutorial_tests
,
"pep"
:
pep_tests
,
"email"
:
email_tests
,
"fun"
:
fun_tests
}
"fun"
:
fun_tests
,
"syntax"
:
syntax_tests
}
# Magic test name that regrtest.py invokes *after* importing this module.
# This worms around a bootstrap problem.
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment