annotate Lib/test/test_unary.py @ 54294:dba767bc3155 legacy-trunk

remove mention of old ctypes version
author Benjamin Peterson <benjamin@python.org>
date Sat, 23 May 2009 20:59:09 +0000
parents aa0d2d51fbde
children 6768b2350c57 1c26505c1de6
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
19190
bee7557213b2 Test the unary operator changes to the compiler
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
1 """Test compiler changes for unary ops (+, -, ~) introduced in Python 2.2"""
bee7557213b2 Test the unary operator changes to the compiler
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
2
bee7557213b2 Test the unary operator changes to the compiler
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
3 import unittest
24364
aa0d2d51fbde Get rid of relative imports in all unittests. Now anything that
Barry Warsaw <barry@python.org>
parents: 23482
diff changeset
4 from test.test_support import run_unittest, have_unicode
19190
bee7557213b2 Test the unary operator changes to the compiler
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
5
bee7557213b2 Test the unary operator changes to the compiler
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
6 class UnaryOpTestCase(unittest.TestCase):
bee7557213b2 Test the unary operator changes to the compiler
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
7
bee7557213b2 Test the unary operator changes to the compiler
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
8 def test_negative(self):
bee7557213b2 Test the unary operator changes to the compiler
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
9 self.assert_(-2 == 0 - 2)
bee7557213b2 Test the unary operator changes to the compiler
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
10 self.assert_(-0 == 0)
bee7557213b2 Test the unary operator changes to the compiler
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
11 self.assert_(--2 == 2)
bee7557213b2 Test the unary operator changes to the compiler
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
12 self.assert_(-2L == 0 - 2L)
bee7557213b2 Test the unary operator changes to the compiler
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
13 self.assert_(-2.0 == 0 - 2.0)
bee7557213b2 Test the unary operator changes to the compiler
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
14 self.assert_(-2j == 0 - 2j)
bee7557213b2 Test the unary operator changes to the compiler
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
15
bee7557213b2 Test the unary operator changes to the compiler
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
16 def test_positive(self):
bee7557213b2 Test the unary operator changes to the compiler
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
17 self.assert_(+2 == 2)
bee7557213b2 Test the unary operator changes to the compiler
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
18 self.assert_(+0 == 0)
bee7557213b2 Test the unary operator changes to the compiler
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
19 self.assert_(++2 == 2)
bee7557213b2 Test the unary operator changes to the compiler
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
20 self.assert_(+2L == 2L)
bee7557213b2 Test the unary operator changes to the compiler
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
21 self.assert_(+2.0 == 2.0)
bee7557213b2 Test the unary operator changes to the compiler
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
22 self.assert_(+2j == 2j)
bee7557213b2 Test the unary operator changes to the compiler
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
23
bee7557213b2 Test the unary operator changes to the compiler
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
24 def test_invert(self):
bee7557213b2 Test the unary operator changes to the compiler
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
25 self.assert_(-2 == 0 - 2)
bee7557213b2 Test the unary operator changes to the compiler
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
26 self.assert_(-0 == 0)
bee7557213b2 Test the unary operator changes to the compiler
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
27 self.assert_(--2 == 2)
bee7557213b2 Test the unary operator changes to the compiler
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
28 self.assert_(-2L == 0 - 2L)
bee7557213b2 Test the unary operator changes to the compiler
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
29
19516
4aec9cb7fe5d Change test_overflow to test_no_overflow; looks like big int literals
Tim Peters <tim.peters@gmail.com>
parents: 19190
diff changeset
30 def test_no_overflow(self):
4aec9cb7fe5d Change test_overflow to test_no_overflow; looks like big int literals
Tim Peters <tim.peters@gmail.com>
parents: 19190
diff changeset
31 nines = "9" * 32
4aec9cb7fe5d Change test_overflow to test_no_overflow; looks like big int literals
Tim Peters <tim.peters@gmail.com>
parents: 19190
diff changeset
32 self.assert_(eval("+" + nines) == eval("+" + nines + "L"))
4aec9cb7fe5d Change test_overflow to test_no_overflow; looks like big int literals
Tim Peters <tim.peters@gmail.com>
parents: 19190
diff changeset
33 self.assert_(eval("-" + nines) == eval("-" + nines + "L"))
4aec9cb7fe5d Change test_overflow to test_no_overflow; looks like big int literals
Tim Peters <tim.peters@gmail.com>
parents: 19190
diff changeset
34 self.assert_(eval("~" + nines) == eval("~" + nines + "L"))
19190
bee7557213b2 Test the unary operator changes to the compiler
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
35
19615
253aaa1edcbd Revert the previous patch to test_pow.py and move the test to test_unary.py
Fred Drake <fdrake@acm.org>
parents: 19516
diff changeset
36 def test_negation_of_exponentiation(self):
253aaa1edcbd Revert the previous patch to test_pow.py and move the test to test_unary.py
Fred Drake <fdrake@acm.org>
parents: 19516
diff changeset
37 # Make sure '**' does the right thing; these form a
253aaa1edcbd Revert the previous patch to test_pow.py and move the test to test_unary.py
Fred Drake <fdrake@acm.org>
parents: 19516
diff changeset
38 # regression test for SourceForge bug #456756.
253aaa1edcbd Revert the previous patch to test_pow.py and move the test to test_unary.py
Fred Drake <fdrake@acm.org>
parents: 19516
diff changeset
39 self.assertEqual(-2 ** 3, -8)
253aaa1edcbd Revert the previous patch to test_pow.py and move the test to test_unary.py
Fred Drake <fdrake@acm.org>
parents: 19516
diff changeset
40 self.assertEqual((-2) ** 3, -8)
253aaa1edcbd Revert the previous patch to test_pow.py and move the test to test_unary.py
Fred Drake <fdrake@acm.org>
parents: 19516
diff changeset
41 self.assertEqual(-2 ** 4, -16)
253aaa1edcbd Revert the previous patch to test_pow.py and move the test to test_unary.py
Fred Drake <fdrake@acm.org>
parents: 19516
diff changeset
42 self.assertEqual((-2) ** 4, 16)
253aaa1edcbd Revert the previous patch to test_pow.py and move the test to test_unary.py
Fred Drake <fdrake@acm.org>
parents: 19516
diff changeset
43
19190
bee7557213b2 Test the unary operator changes to the compiler
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
44 def test_bad_types(self):
bee7557213b2 Test the unary operator changes to the compiler
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
45 for op in '+', '-', '~':
bee7557213b2 Test the unary operator changes to the compiler
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
46 self.assertRaises(TypeError, eval, op + "'a'")
23482
5bd30a36897b tolerate --disable-unicode...
Michael W. Hudson <mwh@python.net>
parents: 20013
diff changeset
47 if have_unicode:
5bd30a36897b tolerate --disable-unicode...
Michael W. Hudson <mwh@python.net>
parents: 20013
diff changeset
48 self.assertRaises(TypeError, eval, op + "u'a'")
19190
bee7557213b2 Test the unary operator changes to the compiler
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
49
bee7557213b2 Test the unary operator changes to the compiler
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
50 self.assertRaises(TypeError, eval, "~2j")
bee7557213b2 Test the unary operator changes to the compiler
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
51 self.assertRaises(TypeError, eval, "~2.0")
bee7557213b2 Test the unary operator changes to the compiler
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff changeset
52
20013
e3184e46303b Change the PyUnit-based tests to use the test_main() approach. This
Fred Drake <fdrake@acm.org>
parents: 19615
diff changeset
53
e3184e46303b Change the PyUnit-based tests to use the test_main() approach. This
Fred Drake <fdrake@acm.org>
parents: 19615
diff changeset
54 def test_main():
e3184e46303b Change the PyUnit-based tests to use the test_main() approach. This
Fred Drake <fdrake@acm.org>
parents: 19615
diff changeset
55 run_unittest(UnaryOpTestCase)
e3184e46303b Change the PyUnit-based tests to use the test_main() approach. This
Fred Drake <fdrake@acm.org>
parents: 19615
diff changeset
56
e3184e46303b Change the PyUnit-based tests to use the test_main() approach. This
Fred Drake <fdrake@acm.org>
parents: 19615
diff changeset
57
e3184e46303b Change the PyUnit-based tests to use the test_main() approach. This
Fred Drake <fdrake@acm.org>
parents: 19615
diff changeset
58 if __name__ == "__main__":
e3184e46303b Change the PyUnit-based tests to use the test_main() approach. This
Fred Drake <fdrake@acm.org>
parents: 19615
diff changeset
59 test_main()