Merge pull request #229 from simpeg/test/examples

add test to ensure examples are up to date
This commit is contained in:
Lindsey
2016-02-05 11:13:59 -08:00
+21 -1
View File
@@ -1,8 +1,28 @@
import unittest
import sys
import os
from SimPEG import Examples
import numpy as np
class compareInitFiles(unittest.TestCase):
def test_compareInitFiles(self):
print 'Checking that __init__.py up-to-date in SimPEG/Examples'
fName = os.path.abspath(__file__)
ExamplesDir = os.path.sep.join(fName.split(os.path.sep)[:-3] + ['SimPEG', 'Examples'])
files = os.listdir(ExamplesDir)
pyfiles = []
[pyfiles.append(py.rstrip('.py')) for py in files if py.endswith('.py') and py != '__init__.py']
setdiff = set(pyfiles) - set(Examples.__examples__)
print ' Any missing files? ', setdiff
didpass = (setdiff == set())
self.assertTrue(didpass, "Examples not up to date, run 'python __init__.py' from SimPEG/Examples to update")
def get(test):
def test_func(self):
print '\nTesting %s.run(plotIt=False)\n'%test
@@ -10,11 +30,11 @@ def get(test):
self.assertTrue(True)
return test_func
attrs = dict()
for test in Examples.__examples__:
attrs['test_'+test] = get(test)
TestExamples = type('TestExamples', (unittest.TestCase,), attrs)
if __name__ == '__main__':
unittest.main()