[Scipy-svn] r2255 - trunk/Lib/sandbox/models/tests

scipy-svn at scipy.org scipy-svn at scipy.org
Thu Oct 12 02:48:49 EDT 2006


Author: timl
Date: 2006-10-12 01:48:34 -0500 (Thu, 12 Oct 2006)
New Revision: 2255

Modified:
   trunk/Lib/sandbox/models/tests/test_formula.py
   trunk/Lib/sandbox/models/tests/test_glm.py
   trunk/Lib/sandbox/models/tests/test_regression.py
   trunk/Lib/sandbox/models/tests/test_utils.py
Log:
update unit tests in sandbox.models to work with the scipy testing framework

Modified: trunk/Lib/sandbox/models/tests/test_formula.py
===================================================================
--- trunk/Lib/sandbox/models/tests/test_formula.py	2006-10-11 23:28:59 UTC (rev 2254)
+++ trunk/Lib/sandbox/models/tests/test_formula.py	2006-10-12 06:48:34 UTC (rev 2255)
@@ -3,10 +3,11 @@
 import numpy.random as R
 import numpy.linalg as L
 import scipy, string
+from numpy.testing import *
 
-from models import utils, formula, contrast
+from scipy.sandbox.models import utils, formula, contrast
 
-class TermTest(unittest.TestCase):
+class test_Term(ScipyTestCase):
 
     def test_init(self):
         t1 = formula.Term("trivial")
@@ -41,7 +42,7 @@
         f = intercept * t1
         self.assertEqual(str(f), str(formula.Formula(t1)))
 
-class FormulaTest(unittest.TestCase):
+class test_Formula(ScipyTestCase):
 
     def setUp(self):
         self.X = R.standard_normal((40,10))
@@ -72,7 +73,7 @@
         self.formula += prod
         x = self.formula.design(namespace=self.namespace)
         col = self.formula.termcolumns(prod, dict=False)
-        scipy.testing.assert_almost_equal(N.squeeze(x[:,col]), self.X[:,0] * self.X[:,2])
+        assert_almost_equal(N.squeeze(x[:,col]), self.X[:,0] * self.X[:,2])
 
     def test_contrast1(self):
         term = self.terms[0] + self.terms[2]
@@ -81,7 +82,7 @@
         col1 = self.formula.termcolumns(self.terms[0], dict=False)
         col2 = self.formula.termcolumns(self.terms[1], dict=False)
         test = [[1] + [0]*9, [0]*2 + [1] + [0]*7]
-        scipy.testing.assert_almost_equal(c.matrix, test)
+        assert_almost_equal(c.matrix, test)
 
     def test_contrast2(self):
     
@@ -91,7 +92,7 @@
         c = contrast.Contrast(term, self.formula)
         c.getmatrix(namespace=self.namespace)
         test = [0]*2 + [1] + [0]*7
-        scipy.testing.assert_almost_equal(c.matrix, test)
+        assert_almost_equal(c.matrix, test)
 
     def test_contrast3(self):
     
@@ -124,4 +125,4 @@
 
 
 if __name__ == '__main__':
-    unittest.main()
+    ScipyTest.run()

Modified: trunk/Lib/sandbox/models/tests/test_glm.py
===================================================================
--- trunk/Lib/sandbox/models/tests/test_glm.py	2006-10-11 23:28:59 UTC (rev 2254)
+++ trunk/Lib/sandbox/models/tests/test_glm.py	2006-10-12 06:48:34 UTC (rev 2255)
@@ -1,26 +1,29 @@
-import models as S
+import scipy.sandbox.models as S
 import unittest
 import numpy.random as R
 import numpy as N
+from numpy.testing import *
+from scipy.sandbox.models.glm import Model
 
 W = R.standard_normal
 
-class RegressionTest(unittest.TestCase):
 
-    def testLogistic(self):
+class test_Regression(ScipyTestCase):
+
+    def check_Logistic(self):
         X = W((40,10))
         Y = N.greater(W((40,)), 0)
         family = S.family.Binomial()
