~ubuntu-branches/ubuntu/karmic/python3.0/karmic

« back to all changes in this revision

Viewing changes to Lib/test/test_builtin.py

  • Committer: Bazaar Package Importer
  • Author(s): Matthias Klose
  • Date: 2009-02-16 17:18:23 UTC
  • mfrom: (1.1.4 upstream)
  • Revision ID: james.westby@ubuntu.com-20090216171823-1d5cm5qnnjvmnzzm
Tags: 3.0.1-0ubuntu1
New upstream version.

Show diffs side-by-side

added added

removed removed

Lines of Context:
10
10
                        FutureWarning, __name__)
11
11
warnings.filterwarnings("ignore", "integer argument expected",
12
12
                        DeprecationWarning, "unittest")
 
13
import builtins
13
14
 
14
15
class Squares:
15
16
 
219
220
        self.assertRaises((OverflowError, ValueError), chr, 2**32)
220
221
 
221
222
    def test_cmp(self):
222
 
        self.assertEqual(cmp(-1, 1), -1)
223
 
        self.assertEqual(cmp(1, -1), 1)
224
 
        self.assertEqual(cmp(1, 1), 0)
225
 
        # verify that circular objects are not handled
226
 
        a = []; a.append(a)
227
 
        b = []; b.append(b)
228
 
        from collections import UserList
229
 
        c = UserList(); c.append(c)
230
 
        self.assertRaises(RuntimeError, cmp, a, b)
231
 
        self.assertRaises(RuntimeError, cmp, b, c)
232
 
        self.assertRaises(RuntimeError, cmp, c, a)
233
 
        self.assertRaises(RuntimeError, cmp, a, c)
234
 
       # okay, now break the cycles
235
 
        a.pop(); b.pop(); c.pop()
236
 
        self.assertRaises(TypeError, cmp)
 
223
        self.assert_(not hasattr(builtins, "cmp"))
237
224
 
238
225
    def test_compile(self):
239
226
        compile('print(1)\n', '', 'exec')
624
611
            def __len__(self):
625
612
                raise ValueError
626
613
        self.assertRaises(ValueError, len, BadSeq())
 
614
        class InvalidLen:
 
615
            def __len__(self):
 
616
                return None
 
617
        self.assertRaises(TypeError, len, InvalidLen())
 
618
        class FloatLen:
 
619
            def __len__(self):
 
620
                return 4.5
 
621
        self.assertRaises(TypeError, len, FloatLen())
 
622
        class HugeLen:
 
623
            def __len__(self):
 
624
                return sys.maxsize + 1
 
625
        self.assertRaises(OverflowError, len, HugeLen())
627
626
 
628
627
    def test_map(self):
629
628
        self.assertEqual(
736
735
            def __getitem__(self, index):
737
736
                raise ValueError
738
737
        self.assertRaises(ValueError, min, BadSeq())
739
 
        class BadNumber:
740
 
            def __cmp__(self, other):
741
 
                raise ValueError
742
 
        self.assertRaises(TypeError, min, (42, BadNumber()))
743
738
 
744
739
        for stmt in (
745
740
            "min(key=int)",                 # no args
1083
1078
        self.assertEqual(round(8), 8)
1084
1079
        self.assertEqual(round(-8), -8)
1085
1080
        self.assertEqual(type(round(0)), int)
1086
 
        self.assertEqual(type(round(-8, -1)), float)
1087
 
        self.assertEqual(type(round(-8, 0)), float)
1088
 
        self.assertEqual(type(round(-8, 1)), float)
 
1081
        self.assertEqual(type(round(-8, -1)), int)
 
1082
        self.assertEqual(type(round(-8, 0)), int)
 
1083
        self.assertEqual(type(round(-8, 1)), int)
1089
1084
 
1090
1085
        # test new kwargs
1091
1086
        self.assertEqual(round(number=-8.0, ndigits=-1), -10.0)