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
667bb4f2
Kaydet (Commit)
667bb4f2
authored
Nis 13, 2008
tarafından
Brett Cannon
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Fix test_warnings by making the state of things more consistent for each test
when it is run.
üst
037d8293
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
42 additions
and
29 deletions
+42
-29
test_warnings.py
Lib/test/test_warnings.py
+42
-29
No files found.
Lib/test/test_warnings.py
Dosyayı görüntüle @
667bb4f2
...
@@ -8,9 +8,10 @@ from test import test_support
...
@@ -8,9 +8,10 @@ from test import test_support
import
warning_tests
import
warning_tests
import
warnings
as
original_warnings
sys
.
modules
[
'_warnings'
]
=
0
sys
.
modules
[
'_warnings'
]
=
0
if
'warnings'
in
sys
.
modules
:
del
sys
.
modules
[
'warnings'
]
del
sys
.
modules
[
'warnings'
]
import
warnings
as
py_warnings
import
warnings
as
py_warnings
...
@@ -19,6 +20,9 @@ del sys.modules['warnings']
...
@@ -19,6 +20,9 @@ del sys.modules['warnings']
import
warnings
as
c_warnings
import
warnings
as
c_warnings
sys
.
modules
[
'warnings'
]
=
original_warnings
@contextmanager
@contextmanager
def
warnings_state
(
module
):
def
warnings_state
(
module
):
"""Use a specific warnings implementation in warning_tests."""
"""Use a specific warnings implementation in warning_tests."""
...
@@ -40,16 +44,32 @@ def warnings_state(module):
...
@@ -40,16 +44,32 @@ def warnings_state(module):
warning_tests
.
warnings
=
original_warnings
warning_tests
.
warnings
=
original_warnings
class
FilterTests
(
unittest
.
TestCase
):
class
BaseTest
(
unittest
.
TestCase
):
"""
Testing the filtering functionality
."""
"""
Basic bookkeeping required for testing
."""
def
setUp
(
self
):
def
setUp
(
self
):
global
__warningregistry__
# The __warningregistry__ needs to be in a pristine state for tests
try
:
# to work properly.
__warningregistry__
.
clear
()
if
'__warningregistry__'
in
globals
():
except
NameError
:
del
globals
()[
'__warningregistry__'
]
pass
if
hasattr
(
warning_tests
,
'__warningregistry__'
):
del
warning_tests
.
__warningregistry__
if
hasattr
(
sys
,
'__warningregistry__'
):
del
sys
.
__warningregistry__
# The 'warnings' module must be explicitly set so that the proper
# interaction between _warnings and 'warnings' can be controlled.
sys
.
modules
[
'warnings'
]
=
self
.
module
super
(
BaseTest
,
self
)
.
setUp
()
def
tearDown
(
self
):
sys
.
modules
[
'warnings'
]
=
original_warnings
super
(
BaseTest
,
self
)
.
tearDown
()
class
FilterTests
(
object
):
"""Testing the filtering functionality."""
def
test_error
(
self
):
def
test_error
(
self
):
with
test_support
.
catch_warning
(
self
.
module
)
as
w
:
with
test_support
.
catch_warning
(
self
.
module
)
as
w
:
...
@@ -164,10 +184,10 @@ class FilterTests(unittest.TestCase):
...
@@ -164,10 +184,10 @@ class FilterTests(unittest.TestCase):
self
.
assertEqual
(
str
(
w
.
message
),
text
)
self
.
assertEqual
(
str
(
w
.
message
),
text
)
self
.
assert_
(
w
.
category
is
UserWarning
)
self
.
assert_
(
w
.
category
is
UserWarning
)
class
CFilterTests
(
FilterTests
):
class
CFilterTests
(
BaseTest
,
FilterTests
):
module
=
c_warnings
module
=
c_warnings
class
PyFilterTests
(
FilterTests
):
class
PyFilterTests
(
BaseTest
,
FilterTests
):
module
=
py_warnings
module
=
py_warnings
...
@@ -210,10 +230,10 @@ class WarnTests(unittest.TestCase):
...
@@ -210,10 +230,10 @@ class WarnTests(unittest.TestCase):
self
.
assertEqual
(
os
.
path
.
basename
(
w
.
filename
),
"sys"
)
self
.
assertEqual
(
os
.
path
.
basename
(
w
.
filename
),
"sys"
)
class
CWarnTests
(
WarnTests
):
class
CWarnTests
(
BaseTest
,
WarnTests
):
module
=
c_warnings
module
=
c_warnings
class
PyWarnTests
(
WarnTests
):
class
PyWarnTests
(
BaseTest
,
WarnTests
):
module
=
py_warnings
module
=
py_warnings
...
@@ -232,14 +252,14 @@ class WCmdLineTests(unittest.TestCase):
...
@@ -232,14 +252,14 @@ class WCmdLineTests(unittest.TestCase):
self
.
module
.
_setoption
(
'error::Warning::0'
)
self
.
module
.
_setoption
(
'error::Warning::0'
)
self
.
assertRaises
(
UserWarning
,
self
.
module
.
warn
,
'convert to error'
)
self
.
assertRaises
(
UserWarning
,
self
.
module
.
warn
,
'convert to error'
)
class
CWCmdLineTests
(
WCmdLineTests
):
class
CWCmdLineTests
(
BaseTest
,
WCmdLineTests
):
module
=
c_warnings
module
=
c_warnings
class
PyWCmdLineTests
(
WCmdLineTests
):
class
PyWCmdLineTests
(
BaseTest
,
WCmdLineTests
):
module
=
py_warnings
module
=
py_warnings
class
_WarningsTests
(
unittest
.
TestCase
):
class
_WarningsTests
(
BaseTest
):
"""Tests specific to the _warnings module."""
"""Tests specific to the _warnings module."""
...
@@ -362,30 +382,23 @@ class WarningsDisplayTests(unittest.TestCase):
...
@@ -362,30 +382,23 @@ class WarningsDisplayTests(unittest.TestCase):
file_object
,
expected_file_line
)
file_object
,
expected_file_line
)
self
.
failUnlessEqual
(
expect
,
file_object
.
getvalue
())
self
.
failUnlessEqual
(
expect
,
file_object
.
getvalue
())
class
CWarningsDisplayTests
(
WarningsDisplayTests
):
class
CWarningsDisplayTests
(
BaseTest
,
WarningsDisplayTests
):
module
=
c_warnings
module
=
c_warnings
class
PyWarningsDisplayTests
(
WarningsDisplayTests
):
class
PyWarningsDisplayTests
(
BaseTest
,
WarningsDisplayTests
):
module
=
py_warnings
module
=
py_warnings
def
test_main
():
def
test_main
():
# Obscure hack so that this test passes after reloads or repeated calls
test_support
.
run_unittest
(
CFilterTests
,
# to test_main (regrtest -R).
PyFilterTests
,
if
'__warningregistry__'
in
globals
():
CWarnTests
,
del
globals
()[
'__warningregistry__'
]
PyWarnTests
,
if
hasattr
(
warning_tests
,
'__warningregistry__'
):
del
warning_tests
.
__warningregistry__
if
hasattr
(
sys
,
'__warningregistry__'
):
del
sys
.
__warningregistry__
test_support
.
run_unittest
(
CFilterTests
,
PyFilterTests
,
CWarnTests
,
PyWarnTests
,
CWCmdLineTests
,
PyWCmdLineTests
,
CWCmdLineTests
,
PyWCmdLineTests
,
_WarningsTests
,
_WarningsTests
,
CWarningsDisplayTests
,
PyWarningsDisplayTests
,
CWarningsDisplayTests
,
PyWarningsDisplayTests
,
)
)
if
__name__
==
"__main__"
:
if
__name__
==
"__main__"
:
test_main
()
test_main
()
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