Commit 2f3e8a10 authored by Stephen Thompson's avatar Stephen Thompson

Issue #8 put testing into lint and tidied up

parent b779b51d
......@@ -13,29 +13,29 @@ checks whether the requirement is met.
Requirements
~~~~~~~~~~~~
+------------+--------------------------------------------------------+-------------------------------------+
| ID | Description | Test |
+============+========================================================+=====================================+
| 0000 | Module has a help page | pylint, see |
| | | tests/pylint.rc and tox.ini |
+------------+--------------------------------------------------------+-------------------------------------+
| 0001 | Functions are documented | pylint, see |
| | | tests/pylint.rc and tox.ini |
+------------+--------------------------------------------------------+-------------------------------------+
| 0002 | Package has a version number | handled by versioneer |
+------------+--------------------------------------------------------+-------------------------------------+
| 0003 | Connects and configures, vega, polaris and aurora | test_configure |
+------------+--------------------------------------------------------+-------------------------------------+
| 0004 | Configures via a python dictionary | test_configure |
+------------+--------------------------------------------------------+-------------------------------------+
| 0005 | Provides get frame to get frame of tracking data | test_get_frame |
+------------+--------------------------------------------------------+-------------------------------------+
| 0006 | Get frame returns data as numpy array | test_get_frame |
+------------+--------------------------------------------------------+-------------------------------------+
| 0007 | Supports multiple tracked objects | test_get_frame |
+------------+--------------------------------------------------------+-------------------------------------+
| 0009 | If no tracking available GetFrame Returns NaN | - |
+------------+--------------------------------------------------------+-------------------------------------+
+----------+--------------------------------------------------------+-------------------------------------+
| ID | Description | Test |
+==========+========================================================+=====================================+
| 00 | Module has a help page | pylint, see |
| | | tests/pylint.rc and tox.ini |
+----------+--------------------------------------------------------+-------------------------------------+
| 01 | Functions are documented | pylint, see |
| | | tests/pylint.rc and tox.ini |
+----------+--------------------------------------------------------+-------------------------------------+
| 02 | Package has a version number | handled by versioneer |
+----------+--------------------------------------------------------+-------------------------------------+
| 03 | Connects and configures, vega, polaris and aurora | test_configure |
+----------+--------------------------------------------------------+-------------------------------------+
| 04 | Configures via a python dictionary | test_configure |
+----------+--------------------------------------------------------+-------------------------------------+
| 05 | Provides get frame to get frame of tracking data | test_get_frame |
+----------+--------------------------------------------------------+-------------------------------------+
| 06 | Get frame returns data as numpy array | test_get_frame |
+----------+--------------------------------------------------------+-------------------------------------+
| 07 | Supports multiple tracked objects | test_get_frame |
+----------+--------------------------------------------------------+-------------------------------------+
| 09 | If no tracking available GetFrame Returns NaN | - |
+----------+--------------------------------------------------------+-------------------------------------+
......
......@@ -447,13 +447,13 @@ class NDITracker:
def get_tool_descriptions(self):
""" Returns the port handles and tool descriptions """
descriptions = full((len(self._tool_descriptors), 2), "empty",
dtype=object)
descriptions = []
port_handles = []
for i in range(len(self._tool_descriptors)):
descriptions[i, 0] = i
descriptions[i, 1] = self._tool_descriptors[i].get("description")
descriptions.append(i)
port_handles.append(self._tool_descriptors[i].get("description"))
return descriptions
return port_handles, descriptions
def start_tracking(self):
"""
......
......@@ -2,13 +2,18 @@
"""scikit-surgerynditracker tests"""
#what testing can we do with out being attached to a tracker?
#What testing can we do when we are attached to a tracker?
#We could build a fake ndi tracker, that listens on a port
#and responds appropriately.
import pytest
from sksurgerynditracker.nditracker import NDITracker
#configuration.
SETTINGS_VEGA = {
"tracker type": "vega",
"ip address" : "192.168.2.17",
"ip address" : "999.999.999.999",
"port" : 8765,
"romfiles" : [
"../data/something_else.rom",
......@@ -31,25 +36,38 @@ SETTINGS_DUMMY = {
}
def test_connect():
#what testing can we do with out being attached to a tracker?
#What testing can we do when we are attached to a tracker?
#We could build a fake ndi tracker, that listens on a port
#and responds appropriately.
"""
connects and configures ,
reqs: 03, 04
"""
tracker = NDITracker(SETTINGS_DUMMY)
tracker.close()
def test_connect_network():
"""
connects and configures, throws error when no vega
reqs: 03, 04
"""
with pytest.raises(IOError):
tracker = NDITracker(SETTINGS_VEGA)
del tracker
def test_connect_serial():
"""
connects and configures, throws error when no serial
reqs: 03, 04
"""
tracker = None
with pytest.raises(IOError):
tracker = NDITracker(SETTINGS_POLARIS)
del tracker
def test_configure():
"""
connects and configures, throws errors when when errors in dictionary
reqs: 03, 04
"""
no_rom = {
"tracker type": "polaris",
}
......@@ -61,7 +79,7 @@ def test_configure():
"tracker type": "optotrack",
}
with pytest.raises(ValueError):
tracker = NDITracker (bad_tracker)
tracker = NDITracker(bad_tracker)
del tracker
no_ip = {
......@@ -82,34 +100,37 @@ def test_configure():
del tracker
with pytest.raises(IOError) or pytest.raises(OSError):
aurora = { "tracker type": "aurora" }
aurora = {"tracker type": "aurora"}
tracker = NDITracker(aurora)
del tracker
with pytest.raises(IOError) or pytest.raises(OSError):
aurora_sp = { "tracker type": "aurora",
"serial_port": "1" }
aurora_sp = {"tracker type": "aurora",
"serial_port": "1"}
tracker = NDITracker(aurora_sp)
del tracker
with pytest.raises(IOError) or pytest.raises(OSError):
aurora_np = { "tracker type": "aurora",
"ports to probe": "50" }
aurora_np = {"tracker type": "aurora",
"ports to probe": "50"}
tracker = NDITracker(aurora_np)
del tracker
def test_close():
tracker = NDITracker(SETTINGS_DUMMY)
tracker.close()
del tracker
def test_read_sroms_from_file():
"""
read sroms throws errors when when no sroms
reqs:
"""
tracker = NDITracker(SETTINGS_DUMMY)
with pytest.raises(ValueError):
tracker._read_sroms_from_file()
tracker.close()
def test_initialise_ports():
"""
initialise ports throws errors when when no device
reqs:
"""
tracker = NDITracker(SETTINGS_DUMMY)
tracker._device = None
with pytest.raises(ValueError):
......@@ -118,6 +139,10 @@ def test_initialise_ports():
tracker.close()
def test_enable_tools():
"""
Enable ports throws errors when when no device
reqs:
"""
tracker = NDITracker(SETTINGS_DUMMY)
tracker._device = None
with pytest.raises(ValueError):
......@@ -126,11 +151,15 @@ def test_enable_tools():
tracker.close()
def test_get_frame():
"""
test get frame returns numpy array
reqs:05, 06
"""
tracker = NDITracker(SETTINGS_DUMMY)
port_handles, timestamps, framenumbers, \
tracking, tracking_quality = tracker.get_frame()
_port_handles, _timestamps, _framenumbers, \
tracking, _tracking_quality = tracker.get_frame()
assert len(tracking) == 0
assert not tracking
del tracker
dummy_two_rom = {
......@@ -141,16 +170,20 @@ def test_get_frame():
}
tracker = NDITracker(dummy_two_rom)
port_handles, timestamps, framenumbers, \
tracking, tracking_quality = tracker.get_frame()
_port_handles, _timestamps, _framenumbers, \
tracking, _tracking_quality = tracker.get_frame()
assert len(tracking) == 2
assert tracking[0].shape == (4,4)
assert tracking[0].shape == (4, 4)
assert tracking[0].dtype == 'float64'
def test_get_tool_descriptions():
"""
test get tool descriptions
reqs:05, 06
"""
tracker = NDITracker(SETTINGS_DUMMY)
descriptions = tracker.get_tool_descriptions()
assert len(descriptions) == 0
_port_handles, descriptions = tracker.get_tool_descriptions()
assert not descriptions
del tracker
dummy_two_rom = {
......@@ -161,24 +194,35 @@ def test_get_tool_descriptions():
}
tracker = NDITracker(dummy_two_rom)
descriptions = tracker.get_tool_descriptions()
_port_handles, descriptions = tracker.get_tool_descriptions()
assert len(descriptions) == 2
def test_start_tracking():
"""
test start tracking
reqs:
"""
tracker = NDITracker(SETTINGS_DUMMY)
with pytest.raises(ValueError):
tracker.start_tracking()
tracker.close()
def test_stop_tracking():
"""
test stop tracking
reqs:
"""
tracker = NDITracker(SETTINGS_DUMMY)
with pytest.raises(ValueError):
tracker.stop_tracking()
tracker.close()
def test_check_for_errors():
"""
test check for errors
reqs:
"""
tracker = NDITracker(SETTINGS_DUMMY)
with pytest.raises(ValueError):
tracker._check_for_errors("dummy error")
tracker.close()
......@@ -13,14 +13,14 @@ deps=-rrequirements-dev.txt
whitelist_externals=coverage,pip
# See .coveragerc for list of omitted files
commands = coverage erase
coverage run -a --source ./sksurgerynditracker -m pytest
coverage run -a --source ./sksurgerynditracker -m pytest -s -v
coverage report -m
[testenv:lint]
basepython=python3.6
deps=pylint
{[testenv]deps}
commands=pylint --rcfile=tests/pylintrc sksurgerynditracker
commands=pylint --rcfile=tests/pylintrc sksurgerynditracker tests
[testenv:docs]
basepython=python3.6
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment