]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
backport gvanrossum's checkin of
authorMichael W. Hudson <mwh@python.net>
Thu, 28 Feb 2002 10:14:24 +0000 (10:14 +0000)
committerMichael W. Hudson <mwh@python.net>
Thu, 28 Feb 2002 10:14:24 +0000 (10:14 +0000)
    revision 1.44 of test_b1.py
    revision 1.31 of test_b2.py

SF patch #523169, by Samuele Pedroni.

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/test_b1.py
Lib/test/test_b2.py

index f2d0c24d4cc56edc9cab10abe609235e73533764..275c6742b6001ccefc1a8b71d8d67f7f9aee40fc 100644 (file)
@@ -476,6 +476,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 ca26a7718408c4df68b6b2368f16a93888af1503..edd44aafa6edad454c1fd0150fd8db821413250d 100644 (file)
@@ -233,7 +233,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('')'