[Numpy-svn] r5338 - trunk/numpy/lib/tests

numpy-svn@scip... numpy-svn@scip...
Wed Jul 2 22:57:36 CDT 2008


Author: alan.mcintyre
Date: 2008-07-02 22:57:29 -0500 (Wed, 02 Jul 2008)
New Revision: 5338

Modified:
   trunk/numpy/lib/tests/test_arraysetops.py
   trunk/numpy/lib/tests/test_financial.py
   trunk/numpy/lib/tests/test_format.py
   trunk/numpy/lib/tests/test_function_base.py
   trunk/numpy/lib/tests/test_index_tricks.py
   trunk/numpy/lib/tests/test_regression.py
   trunk/numpy/lib/tests/test_shape_base.py
   trunk/numpy/lib/tests/test_twodim_base.py
   trunk/numpy/lib/tests/test_type_check.py
Log:
Remove uses of set_package_path, set_local_path, restore_path.
Clean up and (somewhat) standardize test module imports.
Removed unneeded reload calls.


Modified: trunk/numpy/lib/tests/test_arraysetops.py
===================================================================
--- trunk/numpy/lib/tests/test_arraysetops.py	2008-07-03 03:51:46 UTC (rev 5337)
+++ trunk/numpy/lib/tests/test_arraysetops.py	2008-07-03 03:57:29 UTC (rev 5338)
@@ -3,83 +3,67 @@
 """
 
 from numpy.testing import *
-set_package_path()
-import numpy
+import numpy as np
 from numpy.lib.arraysetops import *
-restore_path()
 
-##################################################
-
 class TestAso(TestCase):
-    ##
-    # 03.11.2005, c
     def test_unique1d( self ):
+        a = np.array( [5, 7, 1, 2, 1, 5, 7] )
 
-        a = numpy.array( [5, 7, 1, 2, 1, 5, 7] )
-
-        ec = numpy.array( [1, 2, 5, 7] )
+        ec = np.array( [1, 2, 5, 7] )
         c = unique1d( a )
         assert_array_equal( c, ec )
 
         assert_array_equal([], unique1d([]))
 
-    ##
-    # 03.11.2005, c
     def test_intersect1d( self ):
+        a = np.array( [5, 7, 1, 2] )
+        b = np.array( [2, 4, 3, 1, 5] )
 
-        a = numpy.array( [5, 7, 1, 2] )
-        b = numpy.array( [2, 4, 3, 1, 5] )
-
-        ec = numpy.array( [1, 2, 5] )
+        ec = np.array( [1, 2, 5] )
         c = intersect1d( a, b )
         assert_array_equal( c, ec )
 
         assert_array_equal([], intersect1d([],[]))
 
-    ##
-    # 03.11.2005, c
     def test_intersect1d_nu( self ):
+        a = np.array( [5, 5, 7, 1, 2] )
+        b = np.array( [2, 1, 4, 3, 3, 1, 5] )
 
-        a = numpy.array( [5, 5, 7, 1, 2] )
-        b = numpy.array( [2, 1, 4, 3, 3, 1, 5] )
-
-        ec = numpy.array( [1, 2, 5] )
+        ec = np.array( [1, 2, 5] )
         c = intersect1d_nu( a, b )
         assert_array_equal( c, ec )
 
         assert_array_equal([], intersect1d_nu([],[]))
 
-    ##
-    # 03.11.2005, c
     def test_setxor1d( self ):
+        a = np.array( [5, 7, 1, 2] )
+        b = np.array( [2, 4, 3, 1, 5] )
 
-        a = numpy.array( [5, 7, 1, 2] )
-        b = numpy.array( [2, 4, 3, 1, 5] )
-
-        ec = numpy.array( [3, 4, 7] )
+        ec = np.array( [3, 4, 7] )
         c = setxor1d( a, b )
         assert_array_equal( c, ec )
 
-        a = numpy.array( [1, 2, 3] )
-        b = numpy.array( [6, 5, 4] )
+        a = np.array( [1, 2, 3] )
+        b = np.array( [6, 5, 4] )
 
-        ec = numpy.array( [1, 2, 3, 4, 5, 6] )
+        ec = np.array( [1, 2, 3, 4, 5, 6] )
         c = setxor1d( a, b )
         assert_array_equal( c, ec )
 
-        a = numpy.array( [1, 8, 2, 3] )
-        b = numpy.array( [6, 5, 4, 8] )
+        a = np.array( [1, 8, 2, 3] )
+        b = np.array( [6, 5, 4, 8] )
 
-        ec = numpy.array( [1, 2, 3, 4, 5, 6] )
+        ec = np.array( [1, 2, 3, 4, 5, 6] )
         c = setxor1d( a, b )
         assert_array_equal( c, ec )
 
         assert_array_equal([], setxor1d([],[]))
 
     def test_ediff1d(self):
-        zero_elem = numpy.array([])
-        one_elem = numpy.array([1])
-        two_elem = numpy.array([1,2])
+        zero_elem = np.array([])
+        one_elem = np.array([1])
+        two_elem = np.array([1,2])
 
         assert_array_equal([],ediff1d(zero_elem))
         assert_array_equal([0],ediff1d(zero_elem,to_begin=0))
@@ -88,81 +72,68 @@
         assert_array_equal([],ediff1d(one_elem))
         assert_array_equal([1],ediff1d(two_elem))
 
-    ##
-    # 03.11.2005, c
     def test_setmember1d( self ):
+        a = np.array( [5, 7, 1, 2] )
+        b = np.array( [2, 4, 3, 1, 5] )
 
-        a = numpy.array( [5, 7, 1, 2] )
-        b = numpy.array( [2, 4, 3, 1, 5] )
-
-        ec = numpy.array( [True, False, True, True] )
+        ec = np.array( [True, False, True, True] )
         c = setmember1d( a, b )
         assert_array_equal( c, ec )
 
         a[0] = 8
-        ec = numpy.array( [False, False, True, True] )
+        ec = np.array( [False, False, True, True] )
         c = setmember1d( a, b )
         assert_array_equal( c, ec )
 
         a[0], a[3] = 4, 8
-        ec = numpy.array( [True, False, True, False] )
+        ec = np.array( [True, False, True, False] )
         c = setmember1d( a, b )
         assert_array_equal( c, ec )
 
         assert_array_equal([], setmember1d([],[]))
 
-    ##
-    # 03.11.2005, c
     def test_union1d( self ):
+        a = np.array( [5, 4, 7, 1, 2] )
+        b = np.array( [2, 4, 3, 3, 2, 1, 5] )
 
-        a = numpy.array( [5, 4, 7, 1, 2] )
-        b = numpy.array( [2, 4, 3, 3, 2, 1, 5] )
-
-        ec = numpy.array( [1, 2, 3, 4, 5, 7] )
+        ec = np.array( [1, 2, 3, 4, 5, 7] )
         c = union1d( a, b )
         assert_array_equal( c, ec )
 
         assert_array_equal([], union1d([],[]))
 
-    ##
-    # 03.11.2005, c
-    # 09.01.2006
     def test_setdiff1d( self ):
+        a = np.array( [6, 5, 4, 7, 1, 2] )
+        b = np.array( [2, 4, 3, 3, 2, 1, 5] )
 
-        a = numpy.array( [6, 5, 4, 7, 1, 2] )
-        b = numpy.array( [2, 4, 3, 3, 2, 1, 5] )
-
-        ec = numpy.array( [6, 7] )
+        ec = np.array( [6, 7] )
         c = setdiff1d( a, b )
         assert_array_equal( c, ec )
 
-        a = numpy.arange( 21 )
-        b = numpy.arange( 19 )
-        ec = numpy.array( [19, 20] )
+        a = np.arange( 21 )
+        b = np.arange( 19 )
+        ec = np.array( [19, 20] )
         c = setdiff1d( a, b )
         assert_array_equal( c, ec )
 
         assert_array_equal([], setdiff1d([],[]))
 
     def test_setdiff1d_char_array(self):
-        a = numpy.array(['a','b','c'])
-        b = numpy.array(['a','b','s'])
-        assert_array_equal(setdiff1d(a,b),numpy.array(['c']))
+        a = np.array(['a','b','c'])
+        b = np.array(['a','b','s'])
+        assert_array_equal(setdiff1d(a,b),np.array(['c']))
 
-    ##
-    # 03.11.2005, c
     def test_manyways( self ):
-
         nItem = 100
-        a = numpy.fix( nItem / 10 * numpy.random.random( nItem ) )
-        b = numpy.fix( nItem / 10 * numpy.random.random( nItem ) )
+        a = np.fix( nItem / 10 * np.random.random( nItem ) )
+        b = np.fix( nItem / 10 * np.random.random( nItem ) )
 
         c1 = intersect1d_nu( a, b )
         c2 = unique1d( intersect1d( a, b ) )
         assert_array_equal( c1, c2 )
 
-        a = numpy.array( [5, 7, 1, 2, 8] )
-        b = numpy.array( [9, 8, 2, 4, 3, 1, 5] )
+        a = np.array( [5, 7, 1, 2, 8] )
+        b = np.array( [9, 8, 2, 4, 3, 1, 5] )
 
         c1 = setxor1d( a, b )
         aux1 = intersect1d( a, b )

Modified: trunk/numpy/lib/tests/test_financial.py
===================================================================
--- trunk/numpy/lib/tests/test_financial.py	2008-07-03 03:51:46 UTC (rev 5337)
+++ trunk/numpy/lib/tests/test_financial.py	2008-07-03 03:57:29 UTC (rev 5338)
@@ -1,31 +1,29 @@
 """
