mirror of
https://github.com/python/cpython.git
synced 2025-12-04 16:43:27 +00:00
Migrate remaining tests from UserDict.UserDict to collections.UserDict.
This commit is contained in:
parent
554c8b856c
commit
f80680d8cd
6 changed files with 14 additions and 14 deletions
|
|
@ -1,6 +1,6 @@
|
||||||
# tests common to dict and UserDict
|
# tests common to dict and UserDict
|
||||||
import unittest
|
import unittest
|
||||||
import UserDict
|
import collections
|
||||||
|
|
||||||
|
|
||||||
class BasicTestMappingProtocol(unittest.TestCase):
|
class BasicTestMappingProtocol(unittest.TestCase):
|
||||||
|
|
@ -438,11 +438,11 @@ class TestMappingProtocol(BasicTestMappingProtocol):
|
||||||
# self.assert_(type(dictlike.fromkeys('a')) is dictlike)
|
# self.assert_(type(dictlike.fromkeys('a')) is dictlike)
|
||||||
class mydict(self.type2test):
|
class mydict(self.type2test):
|
||||||
def __new__(cls):
|
def __new__(cls):
|
||||||
return UserDict.UserDict()
|
return collections.UserDict()
|
||||||
ud = mydict.fromkeys('ab')
|
ud = mydict.fromkeys('ab')
|
||||||
self.assertEqual(ud, {'a':None, 'b':None})
|
self.assertEqual(ud, {'a':None, 'b':None})
|
||||||
# FIXME: the following won't work with UserDict, because it's an old style class
|
# FIXME: the following won't work with UserDict, because it's an old style class
|
||||||
# self.assert_(isinstance(ud, UserDict.UserDict))
|
# self.assert_(isinstance(ud, collections.UserDict))
|
||||||
self.assertRaises(TypeError, dict.fromkeys)
|
self.assertRaises(TypeError, dict.fromkeys)
|
||||||
|
|
||||||
class Exc(Exception): pass
|
class Exc(Exception): pass
|
||||||
|
|
@ -574,10 +574,10 @@ class TestHashMappingProtocol(TestMappingProtocol):
|
||||||
TestMappingProtocol.test_fromkeys(self)
|
TestMappingProtocol.test_fromkeys(self)
|
||||||
class mydict(self.type2test):
|
class mydict(self.type2test):
|
||||||
def __new__(cls):
|
def __new__(cls):
|
||||||
return UserDict.UserDict()
|
return collections.UserDict()
|
||||||
ud = mydict.fromkeys('ab')
|
ud = mydict.fromkeys('ab')
|
||||||
self.assertEqual(ud, {'a':None, 'b':None})
|
self.assertEqual(ud, {'a':None, 'b':None})
|
||||||
self.assert_(isinstance(ud, UserDict.UserDict))
|
self.assert_(isinstance(ud, collections.UserDict))
|
||||||
|
|
||||||
def test_pop(self):
|
def test_pop(self):
|
||||||
TestMappingProtocol.test_pop(self)
|
TestMappingProtocol.test_pop(self)
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,7 @@ from test.test_support import fcmp, TESTFN, unlink, run_unittest, \
|
||||||
run_with_locale
|
run_with_locale
|
||||||
from operator import neg
|
from operator import neg
|
||||||
|
|
||||||
import sys, warnings, random, UserDict, io, rational
|
import sys, warnings, random, collections, io, rational
|
||||||
warnings.filterwarnings("ignore", "hex../oct.. of negative int",
|
warnings.filterwarnings("ignore", "hex../oct.. of negative int",
|
||||||
FutureWarning, __name__)
|
FutureWarning, __name__)
|
||||||
warnings.filterwarnings("ignore", "integer argument expected",
|
warnings.filterwarnings("ignore", "integer argument expected",
|
||||||
|
|
@ -400,7 +400,7 @@ class BuiltinTest(unittest.TestCase):
|
||||||
|
|
||||||
# Verify locals stores (used by list comps)
|
# Verify locals stores (used by list comps)
|
||||||
eval('[locals() for i in (2,3)]', g, d)
|
eval('[locals() for i in (2,3)]', g, d)
|
||||||
eval('[locals() for i in (2,3)]', g, UserDict.UserDict())
|
eval('[locals() for i in (2,3)]', g, collections.UserDict())
|
||||||
|
|
||||||
class SpreadSheet:
|
class SpreadSheet:
|
||||||
"Sample application showing nested, calculated lookups."
|
"Sample application showing nested, calculated lookups."
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1,11 @@
|
||||||
import ConfigParser
|
import ConfigParser
|
||||||
import io
|
import io
|
||||||
import unittest
|
import unittest
|
||||||
import UserDict
|
import collections
|
||||||
|
|
||||||
from test import test_support
|
from test import test_support
|
||||||
|
|
||||||
class SortedDict(UserDict.UserDict):
|
class SortedDict(collections.UserDict):
|
||||||
def items(self):
|
def items(self):
|
||||||
return sorted(self.data.items())
|
return sorted(self.data.items())
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
import unittest
|
import unittest
|
||||||
from test import test_support
|
from test import test_support
|
||||||
|
|
||||||
import sys, UserDict, random, string
|
import sys, collections, random, string
|
||||||
|
|
||||||
|
|
||||||
class DictTest(unittest.TestCase):
|
class DictTest(unittest.TestCase):
|
||||||
|
|
@ -209,10 +209,10 @@ class DictTest(unittest.TestCase):
|
||||||
self.assert_(type(dictlike().fromkeys('a')) is dictlike)
|
self.assert_(type(dictlike().fromkeys('a')) is dictlike)
|
||||||
class mydict(dict):
|
class mydict(dict):
|
||||||
def __new__(cls):
|
def __new__(cls):
|
||||||
return UserDict.UserDict()
|
return collections.UserDict()
|
||||||
ud = mydict.fromkeys('ab')
|
ud = mydict.fromkeys('ab')
|
||||||
self.assertEqual(ud, {'a':None, 'b':None})
|
self.assertEqual(ud, {'a':None, 'b':None})
|
||||||
self.assert_(isinstance(ud, UserDict.UserDict))
|
self.assert_(isinstance(ud, collections.UserDict))
|
||||||
self.assertRaises(TypeError, dict.fromkeys)
|
self.assertRaises(TypeError, dict.fromkeys)
|
||||||
|
|
||||||
class Exc(Exception): pass
|
class Exc(Exception): pass
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
from test.test_support import verify, verbose, TestFailed, sortdict
|
from test.test_support import verify, verbose, TestFailed, sortdict
|
||||||
from UserList import UserList
|
from UserList import UserList
|
||||||
from UserDict import UserDict
|
from collections import UserDict
|
||||||
|
|
||||||
def e(a, b):
|
def e(a, b):
|
||||||
print(a, b)
|
print(a, b)
|
||||||
|
|
|
||||||
|
|
@ -175,7 +175,7 @@ class ArbitraryFunctionAttrTest(FuncAttrsTest):
|
||||||
class FunctionDictsTest(FuncAttrsTest):
|
class FunctionDictsTest(FuncAttrsTest):
|
||||||
def test_setting_dict_to_invalid(self):
|
def test_setting_dict_to_invalid(self):
|
||||||
self.cannot_set_attr(self.b, '__dict__', None, TypeError)
|
self.cannot_set_attr(self.b, '__dict__', None, TypeError)
|
||||||
from UserDict import UserDict
|
from collections import UserDict
|
||||||
d = UserDict({'known_attr': 7})
|
d = UserDict({'known_attr': 7})
|
||||||
self.cannot_set_attr(self.fi.a.__func__, '__dict__', d, TypeError)
|
self.cannot_set_attr(self.fi.a.__func__, '__dict__', d, TypeError)
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue