Skip to content

Commit

Permalink
Add test for CmdAction with environment variables
Browse files Browse the repository at this point in the history
This exercises issue pydoit#171.
  • Loading branch information
onnodb authored and Gabriel Beauchamp committed Dec 5, 2017
1 parent 12789e4 commit a7c8011
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
20 changes: 16 additions & 4 deletions tests/sample_process.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
#! /usr/bin/env python

# tests on CmdTask will use this script as an external process.
# 3 or more arguments. process return error exit (166)
# arguments "please fail". process return fail exit (11)
# first argument is sent to stdout
# second argument is sent to stderr
# - If you call this script with 3 or more arguments, the process returns
# exit code (166).
# - If you call this script with arguments "please fail", it returns exit
# code (11).
# - If you call this script with arguments "check env", it verifies the
# existence of an environment variable called "GELKIPWDUZLOVSXE", with
# value "1". If the variable is not found, the process returns exit code (99).
# - Otherwise, any first argument gets written to STDOUT. Any second argument
# gets written to STDERR.

import os
import sys

if __name__ == "__main__":
Expand All @@ -17,6 +23,12 @@
sys.stdout.write("out ouch")
sys.stderr.write("err output on failure")
sys.exit(11)
# check env
if len(sys.argv) == 3 and sys.argv[1]=='check' and sys.argv[2]=='env':
if os.environ.get('GELKIPWDUZLOVSXE') == '1':
sys.exit(0)
else:
sys.exit(99)
# ok
if len(sys.argv) > 1:
sys.stdout.write(sys.argv[1])
Expand Down
5 changes: 5 additions & 0 deletions tests/test_action.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,11 @@ def test_error(self):
got = my_action.execute()
assert isinstance(got, TaskError)

def test_env(self):
my_action = action.CmdAction("%s check env" % PROGRAM, env={'GELKIPWDUZLOVSXE': '1'})
got = my_action.execute()
assert got is None

def test_failure(self):
my_action = action.CmdAction("%s please fail" % PROGRAM)
got = my_action.execute()
Expand Down

0 comments on commit a7c8011

Please sign in to comment.