Skip to content

Commit

Permalink
Bug fix: Allow assignment of individual environment variables
Browse files Browse the repository at this point in the history
  • Loading branch information
xolox committed Jul 9, 2016
1 parent 93830fc commit 2f90711
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 10 deletions.
6 changes: 3 additions & 3 deletions executor/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# Programmer friendly subprocess wrapper.
#
# Author: Peter Odding <peter@peterodding.com>
# Last Change: June 3, 2016
# Last Change: July 9, 2016
# URL: https://executor.readthedocs.org

"""
Expand Down Expand Up @@ -68,7 +68,7 @@
unicode = str

# Semi-standard module versioning.
__version__ = '11.0'
__version__ = '11.0.1'

# Initialize a logger.
logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -503,7 +503,7 @@ def encoding(self):
"""
return DEFAULT_ENCODING

@mutable_property
@writable_property(cached=True)
def environment(self):
"""
A dictionary of environment variables for the external command.
Expand Down
25 changes: 18 additions & 7 deletions executor/tests.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Automated tests for the `executor' module.
#
# Author: Peter Odding <peter@peterodding.com>
# Last Change: June 3, 2016
# Last Change: July 9, 2016
# URL: https://executor.readthedocs.org

"""
Expand Down Expand Up @@ -425,13 +425,24 @@ def test_sudo_option(self):
def test_environment_variable_handling(self):
"""Make sure environment variables can be overridden."""
# Check that environment variables of the current process are passed on to subprocesses.
self.assertEqual(execute('echo $PATH', capture=True), os.environ['PATH'])
output = execute('echo $PATH', capture=True)
assert output == os.environ['PATH']
# Test that environment variable overrides can be given to external commands.
override_value = str(random.random())
self.assertEqual(execute('echo $override',
capture=True,
environment=dict(override=override_value)),
override_value)
output = execute(
'echo $HELLO $WORLD',
capture=True,
environment=dict(
HELLO='Hello',
WORLD='world!',
),
)
assert output == 'Hello world!'
# Test that the environment variables of a command can be modified
# after the command has been initialized.
cmd = ExternalCommand('echo $DELAYED', capture=True)
cmd.environment['DELAYED'] = 'Also works fine'
cmd.wait()
assert cmd.output == 'Also works fine'

def test_simple_async_cmd(self):
"""Make sure commands can be executed asynchronously."""
Expand Down

0 comments on commit 2f90711

Please sign in to comment.