Skip to content

Commit

Permalink
Fix spawn tests in different environments
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
lucc committed Jul 30, 2024
1 parent c6f3c6b commit aae079d
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 10 deletions.
4 changes: 0 additions & 4 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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
'';
});
Expand Down
12 changes: 6 additions & 6 deletions tests/commands/test_global.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down

0 comments on commit aae079d

Please sign in to comment.