From cdc616398bd034af9e89fae81ad38ced059ad18a Mon Sep 17 00:00:00 2001 From: jack-parsons <jack.parsons.uk@icloud.com> Date: Tue, 23 Jul 2019 15:32:45 +0100 Subject: [PATCH] Setting up Gitlab test runner to use unittest script --- .gitlab-ci.yml | 4 +-- AmpScan/trim.py | 45 ++++++++++++------------ tests/__init__.py | 1 - tests/sample_test.py | 20 ----------- tests/{basic_tests.py => test_basics.py} | 8 ----- tests/{core_tests.py => test_core.py} | 7 ---- tests/test_trim.py | 7 ---- 7 files changed, 25 insertions(+), 67 deletions(-) delete mode 100644 tests/sample_test.py rename tests/{basic_tests.py => test_basics.py} (86%) rename tests/{core_tests.py => test_core.py} (97%) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 27383f6..6faf7a0 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 4a31d59..f48e659 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 13f59fd..e69de29 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 e6846aa..0000000 --- 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 86d6cbd..ba7551a 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 1a4edb5..b1ebb53 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 82c49dd..77e2165 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): -- GitLab