From d64fd4ae3558ae1771aa342ed1a8460184b2cd00 Mon Sep 17 00:00:00 2001 From: Rowan Cockett Date: Sat, 2 Jan 2016 18:29:04 -0800 Subject: [PATCH] List examples in the init file. --- SimPEG/Examples/__init__.py | 10 +++++++--- tests/examples/test_examples.py | 4 +--- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/SimPEG/Examples/__init__.py b/SimPEG/Examples/__init__.py index 191664bb..8431e4ba 100644 --- a/SimPEG/Examples/__init__.py +++ b/SimPEG/Examples/__init__.py @@ -12,6 +12,9 @@ import Mesh_QuadTree_Creation import Mesh_QuadTree_FaceDiv import Mesh_QuadTree_HangingNodes import Mesh_Tensor_Creation + +__examples__ = ["EM_FDEM_1D_Inversion", "FLOW_Richards_1D_Celia1990", "Forward_BasicDirectCurrent", "Inversion_Linear", "Mesh_Basic_PlotImage", "Mesh_Basic_Types", "Mesh_Operators_CahnHilliard", "Mesh_QuadTree_Creation", "Mesh_QuadTree_FaceDiv", "Mesh_QuadTree_HangingNodes", "Mesh_Tensor_Creation"] + ##### AUTOIMPORTS ##### if __name__ == '__main__': @@ -30,8 +33,8 @@ if __name__ == '__main__': os.makedirs(docExamplesDir) # Get all the python examples in this folder - thispath = os.path.sep.join(__file__.split(os.path.sep)[:-1]) - onlyfiles = [f[:-3] for f in os.listdir(thispath) if os.path.isfile(os.path.join(thispath, f)) and f.endswith('.py') and not f.startswith('_')] + thispath = os.path.sep.join(__file__.split(os.path.sep)[:-1]) + exfiles = [f[:-3] for f in os.listdir(thispath) if os.path.isfile(os.path.join(thispath, f)) and f.endswith('.py') and not f.startswith('_')] # Add the imports to the top in the AUTOIMPORTS section f = file(__file__, 'r') @@ -44,7 +47,8 @@ if __name__ == '__main__': if line == "##### AUTOIMPORTS #####\n": inimports = not inimports if inimports: - out += '\n'.join(["import %s"%_ for _ in onlyfiles]) + out += '\n'.join(["import %s"%_ for _ in exfiles]) + out += '\n\n__examples__ = ["' + '", "'.join(exfiles)+ '"]\n' out += '\n##### AUTOIMPORTS #####\n' f.close() diff --git a/tests/examples/test_examples.py b/tests/examples/test_examples.py index 48cbaa65..cffa2094 100644 --- a/tests/examples/test_examples.py +++ b/tests/examples/test_examples.py @@ -10,10 +10,8 @@ def get(test): self.assertTrue(True) return func attrs = dict() -tests = [_ for _ in dir(Examples) if not _.startswith('_')] -for test in tests: +for test in Examples.__examples__: attrs['test_'+test] = get(test) -del get, tests, _ TestExamples = type('TestExamples', (unittest.TestCase,), attrs)