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
6b0032f2
Kaydet (Commit)
6b0032f2
authored
Haz 30, 2009
tarafından
Benjamin Peterson
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
use assert* methods in test_unittest
üst
5c8da86f
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
53 additions
and
53 deletions
+53
-53
test_unittest.py
Lib/test/test_unittest.py
+53
-53
No files found.
Lib/test/test_unittest.py
Dosyayı görüntüle @
6b0032f2
...
...
@@ -78,8 +78,8 @@ class TestEquality(object):
# Check for a valid __ne__ implementation
def
test_ne
(
self
):
for
obj_1
,
obj_2
in
self
.
ne_pairs
:
self
.
failIf
Equal
(
obj_1
,
obj_2
)
self
.
failIf
Equal
(
obj_2
,
obj_1
)
self
.
assertNot
Equal
(
obj_1
,
obj_2
)
self
.
assertNot
Equal
(
obj_2
,
obj_1
)
class
TestHashing
(
object
):
"""Used as a mixin for TestCase"""
...
...
@@ -181,10 +181,10 @@ class Test_TestLoader(TestCase):
loader
=
unittest
.
TestLoader
()
# This has to be false for the test to succeed
self
.
failIf
(
'runTest'
.
startswith
(
loader
.
testMethodPrefix
))
self
.
assertFalse
(
'runTest'
.
startswith
(
loader
.
testMethodPrefix
))
suite
=
loader
.
loadTestsFromTestCase
(
Foo
)
self
.
failUnless
(
isinstance
(
suite
,
loader
.
suiteClass
))
self
.
assertTrue
(
isinstance
(
suite
,
loader
.
suiteClass
))
self
.
assertEqual
(
list
(
suite
),
[
Foo
(
'runTest'
)])
################################################################
...
...
@@ -203,7 +203,7 @@ class Test_TestLoader(TestCase):
loader
=
unittest
.
TestLoader
()
suite
=
loader
.
loadTestsFromModule
(
m
)
self
.
failUnless
(
isinstance
(
suite
,
loader
.
suiteClass
))
self
.
assertTrue
(
isinstance
(
suite
,
loader
.
suiteClass
))
expected
=
[
loader
.
suiteClass
([
MyTestCase
(
'test'
)])]
self
.
assertEqual
(
list
(
suite
),
expected
)
...
...
@@ -216,7 +216,7 @@ class Test_TestLoader(TestCase):
loader
=
unittest
.
TestLoader
()
suite
=
loader
.
loadTestsFromModule
(
m
)
self
.
failUnless
(
isinstance
(
suite
,
loader
.
suiteClass
))
self
.
assertTrue
(
isinstance
(
suite
,
loader
.
suiteClass
))
self
.
assertEqual
(
list
(
suite
),
[])
# "This method searches `module` for classes derived from TestCase"
...
...
@@ -230,7 +230,7 @@ class Test_TestLoader(TestCase):
loader
=
unittest
.
TestLoader
()
suite
=
loader
.
loadTestsFromModule
(
m
)
self
.
failUnless
(
isinstance
(
suite
,
loader
.
suiteClass
))
self
.
assertTrue
(
isinstance
(
suite
,
loader
.
suiteClass
))
self
.
assertEqual
(
list
(
suite
),
[
loader
.
suiteClass
()])
...
...
@@ -466,7 +466,7 @@ class Test_TestLoader(TestCase):
loader
=
unittest
.
TestLoader
()
suite
=
loader
.
loadTestsFromName
(
'testcase_1'
,
m
)
self
.
failUnless
(
isinstance
(
suite
,
loader
.
suiteClass
))
self
.
assertTrue
(
isinstance
(
suite
,
loader
.
suiteClass
))
self
.
assertEqual
(
list
(
suite
),
[
MyTestCase
(
'test'
)])
# "The specifier name is a ``dotted name'' that may resolve either to
...
...
@@ -482,7 +482,7 @@ class Test_TestLoader(TestCase):
loader
=
unittest
.
TestLoader
()
suite
=
loader
.
loadTestsFromName
(
'testsuite'
,
m
)
self
.
failUnless
(
isinstance
(
suite
,
loader
.
suiteClass
))
self
.
assertTrue
(
isinstance
(
suite
,
loader
.
suiteClass
))
self
.
assertEqual
(
list
(
suite
),
[
MyTestCase
(
'test'
)])
...
...
@@ -497,7 +497,7 @@ class Test_TestLoader(TestCase):
loader
=
unittest
.
TestLoader
()
suite
=
loader
.
loadTestsFromName
(
'testcase_1.test'
,
m
)
self
.
failUnless
(
isinstance
(
suite
,
loader
.
suiteClass
))
self
.
assertTrue
(
isinstance
(
suite
,
loader
.
suiteClass
))
self
.
assertEqual
(
list
(
suite
),
[
MyTestCase
(
'test'
)])
...
...
@@ -536,7 +536,7 @@ class Test_TestLoader(TestCase):
loader
=
unittest
.
TestLoader
()
suite
=
loader
.
loadTestsFromName
(
'return_TestSuite'
,
m
)
self
.
failUnless
(
isinstance
(
suite
,
loader
.
suiteClass
))
self
.
assertTrue
(
isinstance
(
suite
,
loader
.
suiteClass
))
self
.
assertEqual
(
list
(
suite
),
[
testcase_1
,
testcase_2
])
# "The specifier name is a ``dotted name'' that may resolve ... to
...
...
@@ -550,7 +550,7 @@ class Test_TestLoader(TestCase):
loader
=
unittest
.
TestLoader
()
suite
=
loader
.
loadTestsFromName
(
'return_TestCase'
,
m
)
self
.
failUnless
(
isinstance
(
suite
,
loader
.
suiteClass
))
self
.
assertTrue
(
isinstance
(
suite
,
loader
.
suiteClass
))
self
.
assertEqual
(
list
(
suite
),
[
testcase_1
])
# "The specifier name is a ``dotted name'' that may resolve ... to
...
...
@@ -589,11 +589,11 @@ class Test_TestLoader(TestCase):
try
:
suite
=
loader
.
loadTestsFromName
(
module_name
)
self
.
failUnless
(
isinstance
(
suite
,
loader
.
suiteClass
))
self
.
assertTrue
(
isinstance
(
suite
,
loader
.
suiteClass
))
self
.
assertEqual
(
list
(
suite
),
[])
# audioop should now be loaded, thanks to loadTestsFromName()
self
.
failUnless
(
module_name
in
sys
.
modules
)
self
.
assertTrue
(
module_name
in
sys
.
modules
)
finally
:
if
module_name
in
sys
.
modules
:
del
sys
.
modules
[
module_name
]
...
...
@@ -612,7 +612,7 @@ class Test_TestLoader(TestCase):
loader
=
unittest
.
TestLoader
()
suite
=
loader
.
loadTestsFromNames
([])
self
.
failUnless
(
isinstance
(
suite
,
loader
.
suiteClass
))
self
.
assertTrue
(
isinstance
(
suite
,
loader
.
suiteClass
))
self
.
assertEqual
(
list
(
suite
),
[])
# "Similar to loadTestsFromName(), but takes a sequence of names rather
...
...
@@ -627,7 +627,7 @@ class Test_TestLoader(TestCase):
loader
=
unittest
.
TestLoader
()
suite
=
loader
.
loadTestsFromNames
([],
unittest
)
self
.
failUnless
(
isinstance
(
suite
,
loader
.
suiteClass
))
self
.
assertTrue
(
isinstance
(
suite
,
loader
.
suiteClass
))
self
.
assertEqual
(
list
(
suite
),
[])
# "The specifier name is a ``dotted name'' that may resolve either to
...
...
@@ -828,7 +828,7 @@ class Test_TestLoader(TestCase):
loader
=
unittest
.
TestLoader
()
suite
=
loader
.
loadTestsFromNames
([
'testcase_1'
],
m
)
self
.
failUnless
(
isinstance
(
suite
,
loader
.
suiteClass
))
self
.
assertTrue
(
isinstance
(
suite
,
loader
.
suiteClass
))
expected
=
loader
.
suiteClass
([
MyTestCase
(
'test'
)])
self
.
assertEqual
(
list
(
suite
),
[
expected
])
...
...
@@ -844,7 +844,7 @@ class Test_TestLoader(TestCase):
loader
=
unittest
.
TestLoader
()
suite
=
loader
.
loadTestsFromNames
([
'testsuite'
],
m
)
self
.
failUnless
(
isinstance
(
suite
,
loader
.
suiteClass
))
self
.
assertTrue
(
isinstance
(
suite
,
loader
.
suiteClass
))
self
.
assertEqual
(
list
(
suite
),
[
m
.
testsuite
])
...
...
@@ -859,7 +859,7 @@ class Test_TestLoader(TestCase):
loader
=
unittest
.
TestLoader
()
suite
=
loader
.
loadTestsFromNames
([
'testcase_1.test'
],
m
)
self
.
failUnless
(
isinstance
(
suite
,
loader
.
suiteClass
))
self
.
assertTrue
(
isinstance
(
suite
,
loader
.
suiteClass
))
ref_suite
=
unittest
.
TestSuite
([
MyTestCase
(
'test'
)])
self
.
assertEqual
(
list
(
suite
),
[
ref_suite
])
...
...
@@ -896,7 +896,7 @@ class Test_TestLoader(TestCase):
loader
=
unittest
.
TestLoader
()
suite
=
loader
.
loadTestsFromNames
([
'return_TestSuite'
],
m
)
self
.
failUnless
(
isinstance
(
suite
,
loader
.
suiteClass
))
self
.
assertTrue
(
isinstance
(
suite
,
loader
.
suiteClass
))
expected
=
unittest
.
TestSuite
([
testcase_1
,
testcase_2
])
self
.
assertEqual
(
list
(
suite
),
[
expected
])
...
...
@@ -912,7 +912,7 @@ class Test_TestLoader(TestCase):
loader
=
unittest
.
TestLoader
()
suite
=
loader
.
loadTestsFromNames
([
'return_TestCase'
],
m
)
self
.
failUnless
(
isinstance
(
suite
,
loader
.
suiteClass
))
self
.
assertTrue
(
isinstance
(
suite
,
loader
.
suiteClass
))
ref_suite
=
unittest
.
TestSuite
([
testcase_1
])
self
.
assertEqual
(
list
(
suite
),
[
ref_suite
])
...
...
@@ -936,7 +936,7 @@ class Test_TestLoader(TestCase):
loader
=
unittest
.
TestLoader
()
suite
=
loader
.
loadTestsFromNames
([
'Foo.foo'
],
m
)
self
.
failUnless
(
isinstance
(
suite
,
loader
.
suiteClass
))
self
.
assertTrue
(
isinstance
(
suite
,
loader
.
suiteClass
))
ref_suite
=
unittest
.
TestSuite
([
testcase_1
])
self
.
assertEqual
(
list
(
suite
),
[
ref_suite
])
...
...
@@ -977,11 +977,11 @@ class Test_TestLoader(TestCase):
try
:
suite
=
loader
.
loadTestsFromNames
([
module_name
])
self
.
failUnless
(
isinstance
(
suite
,
loader
.
suiteClass
))
self
.
assertTrue
(
isinstance
(
suite
,
loader
.
suiteClass
))
self
.
assertEqual
(
list
(
suite
),
[
unittest
.
TestSuite
()])
# audioop should now be loaded, thanks to loadTestsFromName()
self
.
failUnless
(
module_name
in
sys
.
modules
)
self
.
assertTrue
(
module_name
in
sys
.
modules
)
finally
:
if
module_name
in
sys
.
modules
:
del
sys
.
modules
[
module_name
]
...
...
@@ -1156,7 +1156,7 @@ class Test_TestLoader(TestCase):
# "The default value is 'test'"
def
test_testMethodPrefix__default_value
(
self
):
loader
=
unittest
.
TestLoader
()
self
.
failUnless
(
loader
.
testMethodPrefix
==
'test'
)
self
.
assertTrue
(
loader
.
testMethodPrefix
==
'test'
)
################################################################
### /Tests for TestLoader.testMethodPrefix
...
...
@@ -1255,7 +1255,7 @@ class Test_TestLoader(TestCase):
# "The default value is the built-in cmp() function"
def
test_sortTestMethodsUsing__default_value
(
self
):
loader
=
unittest
.
TestLoader
()
self
.
failUnless
(
loader
.
sortTestMethodsUsing
is
cmp
)
self
.
assertTrue
(
loader
.
sortTestMethodsUsing
is
cmp
)
# "it can be set to None to disable the sort."
#
...
...
@@ -1342,7 +1342,7 @@ class Test_TestLoader(TestCase):
# "The default value is the TestSuite class"
def
test_suiteClass__default_value
(
self
):
loader
=
unittest
.
TestLoader
()
self
.
failUnless
(
loader
.
suiteClass
is
unittest
.
TestSuite
)
self
.
assertTrue
(
loader
.
suiteClass
is
unittest
.
TestSuite
)
################################################################
### /Tests for TestLoader.suiteClass
...
...
@@ -1755,7 +1755,7 @@ class Test_FunctionTestCase(TestCase):
def
test_id
(
self
):
test
=
unittest
.
FunctionTestCase
(
lambda
:
None
)
self
.
failUnless
(
isinstance
(
test
.
id
(),
basestring
))
self
.
assertTrue
(
isinstance
(
test
.
id
(),
basestring
))
# "Returns a one-line description of the test, or None if no description
# has been provided. The default implementation of this method returns
...
...
@@ -1787,7 +1787,7 @@ class Test_TestResult(TestCase):
def
test_init
(
self
):
result
=
unittest
.
TestResult
()
self
.
failUnless
(
result
.
wasSuccessful
())
self
.
assertTrue
(
result
.
wasSuccessful
())
self
.
assertEqual
(
len
(
result
.
errors
),
0
)
self
.
assertEqual
(
len
(
result
.
failures
),
0
)
self
.
assertEqual
(
result
.
testsRun
,
0
)
...
...
@@ -1816,7 +1816,7 @@ class Test_TestResult(TestCase):
result
.
startTest
(
test
)
self
.
failUnless
(
result
.
wasSuccessful
())
self
.
assertTrue
(
result
.
wasSuccessful
())
self
.
assertEqual
(
len
(
result
.
errors
),
0
)
self
.
assertEqual
(
len
(
result
.
failures
),
0
)
self
.
assertEqual
(
result
.
testsRun
,
1
)
...
...
@@ -1837,7 +1837,7 @@ class Test_TestResult(TestCase):
result
.
startTest
(
test
)
self
.
failUnless
(
result
.
wasSuccessful
())
self
.
assertTrue
(
result
.
wasSuccessful
())
self
.
assertEqual
(
len
(
result
.
errors
),
0
)
self
.
assertEqual
(
len
(
result
.
failures
),
0
)
self
.
assertEqual
(
result
.
testsRun
,
1
)
...
...
@@ -1846,7 +1846,7 @@ class Test_TestResult(TestCase):
result
.
stopTest
(
test
)
# Same tests as above; make sure nothing has changed
self
.
failUnless
(
result
.
wasSuccessful
())
self
.
assertTrue
(
result
.
wasSuccessful
())
self
.
assertEqual
(
len
(
result
.
errors
),
0
)
self
.
assertEqual
(
len
(
result
.
failures
),
0
)
self
.
assertEqual
(
result
.
testsRun
,
1
)
...
...
@@ -1890,7 +1890,7 @@ class Test_TestResult(TestCase):
result
.
addSuccess
(
test
)
result
.
stopTest
(
test
)
self
.
failUnless
(
result
.
wasSuccessful
())
self
.
assertTrue
(
result
.
wasSuccessful
())
self
.
assertEqual
(
len
(
result
.
errors
),
0
)
self
.
assertEqual
(
len
(
result
.
failures
),
0
)
self
.
assertEqual
(
result
.
testsRun
,
1
)
...
...
@@ -1935,15 +1935,15 @@ class Test_TestResult(TestCase):
result
.
addFailure
(
test
,
exc_info_tuple
)
result
.
stopTest
(
test
)
self
.
failIf
(
result
.
wasSuccessful
())
self
.
assertFalse
(
result
.
wasSuccessful
())
self
.
assertEqual
(
len
(
result
.
errors
),
0
)
self
.
assertEqual
(
len
(
result
.
failures
),
1
)
self
.
assertEqual
(
result
.
testsRun
,
1
)
self
.
assertEqual
(
result
.
shouldStop
,
False
)
test_case
,
formatted_exc
=
result
.
failures
[
0
]
self
.
failUnless
(
test_case
is
test
)
self
.
failUnless
(
isinstance
(
formatted_exc
,
str
))
self
.
assertTrue
(
test_case
is
test
)
self
.
assertTrue
(
isinstance
(
formatted_exc
,
str
))
# "addError(test, err)"
# ...
...
...
@@ -1985,15 +1985,15 @@ class Test_TestResult(TestCase):
result
.
addError
(
test
,
exc_info_tuple
)
result
.
stopTest
(
test
)
self
.
failIf
(
result
.
wasSuccessful
())
self
.
assertFalse
(
result
.
wasSuccessful
())
self
.
assertEqual
(
len
(
result
.
errors
),
1
)
self
.
assertEqual
(
len
(
result
.
failures
),
0
)
self
.
assertEqual
(
result
.
testsRun
,
1
)
self
.
assertEqual
(
result
.
shouldStop
,
False
)
test_case
,
formatted_exc
=
result
.
errors
[
0
]
self
.
failUnless
(
test_case
is
test
)
self
.
failUnless
(
isinstance
(
formatted_exc
,
str
))
self
.
assertTrue
(
test_case
is
test
)
self
.
assertTrue
(
isinstance
(
formatted_exc
,
str
))
### Support code for Test_TestCase
################################################################
...
...
@@ -2307,7 +2307,7 @@ class Test_TestCase(TestCase, TestEquality, TestHashing):
def
test
(
self
):
pass
self
.
failUnless
(
Foo
(
'test'
)
.
failureException
is
AssertionError
)
self
.
assertTrue
(
Foo
(
'test'
)
.
failureException
is
AssertionError
)
# "This class attribute gives the exception raised by the test() method.
# If a test framework needs to use a specialized exception, possibly to
...
...
@@ -2325,7 +2325,7 @@ class Test_TestCase(TestCase, TestEquality, TestHashing):
failureException
=
RuntimeError
self
.
failUnless
(
Foo
(
'test'
)
.
failureException
is
RuntimeError
)
self
.
assertTrue
(
Foo
(
'test'
)
.
failureException
is
RuntimeError
)
Foo
(
'test'
)
.
run
(
result
)
...
...
@@ -2348,7 +2348,7 @@ class Test_TestCase(TestCase, TestEquality, TestHashing):
failureException
=
RuntimeError
self
.
failUnless
(
Foo
(
'test'
)
.
failureException
is
RuntimeError
)
self
.
assertTrue
(
Foo
(
'test'
)
.
failureException
is
RuntimeError
)
Foo
(
'test'
)
.
run
(
result
)
...
...
@@ -2384,7 +2384,7 @@ class Test_TestCase(TestCase, TestEquality, TestHashing):
def
runTest
(
self
):
pass
self
.
failUnless
(
isinstance
(
Foo
()
.
id
(),
basestring
))
self
.
assertTrue
(
isinstance
(
Foo
()
.
id
(),
basestring
))
# "If result is omitted or None, a temporary result object is created
# and used, but is not made available to the caller. As TestCase owns the
...
...
@@ -2955,23 +2955,23 @@ class Test_TestSkipping(TestCase):
class
Test_Assertions
(
TestCase
):
def
test_AlmostEqual
(
self
):
self
.
failUnless
AlmostEqual
(
1.00000001
,
1.0
)
self
.
failIf
AlmostEqual
(
1.0000001
,
1.0
)
self
.
assert
AlmostEqual
(
1.00000001
,
1.0
)
self
.
assertNot
AlmostEqual
(
1.0000001
,
1.0
)
self
.
assertRaises
(
self
.
failureException
,
self
.
failUnless
AlmostEqual
,
1.0000001
,
1.0
)
self
.
assert
AlmostEqual
,
1.0000001
,
1.0
)
self
.
assertRaises
(
self
.
failureException
,
self
.
failIf
AlmostEqual
,
1.00000001
,
1.0
)
self
.
assertNot
AlmostEqual
,
1.00000001
,
1.0
)
self
.
failUnless
AlmostEqual
(
1.1
,
1.0
,
places
=
0
)
self
.
assert
AlmostEqual
(
1.1
,
1.0
,
places
=
0
)
self
.
assertRaises
(
self
.
failureException
,
self
.
failUnless
AlmostEqual
,
1.1
,
1.0
,
places
=
1
)
self
.
assert
AlmostEqual
,
1.1
,
1.0
,
places
=
1
)
self
.
failUnless
AlmostEqual
(
0
,
.
1
+.
1
j
,
places
=
0
)
self
.
failIf
AlmostEqual
(
0
,
.
1
+.
1
j
,
places
=
1
)
self
.
assert
AlmostEqual
(
0
,
.
1
+.
1
j
,
places
=
0
)
self
.
assertNot
AlmostEqual
(
0
,
.
1
+.
1
j
,
places
=
1
)
self
.
assertRaises
(
self
.
failureException
,
self
.
failUnless
AlmostEqual
,
0
,
.
1
+.
1
j
,
places
=
1
)
self
.
assert
AlmostEqual
,
0
,
.
1
+.
1
j
,
places
=
1
)
self
.
assertRaises
(
self
.
failureException
,
self
.
failIf
AlmostEqual
,
0
,
.
1
+.
1
j
,
places
=
0
)
self
.
assertNot
AlmostEqual
,
0
,
.
1
+.
1
j
,
places
=
0
)
def
test_assertRaises
(
self
):
def
_raise
(
e
):
...
...
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