Skip to content

Commit

Permalink
Merge pull request #10 from sot/ignore_prompt_vars
Browse files Browse the repository at this point in the history
Ignore shell vars when using a defined env for the shell
  • Loading branch information
jeanconn authored Jun 29, 2018
2 parents 9eb402c + 84a9257 commit ddd9135
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 4 deletions.
2 changes: 1 addition & 1 deletion Ska/Shell/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Licensed under a 3-clause BSD style license - see LICENSE.rst
from .shell import *

__version__ = '3.3.2'
__version__ = '3.3.3'


def test(*args, **kwargs):
Expand Down
13 changes: 10 additions & 3 deletions Ska/Shell/shell.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,10 +152,17 @@ def run_shell(cmdstr, shell='bash', logfile=None, importenv=False, getenv=False,
shell.delaybeforesend = 0.0

if env:
setenv_str = "export %s='%s'" if shell_name == 'bash' else "setenv %s '%s'"
exclude_vars = []
if shell_name == 'bash':
setenv_str = "export %s='%s'"
exclude_vars = ['PS1', 'PS2', 'PS3', 'PS4', 'PROMPT_COMMAND']
else:
setenv_str = "setenv %s '%s'"
exclude_vars = ['PROMPT', 'PROMPT2']
for key, val in env.items():
# Would be better to properly escape any shell characters.
shell.sendline_expect(setenv_str % (key, val))
if key not in exclude_vars:
# Would be better to properly escape any shell characters.
shell.sendline_expect(setenv_str % (key, val))

shell.delaybeforesend = 0.01
outlines = []
Expand Down
7 changes: 7 additions & 0 deletions Ska/Shell/tests/test_shell.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,13 @@ def test_env(self):
outlines = bash('echo $TEST_ENV_VARA', env=envs)
assert outlines == ['hello']

def test_promptenv(self):
# Confirm that a messed up PS1 won't be a problem
# If the user messes with the prompts during use of the shell, all bets are off
# This test will just hang if the fix isn't implemented (should add pytest-timeout)
outlines = bash("echo 'hello'", env={'PS1': "(hello) \\s-\\v\\$"})
assert outlines == ['hello']

def test_importenv(self):
importenv('export TEST_ENV_VARC="hello"', env={'TEST_ENV_VARB': 'world'})
assert os.environ['TEST_ENV_VARC'] == 'hello'
Expand Down

0 comments on commit ddd9135

Please sign in to comment.