Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
c646729c
Commit
c646729c
authored
Nov 17, 2013
by
Serhiy Storchaka
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Issue #19594: Use specific asserts in unittest tests.
parent
eda13afa
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
28 additions
and
28 deletions
+28
-28
Lib/unittest/test/test_case.py
Lib/unittest/test/test_case.py
+6
-6
Lib/unittest/test/test_loader.py
Lib/unittest/test/test_loader.py
+1
-1
Lib/unittest/test/test_result.py
Lib/unittest/test/test_result.py
+2
-2
Lib/unittest/test/testmock/testhelpers.py
Lib/unittest/test/testmock/testhelpers.py
+9
-9
Lib/unittest/test/testmock/testmagicmethods.py
Lib/unittest/test/testmock/testmagicmethods.py
+4
-4
Lib/unittest/test/testmock/testmock.py
Lib/unittest/test/testmock/testmock.py
+5
-5
Lib/unittest/test/testmock/testsentinel.py
Lib/unittest/test/testmock/testsentinel.py
+1
-1
No files found.
Lib/unittest/test/test_case.py
View file @
c646729c
...
...
@@ -307,7 +307,7 @@ class Test_TestCase(unittest.TestCase, TestEquality, TestHashing):
def
test
(
self
):
pass
self
.
assert
True
(
Foo
(
'test'
).
failureException
is
AssertionError
)
self
.
assert
Is
(
Foo
(
'test'
).
failureException
,
AssertionError
)
# "This class attribute gives the exception raised by the test() method.
# If a test framework needs to use a specialized exception, possibly to
...
...
@@ -325,7 +325,7 @@ class Test_TestCase(unittest.TestCase, TestEquality, TestHashing):
failureException
=
RuntimeError
self
.
assert
True
(
Foo
(
'test'
).
failureException
is
RuntimeError
)
self
.
assert
Is
(
Foo
(
'test'
).
failureException
,
RuntimeError
)
Foo
(
'test'
).
run
(
result
)
...
...
@@ -348,7 +348,7 @@ class Test_TestCase(unittest.TestCase, TestEquality, TestHashing):
failureException
=
RuntimeError
self
.
assert
True
(
Foo
(
'test'
).
failureException
is
RuntimeError
)
self
.
assert
Is
(
Foo
(
'test'
).
failureException
,
RuntimeError
)
Foo
(
'test'
).
run
(
result
)
...
...
@@ -660,7 +660,7 @@ class Test_TestCase(unittest.TestCase, TestEquality, TestHashing):
msg
=
e
.
args
[
0
]
else
:
self
.
fail
(
'assertSequenceEqual did not fail.'
)
self
.
assert
True
(
len
(
msg
)
<
len
(
diff
))
self
.
assert
Less
(
len
(
msg
),
len
(
diff
))
self
.
assertIn
(
omitted
,
msg
)
self
.
maxDiff
=
len
(
diff
)
*
2
...
...
@@ -670,7 +670,7 @@ class Test_TestCase(unittest.TestCase, TestEquality, TestHashing):
msg
=
e
.
args
[
0
]
else
:
self
.
fail
(
'assertSequenceEqual did not fail.'
)
self
.
assert
True
(
len
(
msg
)
>
len
(
diff
))
self
.
assert
Greater
(
len
(
msg
),
len
(
diff
))
self
.
assertNotIn
(
omitted
,
msg
)
self
.
maxDiff
=
None
...
...
@@ -680,7 +680,7 @@ class Test_TestCase(unittest.TestCase, TestEquality, TestHashing):
msg
=
e
.
args
[
0
]
else
:
self
.
fail
(
'assertSequenceEqual did not fail.'
)
self
.
assert
True
(
len
(
msg
)
>
len
(
diff
))
self
.
assert
Greater
(
len
(
msg
),
len
(
diff
))
self
.
assertNotIn
(
omitted
,
msg
)
def
testTruncateMessage
(
self
):
...
...
Lib/unittest/test/test_loader.py
View file @
c646729c
...
...
@@ -1305,4 +1305,4 @@ class Test_TestLoader(unittest.TestCase):
# "The default value is the TestSuite class"
def
test_suiteClass__default_value
(
self
):
loader
=
unittest
.
TestLoader
()
self
.
assert
True
(
loader
.
suiteClass
is
unittest
.
TestSuite
)
self
.
assert
Is
(
loader
.
suiteClass
,
unittest
.
TestSuite
)
Lib/unittest/test/test_result.py
View file @
c646729c
...
...
@@ -176,7 +176,7 @@ class Test_TestResult(unittest.TestCase):
self
.
assertEqual
(
result
.
shouldStop
,
False
)
test_case
,
formatted_exc
=
result
.
failures
[
0
]
self
.
assert
True
(
test_case
is
test
)
self
.
assert
Is
(
test_case
,
test
)
self
.
assertIsInstance
(
formatted_exc
,
str
)
# "addError(test, err)"
...
...
@@ -224,7 +224,7 @@ class Test_TestResult(unittest.TestCase):
self
.
assertEqual
(
result
.
shouldStop
,
False
)
test_case
,
formatted_exc
=
result
.
errors
[
0
]
self
.
assert
True
(
test_case
is
test
)
self
.
assert
Is
(
test_case
,
test
)
self
.
assertIsInstance
(
formatted_exc
,
str
)
def
testGetDescriptionWithoutDocstring
(
self
):
...
...
Lib/unittest/test/testmock/testhelpers.py
View file @
c646729c
...
...
@@ -177,7 +177,7 @@ class CallTest(unittest.TestCase):
args
=
_Call
(((
1
,
2
,
3
),
{}))
self
.
assertEqual
(
args
,
call
(
1
,
2
,
3
))
self
.
assertEqual
(
call
(
1
,
2
,
3
),
args
)
self
.
assert
True
(
call
(
1
,
2
,
3
)
in
[
args
])
self
.
assert
In
(
call
(
1
,
2
,
3
),
[
args
])
def
test_call_ne
(
self
):
...
...
@@ -793,7 +793,7 @@ class SpecSignatureTest(unittest.TestCase):
mock_property
=
foo
.
foo
# no spec on properties
self
.
assert
True
(
isinstance
(
mock_property
,
MagicMock
)
)
self
.
assert
IsInstance
(
mock_property
,
MagicMock
)
mock_property
(
1
,
2
,
3
)
mock_property
.
abc
(
4
,
5
,
6
)
mock_property
.
assert_called_once_with
(
1
,
2
,
3
)
...
...
@@ -826,19 +826,19 @@ class TestCallList(unittest.TestCase):
mock
(
b
=
6
)
for
kall
in
call
(
1
,
2
),
call
(
a
=
3
),
call
(
3
,
4
),
call
(
b
=
6
):
self
.
assert
True
(
kall
in
mock
.
call_args_list
)
self
.
assert
In
(
kall
,
mock
.
call_args_list
)
calls
=
[
call
(
a
=
3
),
call
(
3
,
4
)]
self
.
assert
True
(
calls
in
mock
.
call_args_list
)
self
.
assert
In
(
calls
,
mock
.
call_args_list
)
calls
=
[
call
(
1
,
2
),
call
(
a
=
3
)]
self
.
assert
True
(
calls
in
mock
.
call_args_list
)
self
.
assert
In
(
calls
,
mock
.
call_args_list
)
calls
=
[
call
(
3
,
4
),
call
(
b
=
6
)]
self
.
assert
True
(
calls
in
mock
.
call_args_list
)
self
.
assert
In
(
calls
,
mock
.
call_args_list
)
calls
=
[
call
(
3
,
4
)]
self
.
assert
True
(
calls
in
mock
.
call_args_list
)
self
.
assert
In
(
calls
,
mock
.
call_args_list
)
self
.
assert
False
(
call
(
'fish'
)
in
mock
.
call_args_list
)
self
.
assert
False
([
call
(
'fish'
)]
in
mock
.
call_args_list
)
self
.
assert
NotIn
(
call
(
'fish'
),
mock
.
call_args_list
)
self
.
assert
NotIn
([
call
(
'fish'
)],
mock
.
call_args_list
)
def
test_call_list_str
(
self
):
...
...
Lib/unittest/test/testmock/testmagicmethods.py
View file @
c646729c
...
...
@@ -37,12 +37,12 @@ class TestMockingMagicMethods(unittest.TestCase):
return
self
,
'fish'
mock
.
__getitem__
=
f
self
.
assert
False
(
mock
.
__getitem__
is
f
)
self
.
assert
IsNot
(
mock
.
__getitem__
,
f
)
self
.
assertEqual
(
mock
[
'foo'
],
(
mock
,
'fish'
))
self
.
assertEqual
(
mock
.
__getitem__
(
'foo'
),
(
mock
,
'fish'
))
mock
.
__getitem__
=
mock
self
.
assert
True
(
mock
.
__getitem__
is
mock
)
self
.
assert
Is
(
mock
.
__getitem__
,
mock
)
def
test_magic_methods_isolated_between_mocks
(
self
):
...
...
@@ -212,8 +212,8 @@ class TestMockingMagicMethods(unittest.TestCase):
self
.
assertEqual
(
len
(
mock
),
6
)
mock
.
__contains__
=
lambda
s
,
o
:
o
==
3
self
.
assert
True
(
3
in
mock
)
self
.
assert
False
(
6
in
mock
)
self
.
assert
In
(
3
,
mock
)
self
.
assert
NotIn
(
6
,
mock
)
mock
.
__iter__
=
lambda
s
:
iter
(
'foobarbaz'
)
self
.
assertEqual
(
list
(
mock
),
list
(
'foobarbaz'
))
...
...
Lib/unittest/test/testmock/testmock.py
View file @
c646729c
...
...
@@ -52,7 +52,7 @@ class MockTest(unittest.TestCase):
"method_calls not initialised correctly"
)
# Can't use hasattr for this test as it always returns True on a mock
self
.
assert
False
(
'_items'
in
mock
.
__dict__
,
self
.
assert
NotIn
(
'_items'
,
mock
.
__dict__
,
"default mock should not have '_items' attribute"
)
self
.
assertIsNone
(
mock
.
_mock_parent
,
...
...
@@ -493,19 +493,19 @@ class MockTest(unittest.TestCase):
pass
mock = Mock(spec=X)
self.assert
True(isinstance(mock, X)
)
self.assert
IsInstance(mock, X
)
mock = Mock(spec=X())
self.assert
True(isinstance(mock, X)
)
self.assert
IsInstance(mock, X
)
self.assertIs(mock.__class__, X)
self.assertEqual(Mock().__class__.__name__, 'Mock')
mock = Mock(spec_set=X)
self.assert
True(isinstance(mock, X)
)
self.assert
IsInstance(mock, X
)
mock = Mock(spec_set=X())
self.assert
True(isinstance(mock, X)
)
self.assert
IsInstance(mock, X
)
def test_setting_attribute_with_spec_set(self):
...
...
Lib/unittest/test/testmock/testsentinel.py
View file @
c646729c
...
...
@@ -17,7 +17,7 @@ class SentinelTest(unittest.TestCase):
def
testDEFAULT
(
self
):
self
.
assert
True
(
DEFAULT
is
sentinel
.
DEFAULT
)
self
.
assert
Is
(
DEFAULT
,
sentinel
.
DEFAULT
)
def
testBases
(
self
):
# If this doesn't raise an AttributeError then help(mock) is broken
...
...
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