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
f2dfef16
Kaydet (Commit)
f2dfef16
authored
Nis 05, 2009
tarafından
Michael Foord
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Adding assertIs and assertIsNot methods to unittest.TestCase
Issue #2578
üst
7ab5eb91
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
54 additions
and
0 deletions
+54
-0
unittest.rst
Doc/library/unittest.rst
+17
-0
test_unittest.py
Lib/test/test_unittest.py
+23
-0
unittest.py
Lib/unittest.py
+12
-0
NEWS
Misc/NEWS
+2
-0
No files found.
Doc/library/unittest.rst
Dosyayı görüntüle @
f2dfef16
...
@@ -859,6 +859,23 @@ Test cases
...
@@ -859,6 +859,23 @@ Test cases
.. versionadded:: 2.7
.. versionadded:: 2.7
.. method:: assertIs(expr1, expr2[, msg])
This signals a test failure if *expr1* and *expr2* don't evaluate to the same
object.
.. versionadded:: 2.7
.. method:: assertIsNot(expr1, expr2[, msg])
The inverse of the :meth:`assertIs` method.
This signals a test failure if *expr1* and *expr2* evaluate to the same
object.
.. versionadded:: 2.7
.. method:: assertFalse(expr[, msg])
.. method:: assertFalse(expr[, msg])
failIf(expr[, msg])
failIf(expr[, msg])
...
...
Lib/test/test_unittest.py
Dosyayı görüntüle @
f2dfef16
...
@@ -2301,6 +2301,16 @@ class Test_TestCase(TestCase, TestEquality, TestHashing):
...
@@ -2301,6 +2301,16 @@ class Test_TestCase(TestCase, TestEquality, TestHashing):
# from this TestCase instance but since its a local nothing else
# from this TestCase instance but since its a local nothing else
# will ever notice that.
# will ever notice that.
def
testAssertIs
(
self
):
thing
=
object
()
self
.
assertIs
(
thing
,
thing
)
self
.
assertRaises
(
self
.
failureException
,
self
.
assertIs
,
thing
,
object
())
def
testAssertIsNot
(
self
):
thing
=
object
()
self
.
assertIsNot
(
thing
,
object
())
self
.
assertRaises
(
self
.
failureException
,
self
.
assertIsNot
,
thing
,
thing
)
def
testAssertIn
(
self
):
def
testAssertIn
(
self
):
animals
=
{
'monkey'
:
'banana'
,
'cow'
:
'grass'
,
'seal'
:
'fish'
}
animals
=
{
'monkey'
:
'banana'
,
'cow'
:
'grass'
,
'seal'
:
'fish'
}
...
@@ -2444,6 +2454,7 @@ class Test_TestCase(TestCase, TestEquality, TestHashing):
...
@@ -2444,6 +2454,7 @@ class Test_TestCase(TestCase, TestEquality, TestHashing):
# Test that sequences of unhashable objects can be tested for sameness:
# Test that sequences of unhashable objects can be tested for sameness:
self
.
assertSameElements
([[
1
,
2
],
[
3
,
4
]],
[[
3
,
4
],
[
1
,
2
]])
self
.
assertSameElements
([[
1
,
2
],
[
3
,
4
]],
[[
3
,
4
],
[
1
,
2
]])
self
.
assertSameElements
([{
'a'
:
1
},
{
'b'
:
2
}],
[{
'b'
:
2
},
{
'a'
:
1
}])
self
.
assertSameElements
([{
'a'
:
1
},
{
'b'
:
2
}],
[{
'b'
:
2
},
{
'a'
:
1
}])
self
.
assertRaises
(
self
.
failureException
,
self
.
assertSameElements
,
self
.
assertRaises
(
self
.
failureException
,
self
.
assertSameElements
,
[[
1
]],
[[
2
]])
[[
1
]],
[[
2
]])
...
@@ -3016,6 +3027,18 @@ class TestLongMessage(TestCase):
...
@@ -3016,6 +3027,18 @@ class TestLongMessage(TestCase):
"^unexpectedly None$"
,
"^unexpectedly None$"
,
"^unexpectedly None : oops$"
])
"^unexpectedly None : oops$"
])
def
testAssertIs
(
self
):
self
.
assertMessages
(
'assertIs'
,
(
None
,
'foo'
),
[
"^None is not 'foo'$"
,
"^oops$"
,
"^None is not 'foo'$"
,
"^None is not 'foo' : oops$"
])
def
testAssertIsNot
(
self
):
self
.
assertMessages
(
'assertIsNot'
,
(
None
,
None
),
[
"^unexpectedly identical: None$"
,
"^oops$"
,
"^unexpectedly identical: None$"
,
"^unexpectedly identical: None : oops$"
])
######################################################################
######################################################################
## Main
## Main
...
...
Lib/unittest.py
Dosyayı görüntüle @
f2dfef16
...
@@ -806,6 +806,18 @@ class TestCase(object):
...
@@ -806,6 +806,18 @@ class TestCase(object):
standardMsg
=
'
%
r unexpectedly found in
%
r'
%
(
member
,
container
)
standardMsg
=
'
%
r unexpectedly found in
%
r'
%
(
member
,
container
)
self
.
fail
(
self
.
_formatMessage
(
msg
,
standardMsg
))
self
.
fail
(
self
.
_formatMessage
(
msg
,
standardMsg
))
def
assertIs
(
self
,
expr1
,
expr2
,
msg
=
None
):
"""Just like self.assertTrue(a is b), but with a nicer default message."""
if
expr1
is
not
expr2
:
standardMsg
=
'
%
r is not
%
r'
%
(
expr1
,
expr2
)
self
.
fail
(
self
.
_formatMessage
(
msg
,
standardMsg
))
def
assertIsNot
(
self
,
expr1
,
expr2
,
msg
=
None
):
"""Just like self.assertTrue(a is not b), but with a nicer default message."""
if
expr1
is
expr2
:
standardMsg
=
'unexpectedly identical:
%
r'
%
(
expr1
,)
self
.
fail
(
self
.
_formatMessage
(
msg
,
standardMsg
))
def
assertDictEqual
(
self
,
d1
,
d2
,
msg
=
None
):
def
assertDictEqual
(
self
,
d1
,
d2
,
msg
=
None
):
self
.
assert_
(
isinstance
(
d1
,
dict
),
'First argument is not a dictionary'
)
self
.
assert_
(
isinstance
(
d1
,
dict
),
'First argument is not a dictionary'
)
self
.
assert_
(
isinstance
(
d2
,
dict
),
'Second argument is not a dictionary'
)
self
.
assert_
(
isinstance
(
d2
,
dict
),
'Second argument is not a dictionary'
)
...
...
Misc/NEWS
Dosyayı görüntüle @
f2dfef16
...
@@ -212,6 +212,8 @@ Core and Builtins
...
@@ -212,6 +212,8 @@ Core and Builtins
Library
Library
-------
-------
- Issue 5693: TestSuite.__iter__ can now be consistently overridden in subclasses.
- Issue 5694: removed spurious test output in Distutils (test_clean).
- Issue 5694: removed spurious test output in Distutils (test_clean).
- Issue 5471: Fix os.path.expanduser() for $HOME set to '/'.
- Issue 5471: Fix os.path.expanduser() for $HOME set to '/'.
...
...
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