light pep8 formatting in tests

This commit is contained in:
Lindsey Heagy
2016-07-16 16:26:36 -07:00
parent 6826df8989
commit 62b3a3a218
3 changed files with 18 additions and 11 deletions
+3 -3
View File
@@ -5,12 +5,12 @@ from SimPEG import *
class TestTimeProblem(unittest.TestCase):
def setUp(self):
mesh = Mesh.TensorMesh([10,10])
mesh = Mesh.TensorMesh([10, 10])
self.prob = Problem.BaseTimeProblem(mesh)
def test_timeProblem_setTimeSteps(self):
self.prob.timeSteps = [(1e-6, 3), 1e-5, (1e-4, 2)]
trueTS = np.r_[1e-6,1e-6,1e-6,1e-5,1e-4,1e-4]
trueTS = np.r_[1e-6, 1e-6, 1e-6, 1e-5, 1e-4, 1e-4]
self.assertTrue(np.all(trueTS == self.prob.timeSteps))
self.prob.timeSteps = trueTS
@@ -18,7 +18,7 @@ class TestTimeProblem(unittest.TestCase):
self.assertTrue(self.prob.nT == 6)
self.assertTrue(np.all(self.prob.times == np.r_[0,trueTS].cumsum()))
self.assertTrue(np.all(self.prob.times == np.r_[0, trueTS].cumsum()))
if __name__ == '__main__':
+14 -7
View File
@@ -8,6 +8,7 @@ TOL = 1e-20
testReg = True
testRegMesh = True
class RegularizationTests(unittest.TestCase):
def setUp(self):
@@ -16,41 +17,47 @@ class RegularizationTests(unittest.TestCase):
mesh1 = Mesh.TensorMesh([hx])
mesh2 = Mesh.TensorMesh([hx, hy])
mesh3 = Mesh.TensorMesh([hx, hy, hz])
self.meshlist = [mesh1,mesh2, mesh3]
self.meshlist = [mesh1, mesh2, mesh3]
if testReg:
def test_regularization(self):
for R in dir(Regularization):
r = getattr(Regularization, R)
if not inspect.isclass(r): continue
if not inspect.isclass(r):
continue
if not issubclass(r, Regularization.BaseRegularization):
continue
for i, mesh in enumerate(self.meshlist):
print 'Testing %iD'%mesh.dim
print 'Testing %iD' % mesh.dim
mapping = r.mapPair(mesh)
reg = r(mesh, mapping=mapping)
m = np.random.rand(mapping.nP)
reg.mref = np.ones_like(m)*np.mean(m)
print 'Check: phi_m (mref) = %f' %reg.eval(reg.mref)
print 'Check: phi_m (mref) = %f' % reg.eval(reg.mref)
passed = reg.eval(reg.mref) < TOL
self.assertTrue(passed)
print 'Check:', R
passed = Tests.checkDerivative(lambda m : [reg.eval(m), reg.evalDeriv(m)], m, plotIt=False)
passed = Tests.checkDerivative(lambda m: [reg.eval(m),
reg.evalDeriv(m)], m,
plotIt=False)
self.assertTrue(passed)
print 'Check 2 Deriv:', R
passed = Tests.checkDerivative(lambda m : [reg.evalDeriv(m), reg.eval2Deriv(m)], m, plotIt=False)
passed = Tests.checkDerivative(lambda m: [reg.evalDeriv(m),
reg.eval2Deriv(m)], m,
plotIt=False)
self.assertTrue(passed)
def test_regularization_ActiveCells(self):
for R in dir(Regularization):
r = getattr(Regularization, R)
if not inspect.isclass(r): continue
if not inspect.isclass(r):
continue
if not issubclass(r, Regularization.BaseRegularization):
continue
+1 -1
View File
@@ -3,7 +3,7 @@ import unittest
from SimPEG.Tests import OrderTest
import matplotlib.pyplot as plt
#TODO: 'randomTensorMesh'
# TODO: 'randomTensorMesh'
MESHTYPES = ['uniformTensorMesh', 'uniformCurv', 'rotateCurv']
call2 = lambda fun, xyz: fun(xyz[:, 0], xyz[:, 1])
call3 = lambda fun, xyz: fun(xyz[:, 0], xyz[:, 1], xyz[:, 2])