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
118f931d
Commit
118f931d
authored
20 years ago
by
Walter Dörwald
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Rename class attribute containing the class to be tested, so the name is the
same as for the string and sequence tests.
parent
b4541c26
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
16 additions
and
16 deletions
+16
-16
Lib/test/mapping_tests.py
Lib/test/mapping_tests.py
+10
-10
Lib/test/test_os.py
Lib/test/test_os.py
+1
-1
Lib/test/test_shelve.py
Lib/test/test_shelve.py
+1
-1
Lib/test/test_userdict.py
Lib/test/test_userdict.py
+2
-2
Lib/test/test_weakref.py
Lib/test/test_weakref.py
+2
-2
No files found.
Lib/test/mapping_tests.py
View file @
118f931d
...
...
@@ -9,7 +9,7 @@ class BasicTestMappingProtocol(unittest.TestCase):
# Functions that can be useful to override to adapt to dictionary
# semantics
_tested_class
=
None
# which class is being tested (overwrite in subclasses)
type2test
=
None
# which class is being tested (overwrite in subclasses)
def
_reference
(
self
):
"""Return a dictionary of values which are invariant by storage
...
...
@@ -17,7 +17,7 @@ class BasicTestMappingProtocol(unittest.TestCase):
return
{
1
:
2
,
"key1"
:
"value1"
,
"key2"
:(
1
,
2
,
3
)}
def
_empty_mapping
(
self
):
"""Return an empty mapping object"""
return
self
.
_tested_class
()
return
self
.
type2test
()
def
_full_mapping
(
self
,
data
):
"""Return a mapping object with the value contained in data
dictionary"""
...
...
@@ -303,7 +303,7 @@ class TestMappingProtocol(BasicTestMappingProtocol):
def
test_constructor
(
self
):
BasicTestMappingProtocol
.
test_constructor
(
self
)
self
.
assert_
(
self
.
_empty_mapping
()
is
not
self
.
_empty_mapping
())
self
.
assertEqual
(
self
.
_tested_class
(
x
=
1
,
y
=
2
),
{
"x"
:
1
,
"y"
:
2
})
self
.
assertEqual
(
self
.
type2test
(
x
=
1
,
y
=
2
),
{
"x"
:
1
,
"y"
:
2
})
def
test_bool
(
self
):
BasicTestMappingProtocol
.
test_bool
(
self
)
...
...
@@ -427,7 +427,7 @@ class TestMappingProtocol(BasicTestMappingProtocol):
self
.
assertEqual
(
d
,
{
1
:
1
,
2
:
2
,
3
:
3
})
def
test_fromkeys
(
self
):
self
.
assertEqual
(
self
.
_tested_class
.
fromkeys
(
'abc'
),
{
'a'
:
None
,
'b'
:
None
,
'c'
:
None
})
self
.
assertEqual
(
self
.
type2test
.
fromkeys
(
'abc'
),
{
'a'
:
None
,
'b'
:
None
,
'c'
:
None
})
d
=
self
.
_empty_mapping
()
self
.
assert_
(
not
(
d
.
fromkeys
(
'abc'
)
is
d
))
self
.
assertEqual
(
d
.
fromkeys
(
'abc'
),
{
'a'
:
None
,
'b'
:
None
,
'c'
:
None
})
...
...
@@ -437,14 +437,14 @@ class TestMappingProtocol(BasicTestMappingProtocol):
yield
1
self
.
assertEqual
(
d
.
fromkeys
(
g
()),
{
1
:
None
})
self
.
assertRaises
(
TypeError
,
{}.
fromkeys
,
3
)
class
dictlike
(
self
.
_tested_class
):
pass
class
dictlike
(
self
.
type2test
):
pass
self
.
assertEqual
(
dictlike
.
fromkeys
(
'a'
),
{
'a'
:
None
})
self
.
assertEqual
(
dictlike
().
fromkeys
(
'a'
),
{
'a'
:
None
})
self
.
assert_
(
dictlike
.
fromkeys
(
'a'
).
__class__
is
dictlike
)
self
.
assert_
(
dictlike
().
fromkeys
(
'a'
).
__class__
is
dictlike
)
# FIXME: the following won't work with UserDict, because it's an old style class
# self.assert_(type(dictlike.fromkeys('a')) is dictlike)
class
mydict
(
self
.
_tested_class
):
class
mydict
(
self
.
type2test
):
def
__new__
(
cls
):
return
UserDict
.
UserDict
()
ud
=
mydict
.
fromkeys
(
'ab'
)
...
...
@@ -455,7 +455,7 @@ class TestMappingProtocol(BasicTestMappingProtocol):
class
Exc
(
Exception
):
pass
class
baddict1
(
self
.
_tested_class
):
class
baddict1
(
self
.
type2test
):
def
__init__
(
self
):
raise
Exc
()
...
...
@@ -467,9 +467,9 @@ class TestMappingProtocol(BasicTestMappingProtocol):
def
next
(
self
):
raise
Exc
()
self
.
assertRaises
(
Exc
,
self
.
_tested_class
.
fromkeys
,
BadSeq
())
self
.
assertRaises
(
Exc
,
self
.
type2test
.
fromkeys
,
BadSeq
())
class
baddict2
(
self
.
_tested_class
):
class
baddict2
(
self
.
type2test
):
def
__setitem__
(
self
,
key
,
value
):
raise
Exc
()
...
...
@@ -578,7 +578,7 @@ class TestHashMappingProtocol(TestMappingProtocol):
def
test_fromkeys
(
self
):
TestMappingProtocol
.
test_fromkeys
(
self
)
class
mydict
(
self
.
_tested_class
):
class
mydict
(
self
.
type2test
):
def
__new__
(
cls
):
return
UserDict
.
UserDict
()
ud
=
mydict
.
fromkeys
(
'ab'
)
...
...
This diff is collapsed.
Click to expand it.
Lib/test/test_os.py
View file @
118f931d
...
...
@@ -209,7 +209,7 @@ from test import mapping_tests
class
EnvironTests
(
mapping_tests
.
BasicTestMappingProtocol
):
"""check that os.environ object conform to mapping protocol"""
_tested_class
=
None
type2test
=
None
def
_reference
(
self
):
return
{
"KEY1"
:
"VALUE1"
,
"KEY2"
:
"VALUE2"
,
"KEY3"
:
"VALUE3"
}
def
_empty_mapping
(
self
):
...
...
This diff is collapsed.
Click to expand it.
Lib/test/test_shelve.py
View file @
118f931d
...
...
@@ -82,7 +82,7 @@ class TestShelveBase(mapping_tests.BasicTestMappingProtocol):
def
__init__
(
self
,
*
args
,
**
kw
):
self
.
_db
=
[]
mapping_tests
.
BasicTestMappingProtocol
.
__init__
(
self
,
*
args
,
**
kw
)
_tested_class
=
shelve
.
Shelf
type2test
=
shelve
.
Shelf
def
_reference
(
self
):
return
{
"key1"
:
"value1"
,
"key2"
:
2
,
"key3"
:(
1
,
2
,
3
)}
def
_empty_mapping
(
self
):
...
...
This diff is collapsed.
Click to expand it.
Lib/test/test_userdict.py
View file @
118f931d
...
...
@@ -12,7 +12,7 @@ d4 = {"one": None, "two": None}
d5
=
{
"one"
:
1
,
"two"
:
1
}
class
UserDictTest
(
mapping_tests
.
TestHashMappingProtocol
):
_tested_class
=
UserDict
.
IterableUserDict
type2test
=
UserDict
.
IterableUserDict
def
test_all
(
self
):
# Test constructors
...
...
@@ -199,7 +199,7 @@ class SeqDict(UserDict.DictMixin):
fromkeys
=
classmethod
(
fromkeys
)
class
UserDictMixinTest
(
mapping_tests
.
TestMappingProtocol
):
_tested_class
=
SeqDict
type2test
=
SeqDict
def
test_all
(
self
):
## Setup test and verify working of the test class
...
...
This diff is collapsed.
Click to expand it.
Lib/test/test_weakref.py
View file @
118f931d
...
...
@@ -917,14 +917,14 @@ from test import mapping_tests
class
WeakValueDictionaryTestCase
(
mapping_tests
.
BasicTestMappingProtocol
):
"""Check that WeakValueDictionary conforms to the mapping protocol"""
__ref
=
{
"key1"
:
Object
(
1
),
"key2"
:
Object
(
2
),
"key3"
:
Object
(
3
)}
_tested_class
=
weakref
.
WeakValueDictionary
type2test
=
weakref
.
WeakValueDictionary
def
_reference
(
self
):
return
self
.
__ref
.
copy
()
class
WeakKeyDictionaryTestCase
(
mapping_tests
.
BasicTestMappingProtocol
):
"""Check that WeakKeyDictionary conforms to the mapping protocol"""
__ref
=
{
Object
(
"key1"
):
1
,
Object
(
"key2"
):
2
,
Object
(
"key3"
):
3
}
_tested_class
=
weakref
.
WeakKeyDictionary
type2test
=
weakref
.
WeakKeyDictionary
def
_reference
(
self
):
return
self
.
__ref
.
copy
()
...
...
This diff is collapsed.
Click to expand it.
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