diff options
author | Jeremy Hylton <jeremy@alum.mit.edu> | 2001-08-12 02:22:27 (GMT) |
---|---|---|
committer | Jeremy Hylton <jeremy@alum.mit.edu> | 2001-08-12 02:22:27 (GMT) |
commit | 08a640397344b2cc2bf65b5f6ea2db1cc10a19de (patch) | |
tree | b537b80530613161cd5c93d199fb64fb847d2ce3 | |
parent | f73e30c3e3ba6f2779eadf6bf4c21c6bf3e4c075 (diff) | |
download | cpython-08a640397344b2cc2bf65b5f6ea2db1cc10a19de.zip cpython-08a640397344b2cc2bf65b5f6ea2db1cc10a19de.tar.gz cpython-08a640397344b2cc2bf65b5f6ea2db1cc10a19de.tar.bz2 |
Test the unary operator changes to the compiler
-rw-r--r-- | Lib/test/test_unary.py | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/Lib/test/test_unary.py b/Lib/test/test_unary.py new file mode 100644 index 0000000..0419167 --- /dev/null +++ b/Lib/test/test_unary.py @@ -0,0 +1,43 @@ +"""Test compiler changes for unary ops (+, -, ~) introduced in Python 2.2""" + +import unittest +from test_support import run_unittest + +class UnaryOpTestCase(unittest.TestCase): + + def test_negative(self): + self.assert_(-2 == 0 - 2) + self.assert_(-0 == 0) + self.assert_(--2 == 2) + self.assert_(-2L == 0 - 2L) + self.assert_(-2.0 == 0 - 2.0) + self.assert_(-2j == 0 - 2j) + + def test_positive(self): + self.assert_(+2 == 2) + self.assert_(+0 == 0) + self.assert_(++2 == 2) + self.assert_(+2L == 2L) + self.assert_(+2.0 == 2.0) + self.assert_(+2j == 2j) + + def test_invert(self): + self.assert_(-2 == 0 - 2) + self.assert_(-0 == 0) + self.assert_(--2 == 2) + self.assert_(-2L == 0 - 2L) + + def test_overflow(self): + self.assertRaises(OverflowError, eval, "+" + ("9" * 32)) + self.assertRaises(OverflowError, eval, "-" + ("9" * 32)) + self.assertRaises(OverflowError, eval, "~" + ("9" * 32)) + + def test_bad_types(self): + for op in '+', '-', '~': + self.assertRaises(TypeError, eval, op + "'a'") + self.assertRaises(TypeError, eval, op + "u'a'") + + self.assertRaises(TypeError, eval, "~2j") + self.assertRaises(TypeError, eval, "~2.0") + +run_unittest(UnaryOpTestCase) |