-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Issue #46: Added tests for new UI apps.
- Loading branch information
1 parent
1ee579d
commit a594a73
Showing
4 changed files
with
148 additions
and
0 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,19 @@ | ||
"""Tests for command line application """ | ||
import pytest | ||
from sksurgerycalibration.ui.video_calibration_command_line import main | ||
|
||
def test_cl_no_config(): | ||
""" Run command line app with no config file. The parser should | ||
raise SystemExit due to missing required argument""" | ||
with pytest.raises(SystemExit) as pytest_wrapped_e: | ||
main([]) | ||
|
||
#I'm not sure how useful the next 2 asserts are. We already know it's | ||
#a SystemExit, if the code value specific to the parser? | ||
assert pytest_wrapped_e.type == SystemExit | ||
assert pytest_wrapped_e.value.code == 2 | ||
|
||
|
||
def test_cl_with_config(): | ||
""" Run command line app with config """ | ||
main(['-c', 'config/recorded_chessboard.json']) |
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,60 @@ | ||
"""Tests for command line application """ | ||
import copy | ||
import os | ||
import pytest | ||
from sksurgerycalibration.ui.video_calibration_app import run_video_calibration | ||
|
||
config = { "method": "chessboard", | ||
"source": "tests/data/laparoscope_calibration/left/left.ogv", | ||
"corners": [14, 10], | ||
"square size in mm": 6, | ||
"minimum number of views": 5, | ||
"keypress delay": 0, | ||
"interactive" : False, | ||
"sample frequency" : 2 | ||
} | ||
|
||
def _clean_up(prefix): | ||
"""Helper to clean up calibration results""" | ||
for i in range(5): | ||
os.remove(prefix + ".extrinsics." + str(i) + ".txt") | ||
os.remove(prefix + ".ids." + str(i) + ".txt") | ||
os.remove(prefix + ".image_points." + str(i) + ".txt") | ||
os.remove(prefix + ".object_points." + str(i) + ".txt") | ||
os.remove(prefix + ".images." + str(i) + ".png") | ||
os.remove(prefix + ".distortion.txt") | ||
os.remove(prefix + ".handeye.txt") | ||
os.remove(prefix + ".intrinsics.txt") | ||
os.remove(prefix + ".pattern2marker.txt") | ||
|
||
|
||
def test_with_save_prefix(): | ||
""" Run command line app with a save prefix""" | ||
run_video_calibration(config, prefix = "testjunk") | ||
_clean_up("testjunk") | ||
|
||
def test_with_save_directory(): | ||
""" Run command line app with a save prefix""" | ||
run_video_calibration(config, save_dir = "testjunk") | ||
_clean_up("testjunk/calib") | ||
os.rmdir("testjunk") | ||
|
||
def test_with_invalid_method(): | ||
"""Should throw a value error if method is not supported""" | ||
duff_config = copy.deepcopy(config) | ||
duff_config['method'] = 'not chessboard' | ||
with pytest.raises(ValueError): | ||
run_video_calibration(duff_config) | ||
|
||
def test_with_invalid_capture(): | ||
"""Should throw a runtime error if we can't open video capture""" | ||
duff_config = copy.deepcopy(config) | ||
duff_config['source'] = 'bad source' | ||
with pytest.raises(RuntimeError): | ||
run_video_calibration(duff_config) | ||
|
||
def test_with_custome_window_size(): | ||
"""We should be able to set the window size in config""" | ||
ok_config = copy.deepcopy(config) | ||
ok_config['window size'] = [640, 480] | ||
run_video_calibration(ok_config) |
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,21 @@ | ||
"""Tests for command line application """ | ||
import pytest | ||
from sksurgerycalibration.ui.video_calibration_checker_command_line import main | ||
|
||
def test_cl_no_config(): | ||
""" Run command line app with no config file. The parser should | ||
raise SystemExit due to missing required argument""" | ||
with pytest.raises(SystemExit) as pytest_wrapped_e: | ||
main([]) | ||
|
||
#I'm not sure how useful the next 2 asserts are. We already know it's | ||
#a SystemExit, if the code value specific to the parser? | ||
assert pytest_wrapped_e.type == SystemExit | ||
assert pytest_wrapped_e.value.code == 2 | ||
|
||
|
||
def test_cl_with_config(): | ||
""" Run command line app with config """ | ||
main(['-c', 'config/recorded_chessboard.json', | ||
'-d', 'tests/data/laparoscope_calibration/cbh-viking/', | ||
'-p', 'calib.left']) |
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,48 @@ | ||
"""Tests for command line application """ | ||
import copy | ||
import pytest | ||
from sksurgerycalibration.ui.video_calibration_checker_app import \ | ||
run_video_calibration_checker | ||
|
||
config = { "method": "chessboard", | ||
"source": "tests/data/laparoscope_calibration/left/left.ogv", | ||
"corners": [14, 10], | ||
"square size in mm": 6, | ||
"minimum number of views": 5, | ||
"keypress delay": 0, | ||
"interactive" : False, | ||
"sample frequency" : 2 | ||
} | ||
|
||
def test_with_no_config(): | ||
"""It shouldn't run with no configuration file""" | ||
with pytest.raises(ValueError): | ||
run_video_calibration_checker(None, | ||
calib_dir = 'tests/data/laparoscope_calibration/cbh-viking', | ||
prefix = "calib.right") | ||
|
||
|
||
def test_with_prefix(): | ||
""" Run command line app with an existing calibration""" | ||
run_video_calibration_checker(config, | ||
calib_dir = 'tests/data/laparoscope_calibration/cbh-viking', | ||
prefix = "calib.right") | ||
|
||
|
||
def test_with_invalid_capture(): | ||
"""Should throw a runtime error if we can't open video capture""" | ||
duff_config = copy.deepcopy(config) | ||
duff_config['source'] = 'bad source' | ||
with pytest.raises(RuntimeError): | ||
run_video_calibration_checker(duff_config, | ||
calib_dir = 'tests/data/laparoscope_calibration/cbh-viking', | ||
prefix = "calib.right") | ||
|
||
|
||
def test_with_custome_window_size(): | ||
"""We should be able to set the window size in config""" | ||
ok_config = copy.deepcopy(config) | ||
ok_config['window size'] = [640, 480] | ||
run_video_calibration_checker(ok_config, | ||
calib_dir = 'tests/data/laparoscope_calibration/cbh-viking', | ||
prefix = "calib.right") |