From 85d04c885b5f8d2551f77d2afa1e60932e0f5ad7 Mon Sep 17 00:00:00 2001
From: jack-parsons <jack.parsons.uk@icloud.com>
Date: Wed, 24 Jul 2019 11:44:31 +0100
Subject: [PATCH] Adding doctests to core, and fixing the examples

---
 .gitlab-ci.yml     |  4 +++-
 AmpScan/core.py    | 24 +++++++++++++-----------
 tests/stl_file.stl |  3 +++
 tests/test_core.py | 20 ++++++++++++--------
 tests/test_trim.py | 13 ++++++++++---
 5 files changed, 41 insertions(+), 23 deletions(-)
 create mode 100644 tests/stl_file.stl

diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index f60e755..45acf75 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -1,2 +1,4 @@
-tests:
+unittests:
     script: python -m unittest discover tests -v
+doctests:
+    script: python -m doctest -v AmpScan/core.py
diff --git a/AmpScan/core.py b/AmpScan/core.py
index 94d8c46..1e36006 100644
--- a/AmpScan/core.py
+++ b/AmpScan/core.py
@@ -7,10 +7,10 @@ Copyright: Joshua Steer 2018, Joshua.Steer@soton.ac.uk
 
 import numpy as np
 import struct
-from .trim import trimMixin
-from .smooth import smoothMixin
-from .analyse import analyseMixin
-from .ampVis import visMixin
+from AmpScan.trim import trimMixin
+from AmpScan.smooth import smoothMixin
+from AmpScan.analyse import analyseMixin
+from AmpScan.ampVis import visMixin
 
 class AmpObject(trimMixin, smoothMixin, analyseMixin, visMixin):
     r"""
@@ -36,8 +36,9 @@ class AmpObject(trimMixin, smoothMixin, analyseMixin, visMixin):
     
     Examples
     -------
-    >>> fh = 'test.stl'
-    >>> amp = AmpScan.AmpObject(fh)
+    >>> import AmpScan
+    >>> filename = "../tests/stl_file.stl"
+    >>> amp = AmpObject(filename)
 
     """
 
@@ -149,13 +150,13 @@ class AmpObject(trimMixin, smoothMixin, analyseMixin, visMixin):
         
         Examples
         --------
-        >>> fh = 'test.stl'
-        >>> amp = AmpObject(fh, unify=False)
+        >>> filename = "../tests/stl_file.stl"
+        >>> amp = AmpObject(filename, unify=False)
         >>> amp.vert.shape
-        (600, 3)
+        (44832, 3)
         >>> amp.unifyVert()
         >>> amp.vert.shape
-        (125, 3)
+        (7530, 3)
 
         """
         # Requires numpy 1.13
@@ -346,7 +347,8 @@ class AmpObject(trimMixin, smoothMixin, analyseMixin, visMixin):
         
         Examples
         --------
-        >>> amp = AmpObject('test.stl')
+        >>> filename = "../tests/stl_file.stl"
+        >>> amp = AmpObject(filename)
         >>> ang = [np.pi/2, -np.pi/4, np.pi/3]
         >>> amp.rotateAng(ang, ang='rad')
         """
diff --git a/tests/stl_file.stl b/tests/stl_file.stl
new file mode 100644
index 0000000..a05ddf9
--- /dev/null
+++ b/tests/stl_file.stl
@@ -0,0 +1,3 @@
+version https://git-lfs.github.com/spec/v1
+oid sha256:e0d92a552d9a8e48701a9fb05be36b504fe0bf6672e86619e3b8d200b7bcacb5
+size 747284
diff --git a/tests/test_core.py b/tests/test_core.py
index 4c06037..c3e97db 100644
--- a/tests/test_core.py
+++ b/tests/test_core.py
@@ -12,9 +12,8 @@ class TestCore(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"
+        """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")
@@ -166,14 +165,19 @@ class TestCore(unittest.TestCase):
         with self.assertRaises(ValueError):
             self.amp.flip(3)
 
-
     @staticmethod
     def get_path(filename):
-        """
-        Returns the absolute path to the testing files
+        """Returns the absolute path to a test file
+
+        Parameters
+        ----------
+        filename : string
+            Name of file in tests to get path to
 
-        :param filename: Name of the file in tests folder
-        :return: The absolute path to the file
+        Returns
+        -------
+        stl_path : string
+            The path to the file
         """
 
         # Check if the parent directory is tests (this is for Pycharm unittests)
diff --git a/tests/test_trim.py b/tests/test_trim.py
index 74759cd..79df028 100644
--- a/tests/test_trim.py
+++ b/tests/test_trim.py
@@ -31,10 +31,17 @@ class TestTrim(unittest.TestCase):
 
     @staticmethod
     def get_path(filename):
-        """Returns the absolute path to the testing files
+        """Returns the absolute path to a test file
 
-        :param filename: Name of the file in tests folder
-        :return: The absolute path to the 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)
-- 
GitLab