Mercurial > cpython-lru_cache-weakref
annotate Lib/test/test_popen.py @ 79675:c0a2294de787 2.7
Issue #16199: Backport 2to3 typo fix from 3.2.
| author | Chris Jerdonek <chris.jerdonek@gmail.com> |
|---|---|
| date | Thu, 11 Oct 2012 16:15:46 -0700 |
| parents | a73b92d1e9fd |
| children |
| rev | line source |
|---|---|
|
22875
e3de9d19faaa
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
1 #! /usr/bin/env python |
|
e3de9d19faaa
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
2 """Basic tests for os.popen() |
|
e3de9d19faaa
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
3 |
|
e3de9d19faaa
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
4 Particularly useful for platforms that fake popen. |
|
e3de9d19faaa
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
5 """ |
|
e3de9d19faaa
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
6 |
|
40708
38d944efe600
Port test_popen.py to unittest.
Walter Dörwald <walter@livinglogic.de>
parents:
38961
diff
changeset
|
7 import unittest |
|
38d944efe600
Port test_popen.py to unittest.
Walter Dörwald <walter@livinglogic.de>
parents:
38961
diff
changeset
|
8 from test import test_support |
|
38d944efe600
Port test_popen.py to unittest.
Walter Dörwald <walter@livinglogic.de>
parents:
38961
diff
changeset
|
9 import os, sys |
|
22875
e3de9d19faaa
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
10 |
|
e3de9d19faaa
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
11 # Test that command-lines get down as we expect. |
|
e3de9d19faaa
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
12 # To do this we execute: |
|
e3de9d19faaa
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
13 # python -c "import sys;print sys.argv" {rest_of_commandline} |
|
e3de9d19faaa
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
14 # This results in Python being spawned and printing the sys.argv list. |
|
e3de9d19faaa
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
15 # We can then eval() the result of this, and see what each argv was. |
|
28232
47cb85cdd5f3
Don't quote the path to Python unless the path contains an embedded space.
Tim Peters <tim.peters@gmail.com>
parents:
28048
diff
changeset
|
16 python = sys.executable |
|
40708
38d944efe600
Port test_popen.py to unittest.
Walter Dörwald <walter@livinglogic.de>
parents:
38961
diff
changeset
|
17 |
|
38d944efe600
Port test_popen.py to unittest.
Walter Dörwald <walter@livinglogic.de>
parents:
38961
diff
changeset
|
18 class PopenTest(unittest.TestCase): |
|
38d944efe600
Port test_popen.py to unittest.
Walter Dörwald <walter@livinglogic.de>
parents:
38961
diff
changeset
|
19 def _do_test_commandline(self, cmdline, expected): |
|
58619
a73b92d1e9fd
fix windows buildbot
Benjamin Peterson <benjamin@python.org>
parents:
58337
diff
changeset
|
20 cmd = '%s -c "import sys;print sys.argv" %s' % (python, cmdline) |
|
58337
78610b48c396
try to fix for windows
Benjamin Peterson <benjamin@python.org>
parents:
58313
diff
changeset
|
21 data = os.popen(cmd).read() + '\n' |
|
40708
38d944efe600
Port test_popen.py to unittest.
Walter Dörwald <walter@livinglogic.de>
parents:
38961
diff
changeset
|
22 got = eval(data)[1:] # strip off argv[0] |
|
38d944efe600
Port test_popen.py to unittest.
Walter Dörwald <walter@livinglogic.de>
parents:
38961
diff
changeset
|
23 self.assertEqual(got, expected) |
|
22875
e3de9d19faaa
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
24 |
|
40708
38d944efe600
Port test_popen.py to unittest.
Walter Dörwald <walter@livinglogic.de>
parents:
38961
diff
changeset
|
25 def test_popen(self): |
|
38d944efe600
Port test_popen.py to unittest.
Walter Dörwald <walter@livinglogic.de>
parents:
38961
diff
changeset
|
26 self.assertRaises(TypeError, os.popen) |
|
38d944efe600
Port test_popen.py to unittest.
Walter Dörwald <walter@livinglogic.de>
parents:
38961
diff
changeset
|
27 self._do_test_commandline( |
|
38d944efe600
Port test_popen.py to unittest.
Walter Dörwald <walter@livinglogic.de>
parents:
38961
diff
changeset
|
28 "foo bar", |
|
38d944efe600
Port test_popen.py to unittest.
Walter Dörwald <walter@livinglogic.de>
parents:
38961
diff
changeset
|
29 ["foo", "bar"] |
|
38d944efe600
Port test_popen.py to unittest.
Walter Dörwald <walter@livinglogic.de>
parents:
38961
diff
changeset
|
30 ) |
|
38d944efe600
Port test_popen.py to unittest.
Walter Dörwald <walter@livinglogic.de>
parents:
38961
diff
changeset
|
31 self._do_test_commandline( |
|
38d944efe600
Port test_popen.py to unittest.
Walter Dörwald <walter@livinglogic.de>
parents:
38961
diff
changeset
|
32 'foo "spam and eggs" "silly walk"', |
|
38d944efe600
Port test_popen.py to unittest.
Walter Dörwald <walter@livinglogic.de>
parents:
38961
diff
changeset
|
33 ["foo", "spam and eggs", "silly walk"] |
|
38d944efe600
Port test_popen.py to unittest.
Walter Dörwald <walter@livinglogic.de>
parents:
38961
diff
changeset
|
34 ) |
|
38d944efe600
Port test_popen.py to unittest.
Walter Dörwald <walter@livinglogic.de>
parents:
38961
diff
changeset
|
35 self._do_test_commandline( |
|
38d944efe600
Port test_popen.py to unittest.
Walter Dörwald <walter@livinglogic.de>
parents:
38961
diff
changeset
|
36 'foo "a \\"quoted\\" arg" bar', |
|
38d944efe600
Port test_popen.py to unittest.
Walter Dörwald <walter@livinglogic.de>
parents:
38961
diff
changeset
|
37 ["foo", 'a "quoted" arg', "bar"] |
|
38d944efe600
Port test_popen.py to unittest.
Walter Dörwald <walter@livinglogic.de>
parents:
38961
diff
changeset
|
38 ) |
|
38d944efe600
Port test_popen.py to unittest.
Walter Dörwald <walter@livinglogic.de>
parents:
38961
diff
changeset
|
39 test_support.reap_children() |
|
22875
e3de9d19faaa
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
40 |
|
55195
221718e757ba
Add basic tests for the return value of os.popen().close().
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
40708
diff
changeset
|
41 def test_return_code(self): |
|
221718e757ba
Add basic tests for the return value of os.popen().close().
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
40708
diff
changeset
|
42 self.assertEqual(os.popen("exit 0").close(), None) |
|
221718e757ba
Add basic tests for the return value of os.popen().close().
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
40708
diff
changeset
|
43 if os.name == 'nt': |
|
221718e757ba
Add basic tests for the return value of os.popen().close().
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
40708
diff
changeset
|
44 self.assertEqual(os.popen("exit 42").close(), 42) |
|
221718e757ba
Add basic tests for the return value of os.popen().close().
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
40708
diff
changeset
|
45 else: |
|
221718e757ba
Add basic tests for the return value of os.popen().close().
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
40708
diff
changeset
|
46 self.assertEqual(os.popen("exit 42").close(), 42 << 8) |
|
221718e757ba
Add basic tests for the return value of os.popen().close().
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
40708
diff
changeset
|
47 |
|
40708
38d944efe600
Port test_popen.py to unittest.
Walter Dörwald <walter@livinglogic.de>
parents:
38961
diff
changeset
|
48 def test_main(): |
|
38d944efe600
Port test_popen.py to unittest.
Walter Dörwald <walter@livinglogic.de>
parents:
38961
diff
changeset
|
49 test_support.run_unittest(PopenTest) |
|
22875
e3de9d19faaa
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
50 |
|
40708
38d944efe600
Port test_popen.py to unittest.
Walter Dörwald <walter@livinglogic.de>
parents:
38961
diff
changeset
|
51 if __name__ == "__main__": |
|
38d944efe600
Port test_popen.py to unittest.
Walter Dörwald <walter@livinglogic.de>
parents:
38961
diff
changeset
|
52 test_main() |
