diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 27383f6b89156cdc24bc8f40ef7cb91ed08f7c20..6faf7a0f45245a8fc590d967884b6268d78c5928 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -1,2 +1,2 @@ -sample_job: - script: python tests/sample_test.py +tests: + script: python -m unittest -v diff --git a/AmpScan/trim.py b/AmpScan/trim.py index 4a31d59df107fdec8753a9d8876ea40624b77fe5..f48e659560bbcab21b29d032b7ae6f59cc7025ab 100644 --- a/AmpScan/trim.py +++ b/AmpScan/trim.py @@ -5,6 +5,7 @@ Copyright: Joshua Steer 2018, Joshua.Steer@soton.ac.uk """ import numpy as np +from numbers import Number class trimMixin(object): r""" @@ -30,26 +31,26 @@ class trimMixin(object): >>> amp.planarTrim(100, 2) """ -# if isinstance(height, float): + if isinstance(height, Number): # planar values for each vert on face - fv = self.vert[self.faces, plane] - # Number points on each face are above cut plane - fvlogic = (fv > height).sum(axis=1) - # Faces with points both above and below cut plane - adjf = self.faces[np.logical_or(fvlogic == 2, fvlogic == 1)] - # Get adjacent vertices - adjv = np.unique(adjf) - # Get vert above height and set to height - abvInd = adjv[self.vert[adjv, plane] > height] - self.vert[abvInd, plane] = height - # Find all verts above plane - delv = self.vert[:, plane] > height - # Reorder verts to account for deleted one - vInd = np.cumsum(~delv) - 1 - self.faces = self.faces[fvlogic != 3, :] - self.faces = vInd[self.faces] - self.vert = self.vert[~delv, :] - self.values = self.values[~delv] - self.calcStruct() -# else: -# raise TypeError("height arg must be a float") \ No newline at end of file + fv = self.vert[self.faces, plane] + # Number points on each face are above cut plane + fvlogic = (fv > height).sum(axis=1) + # Faces with points both above and below cut plane + adjf = self.faces[np.logical_or(fvlogic == 2, fvlogic == 1)] + # Get adjacent vertices + adjv = np.unique(adjf) + # Get vert above height and set to height + abvInd = adjv[self.vert[adjv, plane] > height] + self.vert[abvInd, plane] = height + # Find all verts above plane + delv = self.vert[:, plane] > height + # Reorder verts to account for deleted one + vInd = np.cumsum(~delv) - 1 + self.faces = self.faces[fvlogic != 3, :] + self.faces = vInd[self.faces] + self.vert = self.vert[~delv, :] + self.values = self.values[~delv] + self.calcStruct() + else: + raise TypeError("height arg must be a float") \ No newline at end of file diff --git a/tests/__init__.py b/tests/__init__.py index 13f59fdb4e741c39be57410a90e722e8833c45fb..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 100644 --- a/tests/__init__.py +++ b/tests/__init__.py @@ -1 +0,0 @@ -from tests import core_tests, basic_tests diff --git a/tests/sample_test.py b/tests/sample_test.py deleted file mode 100644 index e6846aaf9fa33706eaedebec0aae7a8fd9e3a9fc..0000000000000000000000000000000000000000 --- a/tests/sample_test.py +++ /dev/null @@ -1,20 +0,0 @@ -import unittest -import core_tests -import basic_tests - - -def suite(): - """ - Get all the unittests for the whole project - :return: The suite containing the test suites for each module - """ - s = unittest.TestSuite() - # Add the tests to the suite - s.addTest(core_tests.suite()) - s.addTest(basic_tests.suite()) - return s - - -if __name__ == '__main__': - # Run the test suites - unittest.TextTestRunner().run(suite()) diff --git a/tests/basic_tests.py b/tests/test_basics.py similarity index 86% rename from tests/basic_tests.py rename to tests/test_basics.py index 86d6cbdb5bc82cda0e8290d92f35cc6499e82f98..ba7551aedffedd553704ba0973c582879e74663b 100644 --- a/tests/basic_tests.py +++ b/tests/test_basics.py @@ -6,13 +6,6 @@ import os import sys -def suite(): - """ - Build testing suite from unittests in module - """ - return unittest.TestLoader().loadTestsFromTestCase(TestBasicFunction) - - class TestBasicFunction(unittest.TestCase): def test_setup(self): @@ -24,7 +17,6 @@ class TestBasicFunction(unittest.TestCase): """ Test that the suite is running correctly """ - print("Running sample_test.py") self.assertTrue(True) def test_python_imports(self): diff --git a/tests/core_tests.py b/tests/test_core.py similarity index 97% rename from tests/core_tests.py rename to tests/test_core.py index 1a4edb50715f4033ada1a59a0e7d840d3f859f07..b1ebb53eec1e7038f46803c9285bb10ec0bf0ef1 100644 --- a/tests/core_tests.py +++ b/tests/test_core.py @@ -8,13 +8,6 @@ import numpy as np from random import randrange -def suite(): - """ - Build testing suite from unittests in module - """ - return unittest.TestLoader().loadTestsFromTestCase(TestCore) - - class TestCore(unittest.TestCase): ACCURACY = 5 # The number of decimal places to value accuracy for - needed due to floating point inaccuracies diff --git a/tests/test_trim.py b/tests/test_trim.py index 82c49dd8d05e7001c1c05483e63487059ad8ff5b..77e2165f98d9101dda9dba60867b75254d3d92e8 100644 --- a/tests/test_trim.py +++ b/tests/test_trim.py @@ -5,13 +5,6 @@ import unittest import os -def suite(): - """ - Build testing suite from unittests in module - """ - return unittest.TestLoader().loadTestsFromTestCase(TestTrim) - - class TestTrim(unittest.TestCase): def setUp(self):