From 68b4719aea6092e9ab8f174f7a11c246a6a60aa6 Mon Sep 17 00:00:00 2001 From: Rowan Cockett Date: Tue, 9 Jul 2013 22:00:17 -0700 Subject: [PATCH] Ability to run all tests at once. Removed __init__.py added runTests.py and .sh so that we can run all tests at one time. --- code/tests/__init__.py | 3 --- code/tests/runTests.py | 11 +++++++++++ code/tests/runTests.sh | 3 +++ code/tests/test_basemesh.py | 2 +- code/utils.py | 16 +++++++--------- 5 files changed, 22 insertions(+), 13 deletions(-) delete mode 100644 code/tests/__init__.py create mode 100644 code/tests/runTests.py create mode 100644 code/tests/runTests.sh diff --git a/code/tests/__init__.py b/code/tests/__init__.py deleted file mode 100644 index 80b21e43..00000000 --- a/code/tests/__init__.py +++ /dev/null @@ -1,3 +0,0 @@ -# init.py - -from test_mesh import * \ No newline at end of file diff --git a/code/tests/runTests.py b/code/tests/runTests.py new file mode 100644 index 00000000..b6662f00 --- /dev/null +++ b/code/tests/runTests.py @@ -0,0 +1,11 @@ +import glob +import unittest + +# This code will run all tests in directory named test_*.py + +test_file_strings = glob.glob('test_*.py') +module_strings = [str[0:len(str)-3] for str in test_file_strings] +suites = [unittest.defaultTestLoader.loadTestsFromName(str) for str + in module_strings] +testSuite = unittest.TestSuite(suites) +text_runner = unittest.TextTestRunner().run(testSuite) diff --git a/code/tests/runTests.sh b/code/tests/runTests.sh new file mode 100644 index 00000000..9bd83e67 --- /dev/null +++ b/code/tests/runTests.sh @@ -0,0 +1,3 @@ +#!/bin/sh + +python -m unittest discover \ No newline at end of file diff --git a/code/tests/test_basemesh.py b/code/tests/test_basemesh.py index 88655c60..9aece19b 100644 --- a/code/tests/test_basemesh.py +++ b/code/tests/test_basemesh.py @@ -5,7 +5,7 @@ from BaseMesh import BaseMesh import numpy as np -class TestMeshNumbers3D(unittest.TestCase): +class TestBaseMesh(unittest.TestCase): def setUp(self): self.mesh = BaseMesh([6, 2, 3]) diff --git a/code/utils.py b/code/utils.py index a41d8687..a5b877cb 100644 --- a/code/utils.py +++ b/code/utils.py @@ -75,9 +75,15 @@ def mkvc(x, numDims=1): return x.flatten(order='F')[:, np.newaxis, np.newaxis] -def ndgrid(xin): +def ndgrid(*args): """Form tensorial grid for 1, 2 and 3 dimensions. Return X1,X2,X3 arrays depending on the dimension""" + # you can either pass a list [x1, x2, x3] or each seperately + if type(args[0]) == list: + xin = args[0] + else: + xin = args + if len(xin) == 1: return xin elif len(xin) == 2: @@ -88,14 +94,6 @@ def ndgrid(xin): return np.c_[X1, X2, X3] -def flattenF(x): - return np.flatten(x, order='F') - - -def printF(x): - pass - - def ind2sub(shape, ind): # From the given shape, returns the subscrips of the given index revshp = []