[Python-checkins] python/dist/src/Lib/test test_types.py,1.40,1.41

rhettinger@users.sourceforge.net rhettinger@users.sourceforge.net
Tue, 26 Nov 2002 23:29:36 -0800


Update of /cvsroot/python/python/dist/src/Lib/test
In directory sc8-pr-cvs1:/tmp/cvs-serv24449a/Lib/test

Modified Files:
	test_types.py 
Log Message:
SF Patch 643443.  Added dict.fromkeys(iterable, value=None), a class
method for constructing new dictionaries from sequences of keys.



Index: test_types.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/test/test_types.py,v
retrieving revision 1.40
retrieving revision 1.41
diff -C2 -d -r1.40 -r1.41
*** test_types.py	19 Nov 2002 20:49:13 -0000	1.40
--- test_types.py	27 Nov 2002 07:29:33 -0000	1.41
***************
*** 531,534 ****
--- 531,562 ----
  except ValueError: pass
  else: raise TestFailed, 'dict.update(), __getitem__ expected ValueError'
+ # dict.fromkeys()
+ if dict.fromkeys('abc') != {'a':None, 'b':None, 'c':None}:
+     raise TestFailed, 'dict.fromkeys did not work as a class method'
+ d = {}
+ if d.fromkeys('abc') is d:
+     raise TestFailed, 'dict.fromkeys did not return a new dict'
+ if d.fromkeys('abc') != {'a':None, 'b':None, 'c':None}:
+     raise TestFailed, 'dict.fromkeys failed with default value'
+ if d.fromkeys((4,5),0) != {4:0, 5:0}:
+     raise TestFailed, 'dict.fromkeys failed with specified value'
+ if d.fromkeys([]) != {}:
+     raise TestFailed, 'dict.fromkeys failed with null sequence'
+ def g():
+     yield 1
+ if d.fromkeys(g()) != {1:None}:
+     raise TestFailed, 'dict.fromkeys failed with a generator'
+ try: {}.fromkeys(3)
+ except TypeError: pass
+ else: raise TestFailed, 'dict.fromkeys failed to raise TypeError'
+ class dictlike(dict): pass
+ if dictlike.fromkeys('a') != {'a':None}:
+     raise TestFailed, 'dictsubclass.fromkeys did not inherit'
+ if dictlike().fromkeys('a') != {'a':None}:
+     raise TestFailed, 'dictsubclass.fromkeys did not inherit'
+ if type(dictlike.fromkeys('a')) is not dictlike:
+     raise TestFailed, 'dictsubclass.fromkeys created wrong type'
+ if type(dictlike().fromkeys('a')) is not dictlike:
+     raise TestFailed, 'dictsubclass.fromkeys created wrong type'
  # dict.copy()
  d = {1:1, 2:2, 3:3}