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
07f2436f
Commit
07f2436f
authored
Feb 11, 2007
by
Guido van Rossum
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Nailed test_weakref.py. Pfew, messy!
parent
9afbb4e3
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
42 additions
and
39 deletions
+42
-39
Lib/pprint.py
Lib/pprint.py
+1
-2
Lib/test/mapping_tests.py
Lib/test/mapping_tests.py
+34
-30
Lib/test/test_weakref.py
Lib/test/test_weakref.py
+3
-3
Lib/weakref.py
Lib/weakref.py
+4
-4
No files found.
Lib/pprint.py
View file @
07f2436f
...
...
@@ -141,8 +141,7 @@ class PrettyPrinter:
if
length
:
context
[
objid
]
=
1
indent
=
indent
+
self
.
_indent_per_level
items
=
object
.
items
()
items
.
sort
()
items
=
sorted
(
object
.
items
())
key
,
ent
=
items
[
0
]
rep
=
self
.
_repr
(
key
,
context
,
level
)
write
(
rep
)
...
...
Lib/test/mapping_tests.py
View file @
07f2436f
...
...
@@ -49,7 +49,7 @@ class BasicTestMappingProtocol(unittest.TestCase):
#Indexing
for
key
,
value
in
self
.
reference
.
items
():
self
.
assertEqual
(
d
[
key
],
value
)
knownkey
=
self
.
other
.
keys
(
)[
0
]
knownkey
=
list
(
self
.
other
.
keys
()
)[
0
]
self
.
failUnlessRaises
(
KeyError
,
lambda
:
d
[
knownkey
])
#len
self
.
assertEqual
(
len
(
p
),
0
)
...
...
@@ -73,13 +73,16 @@ class BasicTestMappingProtocol(unittest.TestCase):
self
.
assert_
(
hasattr
(
iter
,
'__iter__'
))
x
=
list
(
iter
)
self
.
assert_
(
set
(
x
)
==
set
(
lst
)
==
set
(
ref
))
check_iterandlist
(
d
.
keys
(),
d
.
keys
(),
self
.
reference
.
keys
())
check_iterandlist
(
iter
(
d
),
d
.
keys
(),
self
.
reference
.
keys
())
check_iterandlist
(
d
.
values
(),
d
.
values
(),
self
.
reference
.
values
())
check_iterandlist
(
d
.
items
(),
d
.
items
(),
self
.
reference
.
items
())
check_iterandlist
(
iter
(
d
.
keys
()),
list
(
d
.
keys
()),
self
.
reference
.
keys
())
check_iterandlist
(
iter
(
d
),
list
(
d
.
keys
()),
self
.
reference
.
keys
())
check_iterandlist
(
iter
(
d
.
values
()),
list
(
d
.
values
()),
self
.
reference
.
values
())
check_iterandlist
(
iter
(
d
.
items
()),
list
(
d
.
items
()),
self
.
reference
.
items
())
#get
key
,
value
=
d
.
items
(
).
next
()
knownkey
,
knownvalue
=
self
.
other
.
items
(
).
next
()
key
,
value
=
iter
(
d
.
items
()
).
next
()
knownkey
,
knownvalue
=
iter
(
self
.
other
.
items
()
).
next
()
self
.
assertEqual
(
d
.
get
(
key
,
knownvalue
),
value
)
self
.
assertEqual
(
d
.
get
(
knownkey
,
knownvalue
),
knownvalue
)
self
.
failIf
(
knownkey
in
d
)
...
...
@@ -104,8 +107,8 @@ class BasicTestMappingProtocol(unittest.TestCase):
self
.
assertEqual
(
dict
(
p
),
self
.
reference
)
d
=
self
.
_full_mapping
(
self
.
reference
)
#setdefault
key
,
value
=
d
.
items
(
).
next
()
knownkey
,
knownvalue
=
self
.
other
.
items
(
).
next
()
key
,
value
=
iter
(
d
.
items
()
).
next
()
knownkey
,
knownvalue
=
iter
(
self
.
other
.
items
()
).
next
()
self
.
assertEqual
(
d
.
setdefault
(
key
,
knownvalue
),
value
)
self
.
assertEqual
(
d
[
key
],
value
)
self
.
assertEqual
(
d
.
setdefault
(
knownkey
,
knownvalue
),
knownvalue
)
...
...
@@ -137,21 +140,21 @@ class BasicTestMappingProtocol(unittest.TestCase):
def
test_keys
(
self
):
d
=
self
.
_empty_mapping
()
self
.
assertEqual
(
d
.
keys
(
),
[])
self
.
assertEqual
(
list
(
d
.
keys
()
),
[])
d
=
self
.
reference
self
.
assert_
(
self
.
inmapping
.
keys
(
)[
0
]
in
d
.
keys
())
self
.
assert_
(
self
.
other
.
keys
(
)[
0
]
not
in
d
.
keys
())
self
.
assert_
(
list
(
self
.
inmapping
.
keys
()
)[
0
]
in
d
.
keys
())
self
.
assert_
(
list
(
self
.
other
.
keys
()
)[
0
]
not
in
d
.
keys
())
self
.
assertRaises
(
TypeError
,
d
.
keys
,
None
)
def
test_values
(
self
):
d
=
self
.
_empty_mapping
()
self
.
assertEqual
(
d
.
values
(
),
[])
self
.
assertEqual
(
list
(
d
.
values
()
),
[])
self
.
assertRaises
(
TypeError
,
d
.
values
,
None
)
def
test_items
(
self
):
d
=
self
.
_empty_mapping
()
self
.
assertEqual
(
d
.
items
(
),
[])
self
.
assertEqual
(
list
(
d
.
items
()
),
[])
self
.
assertRaises
(
TypeError
,
d
.
items
,
None
)
...
...
@@ -161,7 +164,8 @@ class BasicTestMappingProtocol(unittest.TestCase):
def
test_getitem
(
self
):
d
=
self
.
reference
self
.
assertEqual
(
d
[
self
.
inmapping
.
keys
()[
0
]],
self
.
inmapping
.
values
()[
0
])
self
.
assertEqual
(
d
[
list
(
self
.
inmapping
.
keys
())[
0
]],
list
(
self
.
inmapping
.
values
())[
0
])
self
.
assertRaises
(
TypeError
,
d
.
__getitem__
)
...
...
@@ -169,7 +173,7 @@ class BasicTestMappingProtocol(unittest.TestCase):
# mapping argument
d
=
self
.
_empty_mapping
()
d
.
update
(
self
.
other
)
self
.
assertEqual
(
d
.
items
(),
self
.
other
.
items
(
))
self
.
assertEqual
(
list
(
d
.
items
()),
list
(
self
.
other
.
items
()
))
# No argument
d
=
self
.
_empty_mapping
()
...
...
@@ -179,12 +183,12 @@ class BasicTestMappingProtocol(unittest.TestCase):
# item sequence
d
=
self
.
_empty_mapping
()
d
.
update
(
self
.
other
.
items
())
self
.
assertEqual
(
d
.
items
(),
self
.
other
.
items
(
))
self
.
assertEqual
(
list
(
d
.
items
()),
list
(
self
.
other
.
items
()
))
# Iterator
d
=
self
.
_empty_mapping
()
d
.
update
(
self
.
other
.
items
())
self
.
assertEqual
(
d
.
items
(),
self
.
other
.
items
(
))
self
.
assertEqual
(
list
(
d
.
items
()),
list
(
self
.
other
.
items
()
))
# FIXME: Doesn't work with UserDict
# self.assertRaises((TypeError, AttributeError), d.update, None)
...
...
@@ -200,10 +204,8 @@ class BasicTestMappingProtocol(unittest.TestCase):
return
self
.
d
[
i
]
d
.
clear
()
d
.
update
(
SimpleUserDict
())
i1
=
d
.
items
()
i2
=
self
.
reference
.
items
()
i1
.
sort
()
i2
.
sort
()
i1
=
sorted
(
d
.
items
())
i2
=
sorted
(
self
.
reference
.
items
())
self
.
assertEqual
(
i1
,
i2
)
class
Exc
(
Exception
):
pass
...
...
@@ -266,13 +268,15 @@ class BasicTestMappingProtocol(unittest.TestCase):
def
test_get
(
self
):
d
=
self
.
_empty_mapping
()
self
.
assert_
(
d
.
get
(
self
.
other
.
keys
(
)[
0
])
is
None
)
self
.
assertEqual
(
d
.
get
(
self
.
other
.
keys
(
)[
0
],
3
),
3
)
self
.
assert_
(
d
.
get
(
list
(
self
.
other
.
keys
()
)[
0
])
is
None
)
self
.
assertEqual
(
d
.
get
(
list
(
self
.
other
.
keys
()
)[
0
],
3
),
3
)
d
=
self
.
reference
self
.
assert_
(
d
.
get
(
self
.
other
.
keys
()[
0
])
is
None
)
self
.
assertEqual
(
d
.
get
(
self
.
other
.
keys
()[
0
],
3
),
3
)
self
.
assertEqual
(
d
.
get
(
self
.
inmapping
.
keys
()[
0
]),
self
.
inmapping
.
values
()[
0
])
self
.
assertEqual
(
d
.
get
(
self
.
inmapping
.
keys
()[
0
],
3
),
self
.
inmapping
.
values
()[
0
])
self
.
assert_
(
d
.
get
(
list
(
self
.
other
.
keys
())[
0
])
is
None
)
self
.
assertEqual
(
d
.
get
(
list
(
self
.
other
.
keys
())[
0
],
3
),
3
)
self
.
assertEqual
(
d
.
get
(
list
(
self
.
inmapping
.
keys
())[
0
]),
list
(
self
.
inmapping
.
values
())[
0
])
self
.
assertEqual
(
d
.
get
(
list
(
self
.
inmapping
.
keys
())[
0
],
3
),
list
(
self
.
inmapping
.
values
())[
0
])
self
.
assertRaises
(
TypeError
,
d
.
get
)
self
.
assertRaises
(
TypeError
,
d
.
get
,
None
,
None
,
None
)
...
...
@@ -287,9 +291,9 @@ class BasicTestMappingProtocol(unittest.TestCase):
def
test_pop
(
self
):
d
=
self
.
_empty_mapping
()
k
,
v
=
self
.
inmapping
.
items
(
)[
0
]
k
,
v
=
list
(
self
.
inmapping
.
items
()
)[
0
]
d
[
k
]
=
v
self
.
assertRaises
(
KeyError
,
d
.
pop
,
self
.
other
.
keys
(
)[
0
])
self
.
assertRaises
(
KeyError
,
d
.
pop
,
list
(
self
.
other
.
keys
()
)[
0
])
self
.
assertEqual
(
d
.
pop
(
k
),
v
)
self
.
assertEqual
(
len
(
d
),
0
)
...
...
Lib/test/test_weakref.py
View file @
07f2436f
...
...
@@ -844,19 +844,19 @@ class MappingTestCase(TestBase):
self
.
assert_
(
len
(
items
)
==
0
,
"iteritems() did not touch all items"
)
# key iterator, via __iter__():
keys
=
dict
.
keys
(
)
keys
=
list
(
dict
.
keys
()
)
for
k
in
dict
:
keys
.
remove
(
k
)
self
.
assert_
(
len
(
keys
)
==
0
,
"__iter__() did not touch all keys"
)
# key iterator, via iterkeys():
keys
=
dict
.
keys
(
)
keys
=
list
(
dict
.
keys
()
)
for
k
in
dict
.
keys
():
keys
.
remove
(
k
)
self
.
assert_
(
len
(
keys
)
==
0
,
"iterkeys() did not touch all keys"
)
# value iterator:
values
=
dict
.
values
(
)
values
=
list
(
dict
.
values
()
)
for
v
in
dict
.
values
():
values
.
remove
(
v
)
self
.
assert_
(
len
(
values
)
==
0
,
...
...
Lib/weakref.py
View file @
07f2436f
...
...
@@ -106,10 +106,10 @@ class WeakValueDictionary(UserDict.UserDict):
yield
wr
.
key
,
value
def
iterkeys
(
self
):
return
self
.
data
.
keys
(
)
return
iter
(
self
.
data
.
keys
()
)
def
__iter__
(
self
):
return
self
.
data
.
keys
(
)
return
iter
(
self
.
data
.
keys
()
)
def
itervaluerefs
(
self
):
"""Return an iterator that yields the weak references to the values.
...
...
@@ -292,10 +292,10 @@ class WeakKeyDictionary(UserDict.UserDict):
yield
obj
def
__iter__
(
self
):
return
self
.
keys
(
)
return
iter
(
self
.
keys
()
)
def
itervalues
(
self
):
return
self
.
data
.
values
(
)
return
iter
(
self
.
data
.
values
()
)
def
keyrefs
(
self
):
"""Return a list of weak references to the keys.
...
...
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