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
519a342d
Kaydet (Commit)
519a342d
authored
Eyl 11, 2002
tarafından
Michael W. Hudson
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Bunch more tests.
üst
fbcde75c
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
83 additions
and
9 deletions
+83
-9
test_trace.py
Lib/test/test_trace.py
+83
-9
No files found.
Lib/test/test_trace.py
Dosyayı görüntüle @
519a342d
...
...
@@ -69,6 +69,62 @@ no_pop_blocks.events = [(0, 'call'),
(
3
,
'line'
),
(
3
,
'return'
)]
def
called
():
# line -3
x
=
1
def
call
():
# line 0
called
()
call
.
events
=
[(
0
,
'call'
),
(
1
,
'line'
),
(
-
3
,
'call'
),
(
-
2
,
'line'
),
(
-
2
,
'return'
),
(
1
,
'return'
)]
def
raises
():
raise
Exception
def
test_raise
():
try
:
raises
()
except
Exception
,
exc
:
x
=
1
test_raise
.
events
=
[(
0
,
'call'
),
(
1
,
'line'
),
(
2
,
'line'
),
(
-
3
,
'call'
),
(
-
2
,
'line'
),
(
-
2
,
'exception'
),
(
2
,
'exception'
),
(
3
,
'line'
),
(
4
,
'line'
),
(
4
,
'return'
)]
def
_settrace_and_return
(
tracefunc
):
sys
.
settrace
(
tracefunc
)
sys
.
_getframe
()
.
f_back
.
f_trace
=
tracefunc
def
settrace_and_return
(
tracefunc
):
_settrace_and_return
(
tracefunc
)
settrace_and_return
.
events
=
[(
1
,
'return'
)]
def
_settrace_and_raise
(
tracefunc
):
sys
.
settrace
(
tracefunc
)
sys
.
_getframe
()
.
f_back
.
f_trace
=
tracefunc
raise
RuntimeError
def
settrace_and_raise
(
tracefunc
):
try
:
_settrace_and_raise
(
tracefunc
)
except
RuntimeError
,
exc
:
pass
settrace_and_raise
.
events
=
[(
2
,
'exception'
),
(
3
,
'line'
),
(
4
,
'line'
),
(
4
,
'return'
)]
class
Tracer
:
def
__init__
(
self
):
self
.
events
=
[]
...
...
@@ -77,18 +133,29 @@ class Tracer:
return
self
.
trace
class
TraceTestCase
(
unittest
.
TestCase
):
def
compare_events
(
self
,
line_offset
,
events
,
expected_events
):
events
=
[(
l
-
line_offset
,
e
)
for
(
l
,
e
)
in
events
]
if
events
!=
expected_events
:
self
.
fail
(
"events did not match expectation:
\n
"
+
"
\n
"
.
join
(
difflib
.
ndiff
(
map
(
str
,
expected_events
),
map
(
str
,
events
))))
def
run_test
(
self
,
func
):
tracer
=
Tracer
()
sys
.
settrace
(
tracer
.
trace
)
func
()
sys
.
settrace
(
None
)
fl
=
func
.
func_code
.
co_firstlineno
events
=
[(
l
-
fl
,
e
)
for
(
l
,
e
)
in
tracer
.
events
]
if
events
!=
func
.
events
:
self
.
fail
(
"events did not match expectation:
\n
"
+
"
\n
"
.
join
(
difflib
.
ndiff
(
map
(
str
,
func
.
events
),
map
(
str
,
events
))))
self
.
compare_events
(
func
.
func_code
.
co_firstlineno
,
tracer
.
events
,
func
.
events
)
def
run_test2
(
self
,
func
):
tracer
=
Tracer
()
func
(
tracer
.
trace
)
sys
.
settrace
(
None
)
self
.
compare_events
(
func
.
func_code
.
co_firstlineno
,
tracer
.
events
,
func
.
events
)
def
test_1_basic
(
self
):
self
.
run_test
(
basic
)
...
...
@@ -100,8 +167,15 @@ class TraceTestCase(unittest.TestCase):
self
.
run_test
(
no_pop_blocks
)
def
test_5_no_pop_tops
(
self
):
self
.
run_test
(
no_pop_tops
)
def
test_6_call
(
self
):
self
.
run_test
(
call
)
def
test_7_raise
(
self
):
self
.
run_test
(
test_raise
)
def
test_8_settrace_and_return
(
self
):
self
.
run_test2
(
settrace_and_return
)
def
test_9_settrace_and_raise
(
self
):
self
.
run_test2
(
settrace_and_raise
)
def
test_main
():
test_support
.
run_unittest
(
TraceTestCase
)
...
...
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