diff --git a/tests/ui/test_video_calibration.py b/tests/ui/test_video_calibration.py new file mode 100644 index 0000000..c83ed03 --- /dev/null +++ b/tests/ui/test_video_calibration.py @@ -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']) diff --git a/tests/ui/test_video_calibration_app.py b/tests/ui/test_video_calibration_app.py new file mode 100644 index 0000000..9fca486 --- /dev/null +++ b/tests/ui/test_video_calibration_app.py @@ -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) diff --git a/tests/ui/test_video_calibration_checker.py b/tests/ui/test_video_calibration_checker.py new file mode 100644 index 0000000..f2ca651 --- /dev/null +++ b/tests/ui/test_video_calibration_checker.py @@ -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']) diff --git a/tests/ui/test_video_calibration_checker_app.py b/tests/ui/test_video_calibration_checker_app.py new file mode 100644 index 0000000..72e91f3 --- /dev/null +++ b/tests/ui/test_video_calibration_checker_app.py @@ -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")