aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/Lib/test/test_builtin.py
diff options
context:
space:
mode:
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 1953f29626e..db823ff9c07 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()