1+ import subprocess
2+ import sys
13from contextlib import nullcontext as does_not_raise
24from unittest .mock import patch
35
2123 ],
2224)
2325def test_entrypoint_command (command , expected_exception ):
26+ """Test the entrypoint with different commands: 'info', 'invalid', ''."""
2427 with (
2528 patch ("sys.argv" , command ),
2629 patch ("builtins.print" ) as mock_print ,
@@ -29,3 +32,30 @@ def test_entrypoint_command(command, expected_exception):
2932 main ()
3033 printed_message = " " .join (map (str , mock_print .call_args .args ))
3134 assert e in printed_message
35+
36+
37+ @pytest .mark .parametrize (
38+ "run_side_effect, expected_message" ,
39+ [
40+ (None , "" ), # No error
41+ (subprocess .CalledProcessError (1 , "napari" ), "error occurred while" ),
42+ ],
43+ )
44+ def test_launch_command (run_side_effect , expected_message , capsys ):
45+ """Test the 'launch' command.
46+
47+ We mock the subprocess.run function to avoid actually launching napari.
48+ """
49+ with (
50+ patch ("sys.argv" , ["movement" , "launch" ]),
51+ patch ("subprocess.run" , side_effect = run_side_effect ) as mock_run ,
52+ ):
53+ main ()
54+ # Assert that subprocess.run was called with the correct arguments
55+ mock_run .assert_called_once ()
56+ args = mock_run .call_args [0 ][0 ]
57+ assert args [0 ] == sys .executable
58+ assert args [1 :] == ["-m" , "napari" , "-w" , "movement" ]
59+ # Assert that the expected message was printed
60+ captured = capsys .readouterr ()
61+ assert expected_message in captured .out
0 commit comments