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 Aug 1, 2024
1 parent 56c1071 commit 5cec090
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 18 deletions.
8 changes: 0 additions & 8 deletions .github/workflows/test.yml-broken
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,5 @@ jobs:
- name: Install dependencies
run: pip install .

# These tests seem to fail on github's CI, we should fix these tests in
# some less hacky way
- name: disable some tests that don't work in CI
run: >
sed -Ei
-e 's/^(\s*)async def test_no_spawn_no_stdin_attached/\[email protected]("broken in ci")\n&/'
tests/commands/test_global.py

- name: Run tests
run: python3 -m unittest --verbose
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 5cec090

Please sign in to comment.