summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_builtin.py
diff options
context:
space:
mode:
authorRaymond Hettinger <python@rcn.com>2003-12-17 20:43:33 (GMT)
committerRaymond Hettinger <python@rcn.com>2003-12-17 20:43:33 (GMT)
commit64958a15d7c03efdc3d2eddf247666e18d1fd910 (patch)
treebc135ae082f8635fa858b81f52f141d7ffbd4c78 /Lib/test/test_builtin.py
parentdf38ea9c29a431602704c6bd45ca7417225a61c4 (diff)
downloadcpython-64958a15d7c03efdc3d2eddf247666e18d1fd910.zip
cpython-64958a15d7c03efdc3d2eddf247666e18d1fd910.tar.gz
cpython-64958a15d7c03efdc3d2eddf247666e18d1fd910.tar.bz2
Guido grants a Christmas wish:
sorted() becomes a regular function instead of a classmethod.
Diffstat (limited to 'Lib/test/test_builtin.py')
-rw-r--r--Lib/test/test_builtin.py37
1 files changed, 35 insertions, 2 deletions
diff --git a/Lib/test/test_builtin.py b/Lib/test/test_builtin.py
index 1953f29..db823ff 100644
--- a/Lib/test/test_builtin.py
+++ b/Lib/test/test_builtin.py
@@ -3,7 +3,7 @@
import test.test_support, unittest
from test.test_support import fcmp, have_unicode, TESTFN, unlink
-import sys, warnings, cStringIO
+import sys, warnings, cStringIO, random
warnings.filterwarnings("ignore", "hex../oct.. of negative int",
FutureWarning, __name__)
warnings.filterwarnings("ignore", "integer argument expected",
@@ -1153,8 +1153,41 @@ class BuiltinTest(unittest.TestCase):
return i
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)
+ test.test_support.run_unittest(BuiltinTest, TestSorted)
if __name__ == "__main__":
test_main()