diff --git a/AmpScan/ssm.py b/AmpScan/ssm.py index 18133278dfb58254fb32ad5a9bf45214237f5d46..ed64f69c8dc8e931b334b2982e71cd680023e6c4 100644 --- a/AmpScan/ssm.py +++ b/AmpScan/ssm.py @@ -22,8 +22,8 @@ class pca(object): >>> import os >>> p = pca() >>> p.importFolder(os.getcwd()+"\\tests\\pca_tests") - >>> p.setBaseline(os.getcwd()+"\\tests\\pca_tests\\sample_stl_sphere_BIN.stl") - >>> p.register(save=os.getcwd()+"\\tests\\pca_tests\\") + >>> p.setBaseline(os.getcwd()+stl_file_3.stl) + >stl_file_3.stlcwd()+"\\tests\\pca_tests\\") >>> p.pca() >>> sfs = [1, 2] >>> newS = p.newShape(sfs) diff --git a/tests/__init__py.py b/tests/__init__py.py index f853b103ffe6bfa4d1bd78b353e4be64172815b0..97d12f026e5377bd47b031056e8ee2127f2aaa9b 100644 --- a/tests/__init__py.py +++ b/tests/__init__py.py @@ -1 +1,2 @@ -from tests import * \ No newline at end of file + +from tests.util import get_path \ No newline at end of file diff --git a/tests/sample_stl_sphere_BIN.stl b/tests/stl_file_3.stl similarity index 100% rename from tests/sample_stl_sphere_BIN.stl rename to tests/stl_file_3.stl diff --git a/tests/test_core.py b/tests/test_core.py index c3e97dbe65c3506edfa96a6d720ec4180fcdfd4a..4aba273d1190f43b52cfe8c5b3e90b013d9106ee 100644 --- a/tests/test_core.py +++ b/tests/test_core.py @@ -3,9 +3,9 @@ Testing suite for the core module """ import unittest -import os import numpy as np from random import randrange +from util import get_path class TestCore(unittest.TestCase): @@ -13,10 +13,10 @@ class TestCore(unittest.TestCase): def setUp(self): """Runs before each unit test. - Sets up the AmpObject object using "sample_stl_sphere_BIN.stl". + Sets up the AmpObject object using "stl_file.stl". """ from AmpScan.core import AmpObject - stl_path = self.get_path("sample_stl_sphere_BIN.stl") + stl_path = get_path("stl_file.stl") self.amp = AmpObject(stl_path) def test_centre(self): @@ -165,27 +165,3 @@ class TestCore(unittest.TestCase): with self.assertRaises(ValueError): self.amp.flip(3) - @staticmethod - def get_path(filename): - """Returns the absolute path to a test file - - Parameters - ---------- - filename : string - Name of file in tests to get path to - - Returns - ------- - stl_path : string - The path to the file - """ - - # Check if the parent directory is tests (this is for Pycharm unittests) - if os.path.basename(os.getcwd()) == "tests": - # This is for Pycharm testing - stl_path = filename - else: - # This is for the Gitlab testing - stl_path = os.path.abspath(os.getcwd()) + "\\tests\\"+filename - return stl_path - diff --git a/tests/test_registration.py b/tests/test_registration.py index 6a81ae21b5a23d656514850ead5203cdd8aa8ad1..25f1f819488431218ce6a306fe0197787aeec48e 100644 --- a/tests/test_registration.py +++ b/tests/test_registration.py @@ -3,19 +3,17 @@ Testing suite for the core module """ import unittest -import os -import numpy as np -from random import randrange +from util import get_path -class TestCore(unittest.TestCase): +class TestRegistration(unittest.TestCase): ACCURACY = 5 # The number of decimal places to value accuracy for - needed due to floating point inaccuracies def setUp(self): """Runs before each unit test. - Sets up the AmpObject object using "sample_stl_sphere_BIN.stl". + Sets up the AmpObject object using "stl_file.stl". """ from AmpScan.core import AmpObject - stl_path = self.get_path("sample_stl_sphere_BIN.stl") + stl_path = get_path("stl_file.stl") self.amp = AmpObject(stl_path) diff --git a/tests/test_trim.py b/tests/test_trim.py index 79df0286701040a6fc9bda06d5527db20db6f3c2..f455e0b898c17d913f80e746467ec3e5726344ad 100644 --- a/tests/test_trim.py +++ b/tests/test_trim.py @@ -2,17 +2,17 @@ Testing suite for trim module """ import unittest -import os +from util import get_path class TestTrim(unittest.TestCase): def setUp(self): """Runs before each unit test - Sets up the AmpObject object using "sample_stl_sphere_BIN.stl" + Sets up the AmpObject object using "stl_file.stl" """ from AmpScan.core import AmpObject - stl_path = self.get_path("sample_stl_sphere_BIN.stl") + stl_path = get_path("stl_file.stl") self.amp = AmpObject(stl_path) def test_trim(self): @@ -28,27 +28,3 @@ class TestTrim(unittest.TestCase): self.amp.planarTrim(0.6, plane=0.9) with self.assertRaises(TypeError): self.amp.planarTrim([], plane=[]) - - @staticmethod - def get_path(filename): - """Returns the absolute path to a test file - - Parameters - ---------- - filename : string - Name of file in tests to get path to - - Returns - ------- - stl_path : string - The path to the file - """ - - # Check if the parent directory is tests (this is for Pycharm unittests) - if os.path.basename(os.getcwd()) == "tests": - # This is for Pycharm testing - stl_path = filename - else: - # This is for the Gitlab testing - stl_path = os.path.abspath(os.getcwd()) + "\\tests\\"+filename - return stl_path diff --git a/tests/util.py b/tests/util.py new file mode 100644 index 0000000000000000000000000000000000000000..0bd5488424ea13d562f802ba5ddfbddf58d8a742 --- /dev/null +++ b/tests/util.py @@ -0,0 +1,28 @@ +""" +Common test utilities +""" +import os + + +def get_path(filename): + """Returns the absolute path to a test file + + Parameters + ---------- + filename : string + Name of file in tests to get path to + + Returns + ------- + stl_path : string + The path to the file + """ + + # Check if the parent directory is tests (this is for Pycharm unittests) + if os.path.basename(os.getcwd()) == "tests": + # This is for Pycharm testing + stl_path = filename + else: + # This is for the Gitlab testing + stl_path = os.path.join(os.path.abspath(os.getcwd()), "tests", filename) + return stl_path