diff --git a/bewegungsschrift.py b/bewegungsschrift.py index f360b86..acc25df 100644 --- a/bewegungsschrift.py +++ b/bewegungsschrift.py @@ -1,5 +1,6 @@ import argparse import yaml +import cv2 from microservices import video_input, pose_estimation, human_selection, labanotation_generation from microservices.pose_estimation.perform_pose_estimation import launch_webcam_test from microservices.pose_estimation.launch_webcam_cube_test import launch_webcam_cube_test diff --git a/tests/test_bewegungsschrift.py b/tests/test_bewegungsschrift.py index d9bc3d2..53ff866 100644 --- a/tests/test_bewegungsschrift.py +++ b/tests/test_bewegungsschrift.py @@ -46,5 +46,14 @@ def test_main_with_human_selection(self, mock_parse_args): mock_generate_labanotation.assert_called_once_with(['pose1', 'pose2']) mock_save_labanotation.assert_called_once_with('labanotation', 'output.yaml') + @patch('bewegungsschrift.argparse.ArgumentParser.parse_args') + def test_main_with_webcam_cube_logging(self, mock_parse_args): + mock_parse_args.return_value = MagicMock(webcam_cube=True, input=None, output=None, select_human=False) + with patch('bewegungsschrift.pose_estimation.launch_webcam_cube_test') as mock_launch_webcam_cube_test, \ + patch('builtins.print') as mock_print: + bewegungsschrift.main() + mock_launch_webcam_cube_test.assert_called_once() + mock_print.assert_any_call("Human position in 3D cube: {'x': 0.5, 'y': 0.5, 'z': 0.0}") + if __name__ == '__main__': unittest.main() diff --git a/tests/test_perform_pose_estimation.py b/tests/test_perform_pose_estimation.py index b12c81b..9ce5dac 100644 --- a/tests/test_perform_pose_estimation.py +++ b/tests/test_perform_pose_estimation.py @@ -20,5 +20,30 @@ def test_perform_pose_estimation(self, mock_process): pose_estimations = perform_pose_estimation.perform_pose_estimation(frames) self.assertEqual(pose_estimations, expected_pose_estimations) + @patch('microservices.pose_estimation.launch_webcam_cube_test.cv2.VideoCapture') + @patch('microservices.pose_estimation.launch_webcam_cube_test.mp.solutions.holistic.Holistic.process') + @patch('microservices.pose_estimation.launch_webcam_cube_test.cv2.imshow') + @patch('microservices.pose_estimation.launch_webcam_cube_test.cv2.waitKey', return_value=27) + @patch('microservices.pose_estimation.launch_webcam_cube_test.cv2.destroyAllWindows') + def test_launch_webcam_cube_test(self, mock_destroyAllWindows, mock_waitKey, mock_imshow, mock_process, mock_VideoCapture): + mock_cap = MagicMock() + mock_VideoCapture.return_value = mock_cap + mock_cap.isOpened.side_effect = [True, False] + mock_cap.read.return_value = (True, 'frame') + + mock_results = MagicMock() + mock_results.pose_landmarks = MagicMock() + mock_results.pose_landmarks.landmark = [MagicMock(x=0.5, y=0.5, z=0.0)] + mock_process.return_value = mock_results + + perform_pose_estimation.launch_webcam_cube_test() + + mock_VideoCapture.assert_called_once_with(0) + mock_cap.read.assert_called_once() + mock_process.assert_called_once() + mock_imshow.assert_called_once_with('Webcam Cube Test', 'frame') + mock_waitKey.assert_called_once_with(5) + mock_destroyAllWindows.assert_called_once() + if __name__ == '__main__': unittest.main()