From 67de92fe32998162c9e09eba238867d2af3434e4 Mon Sep 17 00:00:00 2001
From: jack-parsons <jack.parsons.uk@icloud.com>
Date: Thu, 25 Jul 2019 16:49:53 +0100
Subject: [PATCH] Cleaning up and refactoring test modules

---
 AmpScan/ssm.py                                |  4 +--
 tests/__init__py.py                           |  3 +-
 ...mple_stl_sphere_BIN.stl => stl_file_3.stl} |  0
 tests/test_core.py                            | 30 ++-----------------
 tests/test_registration.py                    | 10 +++----
 tests/test_trim.py                            | 30 ++-----------------
 tests/util.py                                 | 28 +++++++++++++++++
 7 files changed, 42 insertions(+), 63 deletions(-)
 rename tests/{sample_stl_sphere_BIN.stl => stl_file_3.stl} (100%)
 create mode 100644 tests/util.py

diff --git a/AmpScan/ssm.py b/AmpScan/ssm.py
index 1813327..ed64f69 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 f853b10..97d12f0 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 c3e97db..4aba273 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 6a81ae2..25f1f81 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 79df028..f455e0b 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 0000000..0bd5488
--- /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
-- 
GitLab