->>> from numpy import rate, irr, pv, fv, pmt, nper, npv, mirr, round
-
->>> round(rate(10,0,-3500,10000),4)==0.1107
+>>> np.round(np.rate(10,0,-3500,10000),4)==0.1107
 True
 
->>> round(irr([-150000, 15000, 25000, 35000, 45000, 60000]),4)==0.0524
+>>> np.round(np.irr([-150000, 15000, 25000, 35000, 45000, 60000]),4)==0.0524
 True
 
->>> round(pv(0.07,20,12000,0),2) == -127128.17
+>>> np.round(np.pv(0.07,20,12000,0),2) == -127128.17
 True
 
->>> round(fv(0.075, 20, -2000,0,0),2) == 86609.36
+>>> np.round(np.fv(0.075, 20, -2000,0,0),2) == 86609.36
 True
 
->>> round(pmt(0.08/12,5*12,15000),3) == -304.146
+>>> np.round(np.pmt(0.08/12,5*12,15000),3) == -304.146
 True
 
->>> round(nper(0.075,-2000,0,100000.),2) == 21.54
+>>> np.round(np.nper(0.075,-2000,0,100000.),2) == 21.54
 True
 
->>> round(npv(0.05,[-15000,1500,2500,3500,4500,6000]),2) == 117.04
+>>> np.round(np.npv(0.05,[-15000,1500,2500,3500,4500,6000]),2) == 117.04
 True
 
