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
be3856dc
Commit
be3856dc
authored
Aug 24, 2005
by
Georg Brandl
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
patch [ 1141428 ] more __contains__ tests
parent
52715f69
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
29 additions
and
2 deletions
+29
-2
Lib/test/seq_tests.py
Lib/test/seq_tests.py
+27
-0
Lib/test/test_richcmp.py
Lib/test/test_richcmp.py
+2
-2
No files found.
Lib/test/seq_tests.py
View file @
be3856dc
...
@@ -207,6 +207,33 @@ class CommonTest(unittest.TestCase):
...
@@ -207,6 +207,33 @@ class CommonTest(unittest.TestCase):
self
.
assertRaises
(
TypeError
,
u
.
__contains__
)
self
.
assertRaises
(
TypeError
,
u
.
__contains__
)
def
test_contains_fake
(
self
):
class
AllEq
:
# Sequences must use rich comparison against each item
# (unless "is" is true, or an earlier item answered)
# So instances of AllEq must be found in all non-empty sequences.
def
__eq__
(
self
,
other
):
return
True
def
__hash__
(
self
):
raise
NotImplemented
self
.
assert_
(
AllEq
()
not
in
self
.
type2test
([]))
self
.
assert_
(
AllEq
()
in
self
.
type2test
([
1
]))
def
test_contains_order
(
self
):
# Sequences must test in-order. If a rich comparison has side
# effects, these will be visible to tests against later members.
# In this test, the "side effect" is a short-circuiting raise.
class
DoNotTestEq
(
Exception
):
pass
class
StopCompares
:
def
__eq__
(
self
,
other
):
raise
DoNotTestEq
checkfirst
=
self
.
type2test
([
1
,
StopCompares
()])
self
.
assert_
(
1
in
checkfirst
)
checklast
=
self
.
type2test
([
StopCompares
(),
1
])
self
.
assertRaises
(
DoNotTestEq
,
checklast
.
__contains__
,
1
)
def
test_len
(
self
):
def
test_len
(
self
):
self
.
assertEqual
(
len
(
self
.
type2test
()),
0
)
self
.
assertEqual
(
len
(
self
.
type2test
()),
0
)
self
.
assertEqual
(
len
(
self
.
type2test
([])),
0
)
self
.
assertEqual
(
len
(
self
.
type2test
([])),
0
)
...
...
Lib/test/test_richcmp.py
View file @
be3856dc
...
@@ -259,8 +259,8 @@ class DictTest(unittest.TestCase):
...
@@ -259,8 +259,8 @@ class DictTest(unittest.TestCase):
def
test_dicts
(
self
):
def
test_dicts
(
self
):
# Verify that __eq__ and __ne__ work for dicts even if the keys and
# Verify that __eq__ and __ne__ work for dicts even if the keys and
# values don't support anything other than __eq__ and __ne__
. Complex
# values don't support anything other than __eq__ and __ne__
(and
# numbers are a fine example of that.
#
__hash__). Complex
numbers are a fine example of that.
import
random
import
random
imag1a
=
{}
imag1a
=
{}
for
i
in
range
(
50
):
for
i
in
range
(
50
):
...
...
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