-        model = S.glm.GeneralizedLinearModel(design=X, family=S.family.Binomial())
+        model = Model(design=X, family=S.family.Binomial())
         results = model.fit(Y)
         self.assertEquals(results.df_resid, 30)
 
-    def testLogisticdegenerate(self):
+    def check_Logisticdegenerate(self):
         X = W((40,10))
         X[:,0] = X[:,1] + X[:,2]
         Y = N.greater(W((40,)), 0)
         family = S.family.Binomial()
-        model = S.glm.GeneralizedLinearModel(design=X, family=S.family.Binomial())
+        model = Model(design=X, family=S.family.Binomial())
         results = model.fit(Y)
         self.assertEquals(results.df_resid, 31)
 
@@ -29,6 +32,5 @@
     suite = unittest.makeSuite(RegressionTest)
     return suite
         
-
-if __name__ == '__main__':
-    unittest.main()
+if __name__ == "__main__":
+    ScipyTest().run()

Modified: trunk/Lib/sandbox/models/tests/test_regression.py
===================================================================
--- trunk/Lib/sandbox/models/tests/test_regression.py	2006-10-11 23:28:59 UTC (rev 2254)
+++ trunk/Lib/sandbox/models/tests/test_regression.py	2006-10-12 06:48:34 UTC (rev 2255)
@@ -1,10 +1,11 @@
 import unittest
 from numpy.random import standard_normal
 from scipy.sandbox.models.regression import OLSModel, ARModel
+from numpy.testing import *
 
 W = standard_normal
 
-class RegressionTest(unittest.TestCase):
+class test_Regression(ScipyTestCase):
 
     def testOLS(self):
         X = W((40,10))
@@ -42,4 +43,4 @@
         
 
 if __name__ == '__main__':
-    unittest.main()
+    ScipyTest.run()

Modified: trunk/Lib/sandbox/models/tests/test_utils.py
===================================================================
--- trunk/Lib/sandbox/models/tests/test_utils.py	2006-10-11 23:28:59 UTC (rev 2254)
+++ trunk/Lib/sandbox/models/tests/test_utils.py	2006-10-12 06:48:34 UTC (rev 2255)
@@ -2,20 +2,20 @@
 import numpy as N
 import numpy.random as R
 import scipy
-
+from numpy.testing import *
 from scipy.sandbox.models import utils
 
-class UtilsTest(unittest.TestCase):
+class test_Utils(ScipyTestCase):
 
     def test_recipr(self):
         X = N.array([[2,1],[-1,0]])
         Y = utils.recipr(X)
-        scipy.testing.assert_almost_equal(Y, N.array([[0.5,1],[0,0]]))
+        assert_almost_equal(Y, N.array([[0.5,1],[0,0]]))
 
     def test_recipr0(self):
         X = N.array([[2,1],[-4,0]])
         Y = utils.recipr0(X)
-        scipy.testing.assert_almost_equal(Y, N.array([[0.5,1],[-0.25,0]]))
+        assert_almost_equal(Y, N.array([[0.5,1],[-0.25,0]]))
 
     def test_rank(self):
         X = R.standard_normal((40,10))
@@ -41,7 +41,7 @@
         x = N.arange(20)
         y = N.arange(20)
         f = utils.StepFunction(x, y)
-        scipy.testing.assert_almost_equal(f( N.array([[3.2,4.5],[24,-3.1]]) ), [[ 3, 4], [19, 0]])
+        assert_almost_equal(f( N.array([[3.2,4.5],[24,-3.1]]) ), [[ 3, 4], [19, 0]])
 
     def test_StepFunctionBadShape(self):
         x = N.arange(20)
@@ -52,4 +52,4 @@
         self.assertRaises(ValueError, utils.StepFunction, x, y)
 
 if __name__ == '__main__':
-    unittest.main()
+    ScipyTest.run()




More information about the Scipy-svn mailing list