->>> round(mirr([-4500,-800,800,800,600,600,800,800,700,3000],0.08,0.055),4) == 0.0665
+>>> np.round(np.mirr([-4500,-800,800,800,600,600,800,800,700,3000],0.08,0.055),4) == 0.0665
 True
 
->>> round(mirr([-120000,39000,30000,21000,37000,46000],0.10,0.12),4)==0.1344
+>>> np.round(np.mirr([-120000,39000,30000,21000,37000,46000],0.10,0.12),4)==0.1344
 True
 """
 

Modified: trunk/numpy/lib/tests/test_format.py
===================================================================
--- trunk/numpy/lib/tests/test_format.py	2008-07-03 03:51:46 UTC (rev 5337)
+++ trunk/numpy/lib/tests/test_format.py	2008-07-03 03:57:29 UTC (rev 5338)
@@ -2,7 +2,6 @@
 
 Set up:
 
-    >>> import numpy as np
     >>> from cStringIO import StringIO
     >>> from numpy.lib import format
     >>>

Modified: trunk/numpy/lib/tests/test_function_base.py
===================================================================
--- trunk/numpy/lib/tests/test_function_base.py	2008-07-03 03:51:46 UTC (rev 5337)
+++ trunk/numpy/lib/tests/test_function_base.py	2008-07-03 03:57:29 UTC (rev 5338)
@@ -1,11 +1,9 @@
 import sys
 
 from numpy.testing import *
-set_package_path()
-import numpy.lib;reload(numpy.lib)
+import numpy.lib
 from numpy.lib import *
 from numpy.core import *
-restore_path()
 
 class TestAny(TestCase):
     def test_basic(self):

Modified: trunk/numpy/lib/tests/test_index_tricks.py
===================================================================
--- trunk/numpy/lib/tests/test_index_tricks.py	2008-07-03 03:51:46 UTC (rev 5337)
+++ trunk/numpy/lib/tests/test_index_tricks.py	2008-07-03 03:57:29 UTC (rev 5338)
@@ -1,7 +1,5 @@
 from numpy.testing import *
-set_package_path()
 from numpy import array, ones, r_, mgrid
-restore_path()
 
 class TestGrid(TestCase):
     def test_basic(self):

Modified: trunk/numpy/lib/tests/test_regression.py
===================================================================
--- trunk/numpy/lib/tests/test_regression.py	2008-07-03 03:51:46 UTC (rev 5337)
+++ trunk/numpy/lib/tests/test_regression.py	2008-07-03 03:57:29 UTC (rev 5338)
@@ -1,8 +1,5 @@
 from numpy.testing import *
-
-set_local_path()
 import numpy as np
-restore_path()
 
 rlevel = 1
 

Modified: trunk/numpy/lib/tests/test_shape_base.py
===================================================================
--- trunk/numpy/lib/tests/test_shape_base.py	2008-07-03 03:51:46 UTC (rev 5337)
+++ trunk/numpy/lib/tests/test_shape_base.py	2008-07-03 03:57:29 UTC (rev 5338)
@@ -1,8 +1,6 @@
 from numpy.testing import *
-set_package_path()
 from numpy.lib import *
 from numpy.core import *
-restore_path()
 
 class TestApplyAlongAxis(TestCase):
     def test_simple(self):

Modified: trunk/numpy/lib/tests/test_twodim_base.py
===================================================================
--- trunk/numpy/lib/tests/test_twodim_base.py	2008-07-03 03:51:46 UTC (rev 5337)
+++ trunk/numpy/lib/tests/test_twodim_base.py	2008-07-03 03:57:29 UTC (rev 5338)
@@ -3,15 +3,10 @@
 """
 
 from numpy.testing import *
-set_package_path()
 from numpy import arange, rot90, add, fliplr, flipud, zeros, ones, eye, \
      array, diag, histogram2d, tri
 import numpy as np
-restore_path()
 
-##################################################
-
-
 def get_mat(n):
     data = arange(n)
     data = add.outer(data,data)

Modified: trunk/numpy/lib/tests/test_type_check.py
===================================================================
--- trunk/numpy/lib/tests/test_type_check.py	2008-07-03 03:51:46 UTC (rev 5337)
+++ trunk/numpy/lib/tests/test_type_check.py	2008-07-03 03:57:29 UTC (rev 5338)
@@ -1,11 +1,7 @@
-import sys
-
 from numpy.testing import *
-set_package_path()
-import numpy.lib;reload(numpy.lib);reload(numpy.lib.type_check)
+import numpy.lib
 from numpy.lib import *
 from numpy.core import *
-restore_path()
 
 def assert_all(x):
     assert(all(x)), x



More information about the Numpy-svn mailing list