Mercurial > treepkg
annotate test/test_run.py @ 162:876db132431a
Remove debug print
author | Bernhard Herzog <bh@intevation.de> |
---|---|
date | Thu, 19 Jun 2008 14:27:49 +0000 |
parents | e08b4b09d35f |
children | a68a4e22549c |
rev | line source |
---|---|
123
37aadd33ffab
Add tests for treepkg/run.py
Bernhard Herzog <bh@intevation.de>
parents:
diff
changeset
|
1 # Copyright (C) 2008 by Intevation GmbH |
37aadd33ffab
Add tests for treepkg/run.py
Bernhard Herzog <bh@intevation.de>
parents:
diff
changeset
|
2 # Authors: |
37aadd33ffab
Add tests for treepkg/run.py
Bernhard Herzog <bh@intevation.de>
parents:
diff
changeset
|
3 # Bernhard Herzog <bh@intevation.de> |
37aadd33ffab
Add tests for treepkg/run.py
Bernhard Herzog <bh@intevation.de>
parents:
diff
changeset
|
4 # |
37aadd33ffab
Add tests for treepkg/run.py
Bernhard Herzog <bh@intevation.de>
parents:
diff
changeset
|
5 # This program is free software under the GPL (>=v2) |
37aadd33ffab
Add tests for treepkg/run.py
Bernhard Herzog <bh@intevation.de>
parents:
diff
changeset
|
6 # Read the file COPYING coming with the software for details. |
37aadd33ffab
Add tests for treepkg/run.py
Bernhard Herzog <bh@intevation.de>
parents:
diff
changeset
|
7 |
37aadd33ffab
Add tests for treepkg/run.py
Bernhard Herzog <bh@intevation.de>
parents:
diff
changeset
|
8 """Tests for treepkg.run""" |
37aadd33ffab
Add tests for treepkg/run.py
Bernhard Herzog <bh@intevation.de>
parents:
diff
changeset
|
9 |
37aadd33ffab
Add tests for treepkg/run.py
Bernhard Herzog <bh@intevation.de>
parents:
diff
changeset
|
10 import sys |
37aadd33ffab
Add tests for treepkg/run.py
Bernhard Herzog <bh@intevation.de>
parents:
diff
changeset
|
11 import os |
37aadd33ffab
Add tests for treepkg/run.py
Bernhard Herzog <bh@intevation.de>
parents:
diff
changeset
|
12 import unittest |
37aadd33ffab
Add tests for treepkg/run.py
Bernhard Herzog <bh@intevation.de>
parents:
diff
changeset
|
13 |
37aadd33ffab
Add tests for treepkg/run.py
Bernhard Herzog <bh@intevation.de>
parents:
diff
changeset
|
14 from treepkg.run import call, SubprocessError |
37aadd33ffab
Add tests for treepkg/run.py
Bernhard Herzog <bh@intevation.de>
parents:
diff
changeset
|
15 |
37aadd33ffab
Add tests for treepkg/run.py
Bernhard Herzog <bh@intevation.de>
parents:
diff
changeset
|
16 |
37aadd33ffab
Add tests for treepkg/run.py
Bernhard Herzog <bh@intevation.de>
parents:
diff
changeset
|
17 |
37aadd33ffab
Add tests for treepkg/run.py
Bernhard Herzog <bh@intevation.de>
parents:
diff
changeset
|
18 class TestCall(unittest.TestCase): |
37aadd33ffab
Add tests for treepkg/run.py
Bernhard Herzog <bh@intevation.de>
parents:
diff
changeset
|
19 |
37aadd33ffab
Add tests for treepkg/run.py
Bernhard Herzog <bh@intevation.de>
parents:
diff
changeset
|
20 def test_call_defaults(self): |
37aadd33ffab
Add tests for treepkg/run.py
Bernhard Herzog <bh@intevation.de>
parents:
diff
changeset
|
21 call([sys.executable, "-c", "pass"]) |
37aadd33ffab
Add tests for treepkg/run.py
Bernhard Herzog <bh@intevation.de>
parents:
diff
changeset
|
22 |
37aadd33ffab
Add tests for treepkg/run.py
Bernhard Herzog <bh@intevation.de>
parents:
diff
changeset
|
23 def test_call_error(self): |
37aadd33ffab
Add tests for treepkg/run.py
Bernhard Herzog <bh@intevation.de>
parents:
diff
changeset
|
24 """Test call with a subprocess that exits with a non-zero exit code""" |
37aadd33ffab
Add tests for treepkg/run.py
Bernhard Herzog <bh@intevation.de>
parents:
diff
changeset
|
25 try: |
37aadd33ffab
Add tests for treepkg/run.py
Bernhard Herzog <bh@intevation.de>
parents:
diff
changeset
|
26 call([sys.executable, "-c", "import sys; sys.exit(1)"]) |
37aadd33ffab
Add tests for treepkg/run.py
Bernhard Herzog <bh@intevation.de>
parents:
diff
changeset
|
27 except SubprocessError, exc: |
37aadd33ffab
Add tests for treepkg/run.py
Bernhard Herzog <bh@intevation.de>
parents:
diff
changeset
|
28 self.assertEquals(exc.returncode, 1) |
37aadd33ffab
Add tests for treepkg/run.py
Bernhard Herzog <bh@intevation.de>
parents:
diff
changeset
|
29 else: |
37aadd33ffab
Add tests for treepkg/run.py
Bernhard Herzog <bh@intevation.de>
parents:
diff
changeset
|
30 self.fail("call did not raise an exception") |
124
e08b4b09d35f
New parameter treepkg.run.call: extra_env for additional environment
Bernhard Herzog <bh@intevation.de>
parents:
123
diff
changeset
|
31 |
e08b4b09d35f
New parameter treepkg.run.call: extra_env for additional environment
Bernhard Herzog <bh@intevation.de>
parents:
123
diff
changeset
|
32 def test_call_extra_env(self): |
e08b4b09d35f
New parameter treepkg.run.call: extra_env for additional environment
Bernhard Herzog <bh@intevation.de>
parents:
123
diff
changeset
|
33 """Test call with the extra_env parameter""" |
e08b4b09d35f
New parameter treepkg.run.call: extra_env for additional environment
Bernhard Herzog <bh@intevation.de>
parents:
123
diff
changeset
|
34 subprocess_cmd = [sys.executable, "-c", |
e08b4b09d35f
New parameter treepkg.run.call: extra_env for additional environment
Bernhard Herzog <bh@intevation.de>
parents:
123
diff
changeset
|
35 "import sys, os;" |
e08b4b09d35f
New parameter treepkg.run.call: extra_env for additional environment
Bernhard Herzog <bh@intevation.de>
parents:
123
diff
changeset
|
36 "value = os.environ.get('TREEPKG_TEST');" |
e08b4b09d35f
New parameter treepkg.run.call: extra_env for additional environment
Bernhard Herzog <bh@intevation.de>
parents:
123
diff
changeset
|
37 "sys.exit(int(value != 'xyzzy'))" |
e08b4b09d35f
New parameter treepkg.run.call: extra_env for additional environment
Bernhard Herzog <bh@intevation.de>
parents:
123
diff
changeset
|
38 ] |
e08b4b09d35f
New parameter treepkg.run.call: extra_env for additional environment
Bernhard Herzog <bh@intevation.de>
parents:
123
diff
changeset
|
39 # sanity check that the extra environment variable we use for |
e08b4b09d35f
New parameter treepkg.run.call: extra_env for additional environment
Bernhard Herzog <bh@intevation.de>
parents:
123
diff
changeset
|
40 # the test is not set yet |
e08b4b09d35f
New parameter treepkg.run.call: extra_env for additional environment
Bernhard Herzog <bh@intevation.de>
parents:
123
diff
changeset
|
41 self.assertRaises(SubprocessError, call, subprocess_cmd) |
e08b4b09d35f
New parameter treepkg.run.call: extra_env for additional environment
Bernhard Herzog <bh@intevation.de>
parents:
123
diff
changeset
|
42 |
e08b4b09d35f
New parameter treepkg.run.call: extra_env for additional environment
Bernhard Herzog <bh@intevation.de>
parents:
123
diff
changeset
|
43 # the actual test |
e08b4b09d35f
New parameter treepkg.run.call: extra_env for additional environment
Bernhard Herzog <bh@intevation.de>
parents:
123
diff
changeset
|
44 try: |
e08b4b09d35f
New parameter treepkg.run.call: extra_env for additional environment
Bernhard Herzog <bh@intevation.de>
parents:
123
diff
changeset
|
45 call(subprocess_cmd, extra_env=dict(TREEPKG_TEST="xyzzy")) |
e08b4b09d35f
New parameter treepkg.run.call: extra_env for additional environment
Bernhard Herzog <bh@intevation.de>
parents:
123
diff
changeset
|
46 except SubprocessError, exc: |
e08b4b09d35f
New parameter treepkg.run.call: extra_env for additional environment
Bernhard Herzog <bh@intevation.de>
parents:
123
diff
changeset
|
47 self.fail("the extra_env variables were not set properly") |
e08b4b09d35f
New parameter treepkg.run.call: extra_env for additional environment
Bernhard Herzog <bh@intevation.de>
parents:
123
diff
changeset
|
48 else: |
e08b4b09d35f
New parameter treepkg.run.call: extra_env for additional environment
Bernhard Herzog <bh@intevation.de>
parents:
123
diff
changeset
|
49 # test OK |
e08b4b09d35f
New parameter treepkg.run.call: extra_env for additional environment
Bernhard Herzog <bh@intevation.de>
parents:
123
diff
changeset
|
50 pass |