From 32c936c4e32aadc1ffd67d84a2618064b192b27e Mon Sep 17 00:00:00 2001 From: Lindsey Heagy Date: Wed, 3 Feb 2016 19:55:42 -0800 Subject: [PATCH 1/3] add test to ensure examples are up to date --- tests/examples/test_examples.py | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/tests/examples/test_examples.py b/tests/examples/test_examples.py index 2e4803b1..8decc683 100644 --- a/tests/examples/test_examples.py +++ b/tests/examples/test_examples.py @@ -1,8 +1,25 @@ 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.realpath(__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'] + + + didpass = pyfiles == Examples.__examples__ + + 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 +27,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() From b81b5af46179569ec6821a001eb338002cb5a3f7 Mon Sep 17 00:00:00 2001 From: Lindsey Heagy Date: Wed, 3 Feb 2016 20:23:31 -0800 Subject: [PATCH 2/3] use abspath for travis --- tests/examples/test_examples.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/examples/test_examples.py b/tests/examples/test_examples.py index 8decc683..1e1da875 100644 --- a/tests/examples/test_examples.py +++ b/tests/examples/test_examples.py @@ -7,7 +7,7 @@ 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.realpath(__file__) + fName = os.path.abspath(__file__) ExamplesDir = os.path.sep.join(fName.split(os.path.sep)[:-3] + ['SimPEG', 'Examples']) files = os.listdir(ExamplesDir) From 5b78d69c6dd8dd71d2e0f918feb203fa5e811e0a Mon Sep 17 00:00:00 2001 From: Lindsey Heagy Date: Thu, 4 Feb 2016 09:11:23 -0800 Subject: [PATCH 3/3] use set diff for testing if all examples have been included --- tests/examples/test_examples.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tests/examples/test_examples.py b/tests/examples/test_examples.py index 1e1da875..edb5600c 100644 --- a/tests/examples/test_examples.py +++ b/tests/examples/test_examples.py @@ -15,8 +15,11 @@ class compareInitFiles(unittest.TestCase): pyfiles = [] [pyfiles.append(py.rstrip('.py')) for py in files if py.endswith('.py') and py != '__init__.py'] + setdiff = set(pyfiles) - set(Examples.__examples__) - didpass = pyfiles == 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")