-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Issue #31 added mocks and tests to cover most of get_frame
- Loading branch information
1 parent
370bdfc
commit e10d6f2
Showing
4 changed files
with
141 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
# coding=utf-8 | ||
|
||
"""scikit-surgerynditracker mocks for polaris""" | ||
|
||
import ndicapy | ||
|
||
SETTINGS_POLARIS = { | ||
"tracker type": "polaris", | ||
"ports to probe": 20, | ||
"romfiles" : [ | ||
"data/something_else.rom", | ||
"data/8700339.rom"] | ||
} | ||
|
||
class MockPort: | ||
"""A fake serial port for ndi""" | ||
device = 'bad port' | ||
|
||
def mockndiProbe(port_name): #pylint:disable=invalid-name | ||
"""Mock of ndiProbe""" | ||
if port_name == 'good port': | ||
return ndicapy.NDI_OKAY | ||
return ndicapy.NDI_PROBE_FAIL | ||
|
||
def mockndiOpen(port_name): #pylint:disable=invalid-name | ||
"""Mock of ndiOpen""" | ||
if port_name == 'good port': | ||
return True | ||
return False | ||
|
||
def mockndiOpen_fail(port_name): #pylint:disable=invalid-name | ||
"""Mock of ndiOpen that always fail""" | ||
if port_name == 'good port': | ||
return False | ||
return False | ||
|
||
def mockndiGetError(_device): #pylint:disable=invalid-name | ||
"""Mock of ndiGetError""" | ||
return ndicapy.NDI_OKAY | ||
|
||
def mockComports(): #pylint:disable=invalid-name | ||
"""Returns a list of mock comports""" | ||
mock_ports = [MockPort]*20 | ||
mock_ports[5].device = 'good port' | ||
return mock_ports | ||
|
||
def mockndiGetPHSRNumberOfHandles(_device): #pylint:disable=invalid-name | ||
"""Mock of ndiGetPHSRNumberOfHandles""" | ||
return 4 | ||
|
||
def mockndiGetPHRQHandle(_device): #pylint:disable=invalid-name | ||
"""Mock of ndiGetPHRQHandle""" | ||
return int(0) | ||
|
||
def mockndiGetPHSRHandle(_device, index): #pylint:disable=invalid-name | ||
"""Mock of ndiGetPHSRHandle""" | ||
return int(index) | ||
|
||
def mockndiVER(_device, _other_arg): #pylint:disable=invalid-name | ||
"""Mock of ndiVER""" | ||
return 'Mock for Testing' | ||
|
||
def mockndiGetBXFrame(_device, _port_handle): #pylint:disable=invalid-name | ||
"""Mock of ndiGetBXFrame""" | ||
bx_frame_count = 0 | ||
return bx_frame_count | ||
|
||
def mockndiGetBXTransform(_device, _port_handle): #pylint:disable=invalid-name | ||
"""Mock of ndiGetBXTransform""" | ||
return [0,0,0,0,0,0,0,0] | ||
|
||
def mockndiGetBXTransformMissing(_device, _port_handle): #pylint:disable=invalid-name | ||
"""Mock of ndiGetBXTransform""" | ||
return "MISSING" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
# coding=utf-8 | ||
|
||
"""scikit-surgerynditracker tests using a mocked ndicapy""" | ||
from sksurgerynditracker.nditracker import NDITracker | ||
|
||
from tests.polaris_mocks import SETTINGS_POLARIS, mockndiProbe, \ | ||
mockndiOpen, mockndiGetError, mockComports, \ | ||
mockndiGetPHSRNumberOfHandles, mockndiGetPHRQHandle, \ | ||
mockndiGetPHSRHandle, mockndiVER, mockndiGetBXFrame, \ | ||
mockndiGetBXTransform, mockndiGetBXTransformMissing | ||
|
||
def test_getframe_polaris_mock(mocker): | ||
""" | ||
connects and configures, mocks ndicapy.ndiProbe to pass | ||
reqs: 03, 04 | ||
""" | ||
tracker = None | ||
mocker.patch('serial.tools.list_ports.comports', mockComports) | ||
mocker.patch('ndicapy.ndiProbe', mockndiProbe) | ||
mocker.patch('ndicapy.ndiOpen', mockndiOpen) | ||
mocker.patch('ndicapy.ndiCommand') | ||
mocker.patch('ndicapy.ndiGetError', mockndiGetError) | ||
mocker.patch('ndicapy.ndiClose') | ||
mocker.patch('ndicapy.ndiGetPHSRNumberOfHandles', | ||
mockndiGetPHSRNumberOfHandles) | ||
mocker.patch('ndicapy.ndiGetPHRQHandle', mockndiGetPHRQHandle) | ||
mocker.patch('ndicapy.ndiPVWRFromFile') | ||
mocker.patch('ndicapy.ndiGetPHSRHandle', mockndiGetPHSRHandle) | ||
mocker.patch('ndicapy.ndiVER', mockndiVER) | ||
mocker.patch('ndicapy.ndiGetBXFrame', mockndiGetBXFrame) | ||
mocker.patch('ndicapy.ndiGetBXTransform', mockndiGetBXTransform) | ||
|
||
tracker = NDITracker(SETTINGS_POLARIS) | ||
tracker.get_frame() | ||
|
||
del tracker | ||
|
||
def test_getframe_missing(mocker): | ||
""" | ||
connects and configures, mocks ndicapy.ndiProbe to pass | ||
reqs: 03, 04 | ||
""" | ||
tracker = None | ||
mocker.patch('serial.tools.list_ports.comports', mockComports) | ||
mocker.patch('ndicapy.ndiProbe', mockndiProbe) | ||
mocker.patch('ndicapy.ndiOpen', mockndiOpen) | ||
mocker.patch('ndicapy.ndiCommand') | ||
mocker.patch('ndicapy.ndiGetError', mockndiGetError) | ||
mocker.patch('ndicapy.ndiClose') | ||
mocker.patch('ndicapy.ndiGetPHSRNumberOfHandles', | ||
mockndiGetPHSRNumberOfHandles) | ||
mocker.patch('ndicapy.ndiGetPHRQHandle', mockndiGetPHRQHandle) | ||
mocker.patch('ndicapy.ndiPVWRFromFile') | ||
mocker.patch('ndicapy.ndiGetPHSRHandle', mockndiGetPHSRHandle) | ||
mocker.patch('ndicapy.ndiVER', mockndiVER) | ||
mocker.patch('ndicapy.ndiGetBXFrame', mockndiGetBXFrame) | ||
mocker.patch('ndicapy.ndiGetBXTransform', mockndiGetBXTransformMissing) | ||
|
||
tracker = NDITracker(SETTINGS_POLARIS) | ||
tracker.get_frame() | ||
|
||
del tracker |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters