From ccf7f33a2c96b1508e95a9af4f9e5801faac2b0f Mon Sep 17 00:00:00 2001
From: jack-parsons <jack.parsons.uk@icloud.com>
Date: Tue, 23 Jul 2019 11:50:22 +0100
Subject: [PATCH] Refactoring tests and adding documentation

---
 tests/basic_tests.py | 18 +++++++++++++++--
 tests/core_tests.py  | 34 +++++++++++++++----------------
 tests/test_trim.py   | 48 ++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 80 insertions(+), 20 deletions(-)
 create mode 100644 tests/test_trim.py

diff --git a/tests/basic_tests.py b/tests/basic_tests.py
index 472616b..43db51f 100644
--- a/tests/basic_tests.py
+++ b/tests/basic_tests.py
@@ -1,24 +1,35 @@
+"""
+Testing suite for basic functionality
+"""
 import unittest
 import os
 import sys
 
 
 def suite():
+    """
+    Build testing suite from unittests in module
+    """
     return unittest.TestLoader().loadTestsFromTestCase(TestBasicFunction)
 
 
 class TestBasicFunction(unittest.TestCase):
-    ACCURACY = 3  # The number of decimal places to value accuracy for
 
-    def SetUp(self):
+    def test_setup(self):
         modPath = os.path.abspath(os.getcwd())
         sys.path.insert(0, modPath)
 
     def test_running(self):
+        """
+        Test that the suite is running correctly
+        """
         print("Running sample_test.py")
         self.assertTrue(True)
 
     def test_python_imports(self):
+        """
+        Test imports
+        """
         import numpy, scipy, matplotlib, vtk, AmpScan.core
         s = str(type(numpy))
         self.assertEqual(s, "<class 'module'>")
@@ -33,5 +44,8 @@ class TestBasicFunction(unittest.TestCase):
 
     @unittest.expectedFailure
     def test_failure(self):
+        """
+        Test expected failure functionality of test suite
+        """
         s = str(type("string"))
         self.assertEqual(s, "<class 'module'>")
diff --git a/tests/core_tests.py b/tests/core_tests.py
index e8f8831..2007ed5 100644
--- a/tests/core_tests.py
+++ b/tests/core_tests.py
@@ -1,19 +1,20 @@
-# -*- coding: utf-8 -*-
 """
 Testing suite for the core functionality
 """
 
 import unittest
 import os
-import sys
 
 
 def suite():
+    """
+    Build testing suite from unittests in module
+    """
     return unittest.TestLoader().loadTestsFromTestCase(TestCore)
 
 
 class TestCore(unittest.TestCase):
-    ACCURACY = 3  # The number of decimal places to value accuracy for
+    ACCURACY = 5  # The number of decimal places to value accuracy for
 
     def setUp(self):
         """
@@ -38,29 +39,26 @@ class TestCore(unittest.TestCase):
         self.assertTrue(all(centre[i] < (10**-TestCore.ACCURACY) for i in range(3)))
 
     def test_rotate(self):
+        """
+        Tests the rotate method of AmpObject
+        """
         s = str(type(self.amp))
         self.assertEqual(s, "<class 'AmpScan.core.AmpObject'>", "Not expected Object")
         with self.assertRaises(TypeError):
             self.amp.rotateAng(7)
             self.amp.rotateAng({})
 
-    def test_trim(self):
-        # a new test for the trim module
-        stlPath = self.get_path("sample_stl_sphere_BIN.stl")
-        from AmpScan.core import AmpObject
-        Amp = AmpObject(stlPath)
-        #with self.assertRaises(TypeError):
-            #Amp.planarTrim([], plane=[])
-
     def test_translate(self):
-        # Test translating method of AmpObject
+        """
+        Test translating method of AmpObject
+        """
 
         # Check that everything has been translated correctly to a certain accuracy
         start = self.amp.vert.mean(axis=0)[:]
         self.amp.translate([1, -1, 0])
         end = self.amp.vert.mean(axis=0)[:]
-        self.assertAlmostEqual(start[0], end[0]-1, places=TestCore.ACCURACY)
-        self.assertAlmostEqual(start[1], end[1]+1, places=TestCore.ACCURACY)
+        self.assertAlmostEqual(start[0]+1, end[0], places=TestCore.ACCURACY)
+        self.assertAlmostEqual(start[1]-1, end[1], places=TestCore.ACCURACY)
         self.assertAlmostEqual(start[2], end[2], places=TestCore.ACCURACY)
 
         # Check that translating raises TypeError when translating with an invalid type
@@ -77,7 +75,7 @@ class TestCore(unittest.TestCase):
 
     def get_path(self, filename):
         """
-        Method to get the absolute path to the testing files
+        Returns the absolute path to the testing files
 
         :param filename: Name of the file in tests folder
         :return: The absolute path to the file
@@ -86,9 +84,9 @@ class TestCore(unittest.TestCase):
         # Check if the parent directory is tests (this is for Pycharm unittests)
         if os.path.basename(os.getcwd()) == "tests":
             # This is for Pycharm testing
-            stlPath = filename
+            stl_path = filename
         else:
             # This is for the Gitlab testing
-            stlPath = os.path.abspath(os.getcwd()) + "\\tests\\"+filename
-        return stlPath
+            stl_path = os.path.abspath(os.getcwd()) + "\\tests\\"+filename
+        return stl_path
 
diff --git a/tests/test_trim.py b/tests/test_trim.py
new file mode 100644
index 0000000..169bc41
--- /dev/null
+++ b/tests/test_trim.py
@@ -0,0 +1,48 @@
+"""
+Testing suite for trim module
+"""
+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):
+        """
+        Runs before each unit test
+        Sets up the AmpObject object using "sample_stl_sphere_BIN.stl"
+        """
+        from AmpScan.core import AmpObject
+        stl_path = self.get_path("sample_stl_sphere_BIN.stl")
+        self.amp = AmpObject(stl_path)
+
+    def test_trim(self):
+        """
+        a new test for the trim module
+        """
+        with self.assertRaises(TypeError):
+            self.amp.planarTrim([], plane=[])
+
+    def get_path(self, filename):
+        """
+        Returns the absolute path to the testing files
+
+        :param filename: Name of the file in tests folder
+        :return: The absolute 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
-- 
GitLab