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
905c31c7
Kaydet (Commit)
905c31c7
authored
Ara 20, 2007
tarafından
Brett Cannon
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Add tests for the warnings module; specifically formatwarning and showwarning.
Still need tests for warn_explicit and simplefilter.
üst
dff1fd93
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
32 additions
and
1 deletion
+32
-1
test_warnings.py
Lib/test/test_warnings.py
+32
-1
No files found.
Lib/test/test_warnings.py
Dosyayı görüntüle @
905c31c7
import
warnings
import
warnings
import
linecache
import
os
import
os
import
StringIO
import
sys
import
sys
import
unittest
import
unittest
from
test
import
test_support
from
test
import
test_support
...
@@ -36,6 +38,8 @@ class TestModule(unittest.TestCase):
...
@@ -36,6 +38,8 @@ class TestModule(unittest.TestCase):
self
.
assert_
(
w
.
category
is
category
)
self
.
assert_
(
w
.
category
is
category
)
def
test_filtering
(
self
):
def
test_filtering
(
self
):
# Test filterwarnings().
# Implicitly also tests resetwarnings().
with
test_support
.
catch_warning
()
as
w
:
with
test_support
.
catch_warning
()
as
w
:
warnings
.
filterwarnings
(
"error"
,
""
,
Warning
,
""
,
0
)
warnings
.
filterwarnings
(
"error"
,
""
,
Warning
,
""
,
0
)
self
.
assertRaises
(
UserWarning
,
warnings
.
warn
,
'convert to error'
)
self
.
assertRaises
(
UserWarning
,
warnings
.
warn
,
'convert to error'
)
...
@@ -97,6 +101,33 @@ class TestModule(unittest.TestCase):
...
@@ -97,6 +101,33 @@ class TestModule(unittest.TestCase):
self
.
assertEqual
(
os
.
path
.
basename
(
w
.
filename
),
"sys"
)
self
.
assertEqual
(
os
.
path
.
basename
(
w
.
filename
),
"sys"
)
class
WarningsDisplayTests
(
unittest
.
TestCase
):
def
test_formatwarning
(
self
):
message
=
"msg"
category
=
Warning
file_name
=
os
.
path
.
splitext
(
warning_tests
.
__file__
)[
0
]
+
'.py'
line_num
=
3
file_line
=
linecache
.
getline
(
file_name
,
line_num
)
.
strip
()
expect
=
"
%
s:
%
s:
%
s:
%
s
\n
%
s
\n
"
%
(
file_name
,
line_num
,
category
.
__name__
,
message
,
file_line
)
self
.
failUnlessEqual
(
warnings
.
formatwarning
(
message
,
category
,
file_name
,
line_num
),
expect
)
def
test_showwarning
(
self
):
file_name
=
os
.
path
.
splitext
(
warning_tests
.
__file__
)[
0
]
+
'.py'
line_num
=
3
expected_file_line
=
linecache
.
getline
(
file_name
,
line_num
)
.
strip
()
message
=
'msg'
category
=
Warning
file_object
=
StringIO
.
StringIO
()
expect
=
warnings
.
formatwarning
(
message
,
category
,
file_name
,
line_num
)
warnings
.
showwarning
(
message
,
category
,
file_name
,
line_num
,
file_object
)
self
.
failUnlessEqual
(
file_object
.
getvalue
(),
expect
)
def
test_main
(
verbose
=
None
):
def
test_main
(
verbose
=
None
):
# Obscure hack so that this test passes after reloads or repeated calls
# Obscure hack so that this test passes after reloads or repeated calls
# to test_main (regrtest -R).
# to test_main (regrtest -R).
...
@@ -106,7 +137,7 @@ def test_main(verbose=None):
...
@@ -106,7 +137,7 @@ def test_main(verbose=None):
del
warning_tests
.
__warningregistry__
del
warning_tests
.
__warningregistry__
if
hasattr
(
sys
,
'__warningregistry__'
):
if
hasattr
(
sys
,
'__warningregistry__'
):
del
sys
.
__warningregistry__
del
sys
.
__warningregistry__
test_support
.
run_unittest
(
TestModule
)
test_support
.
run_unittest
(
TestModule
,
WarningsDisplayTests
)
if
__name__
==
"__main__"
:
if
__name__
==
"__main__"
:
test_main
(
verbose
=
True
)
test_main
(
verbose
=
True
)
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