Skip to content

Commit

Permalink
Remove env parameter from call_cmd_async
Browse files Browse the repository at this point in the history
The parameter is never used in alot but we have a failing test for it.
Instead of fixing the test the parameter is removed.
  • Loading branch information
lucc committed May 6, 2024
1 parent a6ac98c commit e0e0786
Show file tree
Hide file tree
Showing 3 changed files with 1 addition and 26 deletions.
7 changes: 1 addition & 6 deletions alot/helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ def call_cmd(cmdlist, stdin=None):
return out, err, ret


async def call_cmd_async(cmdlist, stdin=None, env=None):
async def call_cmd_async(cmdlist, stdin=None):
"""Given a command, call that command asynchronously and return the output.
This function only handles `OSError` when creating the subprocess, any
Expand All @@ -305,15 +305,10 @@ async def call_cmd_async(cmdlist, stdin=None, env=None):
termenc = urwid.util.detected_encoding
cmdlist = [s.encode(termenc) for s in cmdlist]

environment = os.environ.copy()
if env is not None:
environment.update(env)
logging.debug('ENV = %s', environment)
logging.debug('CMD = %s', cmdlist)
try:
proc = await asyncio.create_subprocess_exec(
*cmdlist,
env=environment,
stdout=asyncio.subprocess.PIPE,
stderr=asyncio.subprocess.PIPE,
stdin=asyncio.subprocess.PIPE if stdin else None)
Expand Down
3 changes: 0 additions & 3 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,6 @@
# 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
# FIXME: This test seems to be broken?
sed -i 's/\( *\)async def test_env_set.*/\1@unittest.skip\n&/' tests/test_helper.py
python3 -m unittest -v
'';
});
Expand Down
17 changes: 0 additions & 17 deletions tests/test_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -422,23 +422,6 @@ async def test_stdin(self):
ret = await helper.call_cmd_async(['cat', '-'], stdin='foo')
self.assertEqual(ret[0], 'foo')

@utilities.async_test
async def test_env_set(self):
with mock.patch.dict(os.environ, {}, clear=True):
ret = await helper.call_cmd_async(
['python3', '-c', 'import os; '
'print(os.environ.get("foo", "fail"), end="")'
],
env={'foo': 'bar'})
self.assertEqual(ret[0], 'bar')

@utilities.async_test
async def test_env_doesnt_pollute(self):
with mock.patch.dict(os.environ, {}, clear=True):
await helper.call_cmd_async(['echo', '-n', 'foo'],
env={'foo': 'bar'})
self.assertEqual(os.environ, {})

@utilities.async_test
async def test_command_fails(self):
_, err, ret = await helper.call_cmd_async(['_____better_not_exist'])
Expand Down

0 comments on commit e0e0786

Please sign in to comment.