@@ -26,21 +26,18 @@ def test_custom_path_stripped(self):
2626
2727
2828# ---------------------------------------------------------------------------
29- # _host_cmd ()
29+ # _host_prefix ()
3030# ---------------------------------------------------------------------------
3131
3232
33- class TestHostCmd :
33+ class TestHostPrefix :
3434 @patch ("lan_mouse._IN_FLATPAK" , False )
3535 def test_outside_flatpak (self ):
36- assert lan_mouse ._host_cmd ( "pgrep -x lan-mouse" ) == "pgrep -x lan-mouse"
36+ assert lan_mouse ._host_prefix ( ) == []
3737
3838 @patch ("lan_mouse._IN_FLATPAK" , True )
3939 def test_inside_flatpak (self ):
40- assert (
41- lan_mouse ._host_cmd ("pgrep -x lan-mouse" )
42- == "flatpak-spawn --host pgrep -x lan-mouse"
43- )
40+ assert lan_mouse ._host_prefix () == ["flatpak-spawn" , "--host" ]
4441
4542
4643# ---------------------------------------------------------------------------
@@ -185,7 +182,7 @@ def test_skips_malformed_lines(self, mock_run):
185182 def test_custom_bin_path (self , mock_run ):
186183 mock_run .return_value = _make_run_result ("" )
187184 lan_mouse .list_clients ("/custom/lan-mouse" )
188- mock_run .assert_called_once_with ("/custom/lan-mouse cli list" )
185+ mock_run .assert_called_once_with ([ "/custom/lan-mouse" , " cli" , " list"] )
189186
190187
191188# ---------------------------------------------------------------------------
@@ -275,7 +272,7 @@ def test_oserror(self, mock_run):
275272 def test_uses_basename_of_custom_path (self , mock_run ):
276273 mock_run .return_value = _make_run_result ("" , returncode = 0 )
277274 lan_mouse .is_running ("/usr/local/bin/lan-mouse" )
278- mock_run .assert_called_once_with ("pgrep -x lan-mouse" )
275+ mock_run .assert_called_once_with ([ "pgrep" , "-x" , " lan-mouse"] )
279276
280277
281278# ---------------------------------------------------------------------------
@@ -288,7 +285,7 @@ class TestActivate:
288285 def test_success (self , mock_run ):
289286 mock_run .return_value = _make_run_result ("" , returncode = 0 )
290287 assert lan_mouse .activate (0 ) is True
291- mock_run .assert_called_once_with ("lan-mouse cli activate 0" )
288+ mock_run .assert_called_once_with ([ "lan-mouse" , " cli" , " activate" , "0" ] )
292289
293290 @patch ("lan_mouse._run" )
294291 def test_failure (self , mock_run ):
@@ -304,15 +301,15 @@ def test_timeout(self, mock_run):
304301 def test_custom_bin_path (self , mock_run ):
305302 mock_run .return_value = _make_run_result ("" , returncode = 0 )
306303 lan_mouse .activate (3 , "/opt/lm" )
307- mock_run .assert_called_once_with ("/opt/lm cli activate 3" )
304+ mock_run .assert_called_once_with ([ "/opt/lm" , " cli" , " activate" , "3" ] )
308305
309306
310307class TestDeactivate :
311308 @patch ("lan_mouse._run" )
312309 def test_success (self , mock_run ):
313310 mock_run .return_value = _make_run_result ("" , returncode = 0 )
314311 assert lan_mouse .deactivate (1 ) is True
315- mock_run .assert_called_once_with ("lan-mouse cli deactivate 1" )
312+ mock_run .assert_called_once_with ([ "lan-mouse" , " cli" , " deactivate" , "1" ] )
316313
317314 @patch ("lan_mouse._run" )
318315 def test_failure (self , mock_run ):
@@ -361,26 +358,33 @@ def test_custom_bin_without_uwsm(self, _mock):
361358
362359class TestLaunch :
363360 @patch ("subprocess.Popen" )
364- @patch ("lan_mouse._host_cmd " , side_effect = lambda c : c )
361+ @patch ("lan_mouse._IN_FLATPAK " , False )
365362 @patch ("lan_mouse._resolve_launch_cmd" , return_value = "uwsm-app -- lan-mouse" )
366- def test_auto_detect (self , _resolve , _host , mock_popen ):
363+ def test_auto_detect (self , _resolve , mock_popen ):
367364 lan_mouse .launch ()
368365 mock_popen .assert_called_once ()
369- assert mock_popen .call_args [0 ][0 ] == "uwsm-app -- lan-mouse"
366+ assert mock_popen .call_args [0 ][0 ] == [ "uwsm-app" , "--" , " lan-mouse"]
370367
371368 @patch ("subprocess.Popen" )
372- @patch ("lan_mouse._host_cmd " , side_effect = lambda c : c )
373- def test_custom_command (self , _host , mock_popen ):
369+ @patch ("lan_mouse._IN_FLATPAK " , False )
370+ def test_custom_command (self , mock_popen ):
374371 lan_mouse .launch ("my-custom-launcher" )
375372 mock_popen .assert_called_once ()
376- assert mock_popen .call_args [0 ][0 ] == "my-custom-launcher"
373+ assert mock_popen .call_args [0 ][0 ] == [ "my-custom-launcher" ]
377374
378375 @patch ("subprocess.Popen" )
379- @patch ("lan_mouse._host_cmd " , side_effect = lambda c : c )
376+ @patch ("lan_mouse._IN_FLATPAK " , False )
380377 @patch ("lan_mouse._resolve_launch_cmd" , return_value = "lan-mouse" )
381- def test_whitespace_command_uses_auto (self , _resolve , _host , mock_popen ):
378+ def test_whitespace_command_uses_auto (self , _resolve , mock_popen ):
382379 lan_mouse .launch (" " )
383- assert mock_popen .call_args [0 ][0 ] == "lan-mouse"
380+ assert mock_popen .call_args [0 ][0 ] == ["lan-mouse" ]
381+
382+ @patch ("subprocess.Popen" )
383+ @patch ("lan_mouse._IN_FLATPAK" , True )
384+ @patch ("lan_mouse._resolve_launch_cmd" , return_value = "lan-mouse" )
385+ def test_flatpak_prepends_host_prefix (self , _resolve , mock_popen ):
386+ lan_mouse .launch ()
387+ assert mock_popen .call_args [0 ][0 ] == ["flatpak-spawn" , "--host" , "lan-mouse" ]
384388
385389
386390# ---------------------------------------------------------------------------
@@ -395,7 +399,7 @@ class TestKill:
395399 def test_kill_success_immediate (self , mock_run , mock_sleep , mock_running ):
396400 mock_run .return_value = _make_run_result ("" , returncode = 0 )
397401 assert lan_mouse .kill () is True
398- mock_run .assert_called_once_with ("pkill -x lan-mouse" )
402+ mock_run .assert_called_once_with ([ "pkill" , "-x" , " lan-mouse"] )
399403 mock_sleep .assert_not_called ()
400404
401405 @patch ("time.sleep" )
@@ -433,7 +437,7 @@ def test_kill_process_never_exits(self, mock_run, mock_sleep, mock_running):
433437 def test_kill_custom_bin_path (self , mock_run , mock_sleep , mock_running ):
434438 mock_run .return_value = _make_run_result ("" , returncode = 0 )
435439 lan_mouse .kill ("/usr/local/bin/lan-mouse" )
436- mock_run .assert_called_once_with ("pkill -x lan-mouse" )
440+ mock_run .assert_called_once_with ([ "pkill" , "-x" , " lan-mouse"] )
437441
438442
439443# ---------------------------------------------------------------------------
0 commit comments