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
ae3db0a1
Kaydet (Commit)
ae3db0a1
authored
Şub 22, 2010
tarafından
Michael Foord
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Support for old TestResult object (unittest) with warnings when using unsupported features.
üst
4b81bc7f
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
77 additions
and
8 deletions
+77
-8
test_unittest.py
Lib/test/test_unittest.py
+49
-1
case.py
Lib/unittest/case.py
+26
-5
result.py
Lib/unittest/result.py
+2
-2
No files found.
Lib/test/test_unittest.py
Dosyayı görüntüle @
ae3db0a1
...
...
@@ -2062,6 +2062,53 @@ class Test_TestResult(TestCase):
'Tests getDescription() for a method with a longer '
'docstring.'
))
classDict
=
dict
(
unittest
.
TestResult
.
__dict__
)
for
m
in
'addSkip'
,
'addExpectedFailure'
,
'addUnexpectedSuccess'
:
del
classDict
[
m
]
OldResult
=
type
(
'OldResult'
,
(
object
,),
classDict
)
class
Test_OldTestResult
(
unittest
.
TestCase
):
def
assertOldResultWarning
(
self
,
test
,
failures
):
with
warnings
.
catch_warnings
(
record
=
True
)
as
log
:
result
=
OldResult
()
test
.
run
(
result
)
self
.
assertEqual
(
len
(
result
.
failures
),
failures
)
warning
,
=
log
self
.
assertIs
(
warning
.
category
,
RuntimeWarning
)
def
testOldTestResult
(
self
):
class
Test
(
unittest
.
TestCase
):
def
testSkip
(
self
):
self
.
skipTest
(
'foobar'
)
@unittest.expectedFailure
def
testExpectedFail
(
self
):
raise
TypeError
@unittest.expectedFailure
def
testUnexpectedSuccess
(
self
):
pass
for
test_name
,
should_pass
in
((
'testSkip'
,
True
),
(
'testExpectedFail'
,
True
),
(
'testUnexpectedSuccess'
,
False
)):
test
=
Test
(
test_name
)
self
.
assertOldResultWarning
(
test
,
int
(
not
should_pass
))
def
testOldTestTesultSetup
(
self
):
class
Test
(
unittest
.
TestCase
):
def
setUp
(
self
):
self
.
skipTest
(
'no reason'
)
def
testFoo
(
self
):
pass
self
.
assertOldResultWarning
(
Test
(
'testFoo'
),
0
)
def
testOldTestResultClass
(
self
):
@unittest.skip
(
'no reason'
)
class
Test
(
unittest
.
TestCase
):
def
testFoo
(
self
):
pass
self
.
assertOldResultWarning
(
Test
(
'testFoo'
),
0
)
### Support code for Test_TestCase
################################################################
...
...
@@ -3826,7 +3873,8 @@ def test_main():
test_support
.
run_unittest
(
Test_TestCase
,
Test_TestLoader
,
Test_TestSuite
,
Test_TestResult
,
Test_FunctionTestCase
,
Test_TestSkipping
,
Test_Assertions
,
TestLongMessage
,
Test_TestProgram
,
TestCleanUp
,
TestDiscovery
,
Test_TextTestRunner
)
Test_TestProgram
,
TestCleanUp
,
TestDiscovery
,
Test_TextTestRunner
,
Test_OldTestResult
)
if
__name__
==
"__main__"
:
test_main
()
Lib/unittest/case.py
Dosyayı görüntüle @
ae3db0a1
...
...
@@ -249,6 +249,15 @@ class TestCase(object):
return
"<
%
s testMethod=
%
s>"
%
\
(
strclass
(
self
.
__class__
),
self
.
_testMethodName
)
def
_addSkip
(
self
,
result
,
reason
):
addSkip
=
getattr
(
result
,
'addSkip'
,
None
)
if
addSkip
is
not
None
:
addSkip
(
self
,
reason
)
else
:
warnings
.
warn
(
"TestResult has no addSkip method, skips not reported"
,
RuntimeWarning
,
2
)
result
.
addSuccess
(
self
)
def
run
(
self
,
result
=
None
):
orig_result
=
result
if
result
is
None
:
...
...
@@ -262,7 +271,7 @@ class TestCase(object):
if
getattr
(
self
.
__class__
,
"__unittest_skip__"
,
False
):
# If the whole class was skipped.
try
:
result
.
addSkip
(
self
,
self
.
__class__
.
__unittest_skip_why__
)
self
.
_addSkip
(
result
,
self
.
__class__
.
__unittest_skip_why__
)
finally
:
result
.
stopTest
(
self
)
return
...
...
@@ -272,7 +281,7 @@ class TestCase(object):
try
:
self
.
setUp
()
except
SkipTest
as
e
:
result
.
addSkip
(
self
,
str
(
e
))
self
.
_addSkip
(
result
,
str
(
e
))
except
Exception
:
result
.
addError
(
self
,
sys
.
exc_info
())
else
:
...
...
@@ -281,11 +290,23 @@ class TestCase(object):
except
self
.
failureException
:
result
.
addFailure
(
self
,
sys
.
exc_info
())
except
_ExpectedFailure
as
e
:
result
.
addExpectedFailure
(
self
,
e
.
exc_info
)
addExpectedFailure
=
getattr
(
result
,
'addExpectedFailure'
,
None
)
if
addExpectedFailure
is
not
None
:
addExpectedFailure
(
self
,
e
.
exc_info
)
else
:
warnings
.
warn
(
"TestResult has no addExpectedFailure method, reporting as passes"
,
RuntimeWarning
)
result
.
addSuccess
(
self
)
except
_UnexpectedSuccess
:
result
.
addUnexpectedSuccess
(
self
)
addUnexpectedSuccess
=
getattr
(
result
,
'addUnexpectedSuccess'
,
None
)
if
addUnexpectedSuccess
is
not
None
:
addUnexpectedSuccess
(
self
)
else
:
warnings
.
warn
(
"TestResult has no addUnexpectedSuccess method, reporting as failures"
,
RuntimeWarning
)
result
.
addFailure
(
self
,
sys
.
exc_info
())
except
SkipTest
as
e
:
result
.
addSkip
(
self
,
str
(
e
))
self
.
_addSkip
(
result
,
str
(
e
))
except
Exception
:
result
.
addError
(
self
,
sys
.
exc_info
())
else
:
...
...
Lib/unittest/result.py
Dosyayı görüntüle @
ae3db0a1
...
...
@@ -107,6 +107,6 @@ class TestResult(object):
return
length
def
__repr__
(
self
):
return
"<
%
s run=
%
i errors=
%
i failures=
%
i>"
%
\
return
(
"<
%
s run=
%
i errors=
%
i failures=
%
i>"
%
(
util
.
strclass
(
self
.
__class__
),
self
.
testsRun
,
len
(
self
.
errors
),
len
(
self
.
failures
))
len
(
self
.
failures
))
)
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