From 5a3eed75141a9c90cdd1a58d700c215308474ed5 Mon Sep 17 00:00:00 2001 From: Lucas Hoffmann Date: Tue, 30 Jul 2024 13:46:40 +0200 Subject: [PATCH] Fix spawn tests in different environments We are running our tests in different environments, sometimes with a terminal as stdin and sometimes with /dev/null as stdin. Both are seen as "not a pipe" by `test -p` so we use that to test if our python code redirects text into an external process. --- flake.nix | 4 ---- tests/commands/test_global.py | 12 ++++++------ 2 files changed, 6 insertions(+), 10 deletions(-) diff --git a/flake.nix b/flake.nix index 339f65874..3cd0609a1 100644 --- a/flake.nix +++ b/flake.nix @@ -36,10 +36,6 @@ nativeCheckInputs = with pkgs; [ gnupg notmuch procps ]; checkPhase = '' - # In the nix sandbox stdin is not a terminal but /dev/null so we - # change the shell command only in this specific test. - sed -i '/test_no_spawn_no_stdin_attached/,/^$/s/test -t 0/sh -c "[ $(wc -l) -eq 0 ]"/' tests/commands/test_global.py - python3 -m unittest -v ''; }); diff --git a/tests/commands/test_global.py b/tests/commands/test_global.py index 775a822ce..8932f77a3 100644 --- a/tests/commands/test_global.py +++ b/tests/commands/test_global.py @@ -124,19 +124,19 @@ async def test_no_spawn_stdin_success(self): @utilities.async_test async def test_no_spawn_no_stdin_attached(self): ui = utilities.make_ui() - cmd = g_commands.ExternalCommand('test -t 0', refocus=False) + cmd = g_commands.ExternalCommand('test -p /dev/stdin', refocus=False) await cmd.apply(ui) - ui.notify.assert_not_called() + ui.notify.assert_called_once_with( + 'editor has exited with error code 1 -- No stderr output', + priority='error') @utilities.async_test async def test_no_spawn_stdin_attached(self): ui = utilities.make_ui() cmd = g_commands.ExternalCommand( - "test -t 0", stdin='0', refocus=False) + "test -p /dev/stdin", stdin='0', refocus=False) await cmd.apply(ui) - ui.notify.assert_called_once_with( - 'editor has exited with error code 1 -- No stderr output', - priority='error') + ui.notify.assert_not_called() @utilities.async_test async def test_no_spawn_failure(self):