Commit f80680d8 authored by Raymond Hettinger's avatar Raymond Hettinger

Migrate remaining tests from UserDict.UserDict to collections.UserDict.

parent 554c8b85
# tests common to dict and UserDict
import unittest
import UserDict
import collections
class BasicTestMappingProtocol(unittest.TestCase):
......@@ -438,11 +438,11 @@ class TestMappingProtocol(BasicTestMappingProtocol):
# self.assert_(type(dictlike.fromkeys('a')) is dictlike)
class mydict(self.type2test):
def __new__(cls):
return UserDict.UserDict()
return collections.UserDict()
ud = mydict.fromkeys('ab')
self.assertEqual(ud, {'a':None, 'b':None})
# 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)
class Exc(Exception): pass
......@@ -574,10 +574,10 @@ class TestHashMappingProtocol(TestMappingProtocol):
TestMappingProtocol.test_fromkeys(self)
class mydict(self.type2test):
def __new__(cls):
return UserDict.UserDict()
return collections.UserDict()
ud = mydict.fromkeys('ab')
self.assertEqual(ud, {'a':None, 'b':None})
self.assert_(isinstance(ud, UserDict.UserDict))
self.assert_(isinstance(ud, collections.UserDict))
def test_pop(self):
TestMappingProtocol.test_pop(self)
......
......@@ -5,7 +5,7 @@ from test.test_support import fcmp, TESTFN, unlink, run_unittest, \
run_with_locale
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",
FutureWarning, __name__)
warnings.filterwarnings("ignore", "integer argument expected",
......@@ -400,7 +400,7 @@ class BuiltinTest(unittest.TestCase):
# Verify locals stores (used by list comps)
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:
"Sample application showing nested, calculated lookups."
......
import ConfigParser
import io
import unittest
import UserDict
import collections
from test import test_support
class SortedDict(UserDict.UserDict):
class SortedDict(collections.UserDict):
def items(self):
return sorted(self.data.items())
......
import unittest
from test import test_support
import sys, UserDict, random, string
import sys, collections, random, string
class DictTest(unittest.TestCase):
......@@ -209,10 +209,10 @@ class DictTest(unittest.TestCase):
self.assert_(type(dictlike().fromkeys('a')) is dictlike)
class mydict(dict):
def __new__(cls):
return UserDict.UserDict()
return collections.UserDict()
ud = mydict.fromkeys('ab')
self.assertEqual(ud, {'a':None, 'b':None})
self.assert_(isinstance(ud, UserDict.UserDict))
self.assert_(isinstance(ud, collections.UserDict))
self.assertRaises(TypeError, dict.fromkeys)
class Exc(Exception): pass
......
from test.test_support import verify, verbose, TestFailed, sortdict
from UserList import UserList
from UserDict import UserDict
from collections import UserDict
def e(a, b):
print(a, b)
......
......@@ -175,7 +175,7 @@ class ArbitraryFunctionAttrTest(FuncAttrsTest):
class FunctionDictsTest(FuncAttrsTest):
def test_setting_dict_to_invalid(self):
self.cannot_set_attr(self.b, '__dict__', None, TypeError)
from UserDict import UserDict
from collections import UserDict
d = UserDict({'known_attr': 7})
self.cannot_set_attr(self.fi.a.__func__, '__dict__', d, TypeError)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment