]> granicus.if.org Git - python/commitdiff
SF patch #523169, by Samuele Pedroni.
authorGuido van Rossum <guido@python.org>
Tue, 26 Feb 2002 22:39:23 +0000 (22:39 +0000)
committerGuido van Rossum <guido@python.org>
Tue, 26 Feb 2002 22:39:23 +0000 (22:39 +0000)
There were never tests for the fact that list() always returns a *new*
list object, even when the argument is a list, while tuple() may
return a reference to the argument when it is a tuple.  Now there are.

Lib/test/output/test_builtin
Lib/test/test_b1.py
Lib/test/test_b2.py

index 1c3b69c8380f3741c1be378e7a2985ad6f827851..6c1b9aa81cdc5859b7e0f0395e35073ca6521c60 100644 (file)
@@ -26,6 +26,7 @@ int
 isinstance
 issubclass
 len
+list
 long
 map
 max
index 17f041101e8c33066c807af893260d8d552bbb2e..8d47abc73706c69ac911fcb2aba6629f70e2db94 100644 (file)
@@ -491,6 +491,16 @@ if len([1, 2, 3, 4]) != 4: raise TestFailed, 'len([1, 2, 3, 4])'
 if len({}) != 0: raise TestFailed, 'len({})'
 if len({'a':1, 'b': 2}) != 2: raise TestFailed, 'len({\'a\':1, \'b\': 2})'
 
+print 'list'
+if list([]) != []: raise TestFailed, 'list([])'
+l0_3 = [0, 1, 2, 3]
+l0_3_bis = list(l0_3)
+if l0_3 != l0_3_bis or l0_3 is l0_3_bis: raise TestFailed, 'list([0, 1, 2, 3])'
+if list(()) != []: raise TestFailed, 'list(())'
+if list((0, 1, 2, 3)) != [0, 1, 2, 3]: raise TestFailed, 'list((0, 1, 2, 3))'
+if list('') != []: raise TestFailed, 'list('')'
+if list('spam') != ['s', 'p', 'a', 'm']: raise TestFailed, "list('spam')"
+
 print 'long'
 if long(314) != 314L: raise TestFailed, 'long(314)'
 if long(3.14) != 3L: raise TestFailed, 'long(3.14)'
index c5af1b31f5a2372af80ecd8608a544f0242d5909..b9303801ab168b7549e6ef13e4914be9e9ac05ab 100644 (file)
@@ -253,7 +253,9 @@ if str({}) != '{}': raise TestFailed, 'str({})'
 
 print 'tuple'
 if tuple(()) != (): raise TestFailed, 'tuple(())'
-if tuple((0, 1, 2, 3)) != (0, 1, 2, 3): raise TestFailed, 'tuple((0, 1, 2, 3))'
+t0_3 = (0, 1, 2, 3)
+t0_3_bis = tuple(t0_3)
+if t0_3 is not t0_3_bis: raise TestFailed, 'tuple((0, 1, 2, 3))'
 if tuple([]) != (): raise TestFailed, 'tuple([])'
 if tuple([0, 1, 2, 3]) != (0, 1, 2, 3): raise TestFailed, 'tuple([0, 1, 2, 3])'
 if tuple('') != (): raise TestFailed, 'tuple('')'