[Python-checkins] python/dist/src/Lib/test test_builtin.py, 1.26,
1.27 test_descrtut.py, 1.18, 1.19 test_itertools.py, 1.26,
1.27 test_operator.py, 1.12, 1.13 test_set.py, 1.7,
1.8 test_sort.py, 1.10, 1.11
rhettinger at users.sourceforge.net
rhettinger at users.sourceforge.net
Wed Dec 17 15:43:35 EST 2003
Update of /cvsroot/python/python/dist/src/Lib/test
In directory sc8-pr-cvs1:/tmp/cvs-serv9388/Lib/test
Modified Files:
test_builtin.py test_descrtut.py test_itertools.py
test_operator.py test_set.py test_sort.py
Log Message:
Guido grants a Christmas wish:
sorted() becomes a regular function instead of a classmethod.
Index: test_builtin.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/test/test_builtin.py,v
retrieving revision 1.26
retrieving revision 1.27
diff -C2 -d -r1.26 -r1.27
*** test_builtin.py 29 Nov 2003 23:52:12 -0000 1.26
--- test_builtin.py 17 Dec 2003 20:43:32 -0000 1.27
***************
*** 4,8 ****
from test.test_support import fcmp, have_unicode, TESTFN, unlink
! import sys, warnings, cStringIO
warnings.filterwarnings("ignore", "hex../oct.. of negative int",
FutureWarning, __name__)
--- 4,8 ----
from test.test_support import fcmp, have_unicode, TESTFN, unlink
! import sys, warnings, cStringIO, random
warnings.filterwarnings("ignore", "hex../oct.. of negative int",
FutureWarning, __name__)
***************
*** 1154,1159 ****
self.assertRaises(ValueError, zip, BadSeq(), BadSeq())
def test_main():
! test.test_support.run_unittest(BuiltinTest)
if __name__ == "__main__":
--- 1154,1192 ----
self.assertRaises(ValueError, zip, BadSeq(), BadSeq())
+ class TestSorted(unittest.TestCase):
+
+ def test_basic(self):
+ data = range(100)
+ copy = data[:]
+ random.shuffle(copy)
+ self.assertEqual(data, sorted(copy))
+ self.assertNotEqual(data, copy)
+
+ data.reverse()
+ random.shuffle(copy)
+ self.assertEqual(data, sorted(copy, cmp=lambda x, y: cmp(y,x)))
+ self.assertNotEqual(data, copy)
+ random.shuffle(copy)
+ self.assertEqual(data, sorted(copy, key=lambda x: -x))
+ self.assertNotEqual(data, copy)
+ random.shuffle(copy)
+ self.assertEqual(data, sorted(copy, reverse=1))
+ self.assertNotEqual(data, copy)
+
+ def test_inputtypes(self):
+ s = 'abracadabra'
+ for T in [unicode, list, tuple]:
+ self.assertEqual(sorted(s), sorted(T(s)))
+
+ s = ''.join(dict.fromkeys(s).keys()) # unique letters only
+ for T in [unicode, set, frozenset, list, tuple, dict.fromkeys]:
+ self.assertEqual(sorted(s), sorted(T(s)))
+
+ def test_baddecorator(self):
+ data = 'The quick Brown fox Jumped over The lazy Dog'.split()
+ self.assertRaises(TypeError, sorted, data, None, lambda x,y: 0)
+
def test_main():
! test.test_support.run_unittest(BuiltinTest, TestSorted)
if __name__ == "__main__":
Index: test_descrtut.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/test/test_descrtut.py,v
retrieving revision 1.18
retrieving revision 1.19
diff -C2 -d -r1.18 -r1.19
*** test_descrtut.py 8 Nov 2003 12:39:53 -0000 1.18
--- test_descrtut.py 17 Dec 2003 20:43:32 -0000 1.19
***************
*** 227,232 ****
'remove',
'reverse',
! 'sort',
! 'sorted']
The new introspection API gives more information than the old one: in
--- 227,231 ----
'remove',
'reverse',
! 'sort']
The new introspection API gives more information than the old one: in
Index: test_itertools.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/test/test_itertools.py,v
retrieving revision 1.26
retrieving revision 1.27
diff -C2 -d -r1.26 -r1.27
*** test_itertools.py 6 Dec 2003 16:23:06 -0000 1.26
--- test_itertools.py 17 Dec 2003 20:43:32 -0000 1.27
***************
*** 98,111 ****
s = 'abracadabra'
# sort s | uniq
! r = [k for k, g in groupby(list.sorted(s))]
self.assertEqual(r, ['a', 'b', 'c', 'd', 'r'])
# sort s | uniq -d
! r = [k for k, g in groupby(list.sorted(s)) if list(islice(g,1,2))]
self.assertEqual(r, ['a', 'b', 'r'])
# sort s | uniq -c
! r = [(len(list(g)), k) for k, g in groupby(list.sorted(s))]
self.assertEqual(r, [(5, 'a'), (2, 'b'), (1, 'c'), (1, 'd'), (2, 'r')])
# sort s | uniq -c | sort -rn | head -3
! r = list.sorted([(len(list(g)) , k) for k, g in groupby(list.sorted(s))], reverse=True)[:3]
self.assertEqual(r, [(5, 'a'), (2, 'r'), (2, 'b')])
--- 98,111 ----
s = 'abracadabra'
# sort s | uniq
! r = [k for k, g in groupby(sorted(s))]
self.assertEqual(r, ['a', 'b', 'c', 'd', 'r'])
# sort s | uniq -d
! r = [k for k, g in groupby(sorted(s)) if list(islice(g,1,2))]
self.assertEqual(r, ['a', 'b', 'r'])
# sort s | uniq -c
! r = [(len(list(g)), k) for k, g in groupby(sorted(s))]
self.assertEqual(r, [(5, 'a'), (2, 'b'), (1, 'c'), (1, 'd'), (2, 'r')])
# sort s | uniq -c | sort -rn | head -3
! r = sorted([(len(list(g)) , k) for k, g in groupby(sorted(s))], reverse=True)[:3]
self.assertEqual(r, [(5, 'a'), (2, 'r'), (2, 'b')])
***************
*** 670,674 ****
>>> from operator import itemgetter
>>> d = dict(a=1, b=2, c=1, d=2, e=1, f=2, g=3)
! >>> di = list.sorted(d.iteritems(), key=itemgetter(1))
>>> for k, g in groupby(di, itemgetter(1)):
... print k, map(itemgetter(0), g)
--- 670,674 ----
>>> from operator import itemgetter
>>> d = dict(a=1, b=2, c=1, d=2, e=1, f=2, g=3)
! >>> di = sorted(d.iteritems(), key=itemgetter(1))
>>> for k, g in groupby(di, itemgetter(1)):
... print k, map(itemgetter(0), g)
Index: test_operator.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/test/test_operator.py,v
retrieving revision 1.12
retrieving revision 1.13
diff -C2 -d -r1.12 -r1.13
*** test_operator.py 1 Dec 2003 13:18:39 -0000 1.12
--- test_operator.py 17 Dec 2003 20:43:32 -0000 1.13
***************
*** 264,268 ****
getcount = operator.itemgetter(1)
self.assertEqual(map(getcount, inventory), [3, 2, 5, 1])
! self.assertEqual(list.sorted(inventory, key=getcount),
[('orange', 1), ('banana', 2), ('apple', 3), ('pear', 5)])
--- 264,268 ----
getcount = operator.itemgetter(1)
self.assertEqual(map(getcount, inventory), [3, 2, 5, 1])
! self.assertEqual(sorted(inventory, key=getcount),
[('orange', 1), ('banana', 2), ('apple', 3), ('pear', 5)])
Index: test_set.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/test/test_set.py,v
retrieving revision 1.7
retrieving revision 1.8
diff -C2 -d -r1.7 -r1.8
*** test_set.py 24 Nov 2003 02:57:33 -0000 1.7
--- test_set.py 17 Dec 2003 20:43:32 -0000 1.8
***************
*** 23,28 ****
def test_uniquification(self):
! actual = list.sorted(self.s)
! expected = list.sorted(self.d)
self.assertEqual(actual, expected)
self.assertRaises(PassThru, self.thetype, check_pass_thru())
--- 23,28 ----
def test_uniquification(self):
! actual = sorted(self.s)
! expected = sorted(self.d)
self.assertEqual(actual, expected)
self.assertRaises(PassThru, self.thetype, check_pass_thru())
***************
*** 1242,1246 ****
for s in ("123", "", range(1000), ('do', 1.2), xrange(2000,2200,5)):
for g in (G, I, Ig, S, L, R):
! self.assertEqual(list.sorted(cons(g(s))), list.sorted(g(s)))
self.assertRaises(TypeError, cons , X(s))
self.assertRaises(TypeError, cons , N(s))
--- 1242,1246 ----
for s in ("123", "", range(1000), ('do', 1.2), xrange(2000,2200,5)):
for g in (G, I, Ig, S, L, R):
! self.assertEqual(sorted(cons(g(s))), sorted(g(s)))
self.assertRaises(TypeError, cons , X(s))
self.assertRaises(TypeError, cons , N(s))
***************
*** 1254,1258 ****
expected = meth(data)
actual = meth(G(data))
! self.assertEqual(list.sorted(actual), list.sorted(expected))
self.assertRaises(TypeError, meth, X(s))
self.assertRaises(TypeError, meth, N(s))
--- 1254,1258 ----
expected = meth(data)
actual = meth(G(data))
! self.assertEqual(sorted(actual), sorted(expected))
self.assertRaises(TypeError, meth, X(s))
self.assertRaises(TypeError, meth, N(s))
***************
*** 1268,1272 ****
getattr(s, methname)(list(g(data)))
getattr(t, methname)(g(data))
! self.assertEqual(list.sorted(s), list.sorted(t))
self.assertRaises(TypeError, getattr(set('january'), methname), X(data))
--- 1268,1272 ----
getattr(s, methname)(list(g(data)))
getattr(t, methname)(g(data))
! self.assertEqual(sorted(s), sorted(t))
self.assertRaises(TypeError, getattr(set('january'), methname), X(data))
Index: test_sort.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/test/test_sort.py,v
retrieving revision 1.10
retrieving revision 1.11
diff -C2 -d -r1.10 -r1.11
*** test_sort.py 4 Dec 2003 11:41:24 -0000 1.10
--- test_sort.py 17 Dec 2003 20:43:32 -0000 1.11
***************
*** 249,306 ****
self.assertEqual(data, copy2)
- class TestSorted(unittest.TestCase):
-
- def test_basic(self):
- data = range(100)
- copy = data[:]
- random.shuffle(copy)
- self.assertEqual(data, list.sorted(copy))
- self.assertNotEqual(data, copy)
-
- data.reverse()
- random.shuffle(copy)
- self.assertEqual(data, list.sorted(copy, cmp=lambda x, y: cmp(y,x)))
- self.assertNotEqual(data, copy)
- random.shuffle(copy)
- self.assertEqual(data, list.sorted(copy, key=lambda x: -x))
- self.assertNotEqual(data, copy)
- random.shuffle(copy)
- self.assertEqual(data, list.sorted(copy, reverse=1))
- self.assertNotEqual(data, copy)
-
- def test_inputtypes(self):
- s = 'abracadabra'
- for T in [unicode, list, tuple]:
- self.assertEqual(list.sorted(s), list.sorted(T(s)))
-
- s = ''.join(dict.fromkeys(s).keys()) # unique letters only
- for T in [unicode, set, frozenset, list, tuple, dict.fromkeys]:
- self.assertEqual(list.sorted(s), list.sorted(T(s)))
-
- def test_baddecorator(self):
- data = 'The quick Brown fox Jumped over The lazy Dog'.split()
- self.assertRaises(TypeError, list.sorted, data, None, lambda x,y: 0)
-
- def classmethods(self):
- s = "hello world"
- a = list.sorted(s)
- b = UserList.sorted(s)
- c = [].sorted(s)
- d = UserList().sorted(s)
- class Mylist(list):
- def __new__(cls):
- return UserList()
- e = MyList.sorted(s)
- f = MyList().sorted(s)
- class Myuserlist(UserList):
- def __new__(cls):
- return []
- g = MyList.sorted(s)
- h = MyList().sorted(s)
- self.assert_(a == b == c == d == e == f == g == h)
- self.assert_(b.__class__ == d.__class__ == UserList)
- self.assert_(e.__class__ == f.__class__ == MyList)
- self.assert_(g.__class__ == h.__class__ == Myuserlist)
-
#==============================================================================
--- 249,252 ----
***************
*** 308,312 ****
test_classes = (
TestDecorateSortUndecorate,
- TestSorted,
TestBugs,
)
--- 254,257 ----
More information about the Python-checkins
mailing list