[Python-checkins] python/dist/src/Lib/test test_complex.py,1.11,1.12

doerwalter@users.sourceforge.net doerwalter@users.sourceforge.net
Tue, 15 Jul 2003 11:47:29 -0700


Update of /cvsroot/python/python/dist/src/Lib/test
In directory sc8-pr-cvs1:/tmp/cvs-serv14985/Lib/test

Modified Files:
	test_complex.py 
Log Message:
Add various test cases from SF patch 543867.


Index: test_complex.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/test/test_complex.py,v
retrieving revision 1.11
retrieving revision 1.12
diff -C2 -d -r1.11 -r1.12
*** test_complex.py	29 Jun 2003 05:46:54 -0000	1.11
--- test_complex.py	15 Jul 2003 18:47:27 -0000	1.12
***************
*** 1,3 ****
! import unittest
  from test import test_support
  
--- 1,3 ----
! import unittest, os
  from test import test_support
  
***************
*** 107,110 ****
--- 107,118 ----
          self.assertRaises(ZeroDivisionError, (1+1j).__mod__, 0+0j)
  
+         a = 3.33+4.43j
+         try:
+             a % 0
+         except ZeroDivisionError:
+             pass
+         else:
+             self.fail("modulo parama can't be 0")
+ 
      def test_divmod(self):
          self.assertRaises(ZeroDivisionError, divmod, 1+1j, 0+0j)
***************
*** 118,121 ****
--- 126,160 ----
          self.assertRaises(ValueError, pow, 1+1j, 1+1j, 1+1j)
  
+         a = 3.33+4.43j
+         self.assertEqual(a ** 0j, 1)
+         self.assertEqual(a ** 0.+0.j, 1)
+ 
+         self.assertEqual(3j ** 0j, 1)
+         self.assertEqual(3j ** 0, 1)
+ 
+         try:
+             0j ** a
+         except ZeroDivisionError:
+             pass
+         else:
+             self.fail("should fail 0.0 to negative or complex power")
+ 
+         try:
+             0j ** (3-2j)
+         except ZeroDivisionError:
+             pass
+         else:
+             self.fail("should fail 0.0 to negative or complex power")
+ 
+         # The following is used to exercise certain code paths
+         self.assertEqual(a ** 105, a ** 105)
+         self.assertEqual(a ** -105, a ** -105)
+         self.assertEqual(a ** -30, a ** -30)
+ 
+         self.assertEqual(0.0j ** 0, 1)
+ 
+         b = 5.1+2.3j
+         self.assertRaises(ValueError, pow, a, b, 0)
+ 
      def test_boolcontext(self):
          for i in xrange(100):
***************
*** 244,247 ****
--- 283,304 ----
          self.assertEqual(-(1+6j), -1-6j)
  
+     def test_file(self):
+         a = 3.33+4.43j
+         b = 5.1+2.3j
+ 
+         fo = None
+         try:
+             fo = open(test_support.TESTFN, "wb")
+             print >>fo, a, b
+             fo.close()
+             fo = open(test_support.TESTFN, "rb")
+             self.assertEqual(fo.read(), "%s %s\n" % (a, b))
+         finally:
+             if (fo is not None) and (not fo.closed):
+                 fo.close()
+             try:
+                 os.remove(test_support.TESTFN)
+             except (OSError, IOError):
+                 pass
  
  def test_main():