Mercurial > cpython-lru_cache-weakref
annotate Lib/test/test_popen.py @ 54294:dba767bc3155 legacy-trunk
remove mention of old ctypes version
| author | Benjamin Peterson <benjamin@python.org> |
|---|---|
| date | Sat, 23 May 2009 20:59:09 +0000 |
| parents | 38d944efe600 |
| children | 221718e757ba e9a6234b26af |
| 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 |
|
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
|
17 if ' ' in python: |
|
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
|
18 python = '"' + python + '"' # quote embedded space for cmdline |
|
40708
38d944efe600
Port test_popen.py to unittest.
Walter Dörwald <walter@livinglogic.de>
parents:
38961
diff
changeset
|
19 |
|
38d944efe600
Port test_popen.py to unittest.
Walter Dörwald <walter@livinglogic.de>
parents:
38961
diff
changeset
|
20 class PopenTest(unittest.TestCase): |
|
38d944efe600
Port test_popen.py to unittest.
Walter Dörwald <walter@livinglogic.de>
parents:
38961
diff
changeset
|
21 def _do_test_commandline(self, cmdline, expected): |
|
38d944efe600
Port test_popen.py to unittest.
Walter Dörwald <walter@livinglogic.de>
parents:
38961
diff
changeset
|
22 cmd = '%s -c "import sys;print sys.argv" %s' % (python, cmdline) |
|
38d944efe600
Port test_popen.py to unittest.
Walter Dörwald <walter@livinglogic.de>
parents:
38961
diff
changeset
|
23 data = os.popen(cmd).read() |
|
38d944efe600
Port test_popen.py to unittest.
Walter Dörwald <walter@livinglogic.de>
parents:
38961
diff
changeset
|
24 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
|
25 self.assertEqual(got, expected) |
|
22875
e3de9d19faaa
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
26 |
|
40708
38d944efe600
Port test_popen.py to unittest.
Walter Dörwald <walter@livinglogic.de>
parents:
38961
diff
changeset
|
27 def test_popen(self): |
|
38d944efe600
Port test_popen.py to unittest.
Walter Dörwald <walter@livinglogic.de>
parents:
38961
diff
changeset
|
28 self.assertRaises(TypeError, os.popen) |
|
38d944efe600
Port test_popen.py to unittest.
Walter Dörwald <walter@livinglogic.de>
parents:
38961
diff
changeset
|
29 self._do_test_commandline( |
|
38d944efe600
Port test_popen.py to unittest.
Walter Dörwald <walter@livinglogic.de>
parents:
38961
diff
changeset
|
30 "foo bar", |
|
38d944efe600
Port test_popen.py to unittest.
Walter Dörwald <walter@livinglogic.de>
parents:
38961
diff
changeset
|
31 ["foo", "bar"] |
|
38d944efe600
Port test_popen.py to unittest.
Walter Dörwald <walter@livinglogic.de>
parents:
38961
diff
changeset
|
32 ) |
|
38d944efe600
Port test_popen.py to unittest.
Walter Dörwald <walter@livinglogic.de>
parents:
38961
diff
changeset
|
33 self._do_test_commandline( |
|
38d944efe600
Port test_popen.py to unittest.
Walter Dörwald <walter@livinglogic.de>
parents:
38961
diff
changeset
|
34 'foo "spam and eggs" "silly walk"', |
|
38d944efe600
Port test_popen.py to unittest.
Walter Dörwald <walter@livinglogic.de>
parents:
38961
diff
changeset
|
35 ["foo", "spam and eggs", "silly walk"] |
|
38d944efe600
Port test_popen.py to unittest.
Walter Dörwald <walter@livinglogic.de>
parents:
38961
diff
changeset
|
36 ) |
|
38d944efe600
Port test_popen.py to unittest.
Walter Dörwald <walter@livinglogic.de>
parents:
38961
diff
changeset
|
37 self._do_test_commandline( |
|
38d944efe600
Port test_popen.py to unittest.
Walter Dörwald <walter@livinglogic.de>
parents:
38961
diff
changeset
|
38 'foo "a \\"quoted\\" arg" bar', |
|
38d944efe600
Port test_popen.py to unittest.
Walter Dörwald <walter@livinglogic.de>
parents:
38961
diff
changeset
|
39 ["foo", 'a "quoted" arg', "bar"] |
|
38d944efe600
Port test_popen.py to unittest.
Walter Dörwald <walter@livinglogic.de>
parents:
38961
diff
changeset
|
40 ) |
|
38d944efe600
Port test_popen.py to unittest.
Walter Dörwald <walter@livinglogic.de>
parents:
38961
diff
changeset
|
41 test_support.reap_children() |
|
22875
e3de9d19faaa
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
42 |
|
40708
38d944efe600
Port test_popen.py to unittest.
Walter Dörwald <walter@livinglogic.de>
parents:
38961
diff
changeset
|
43 def test_main(): |
|
38d944efe600
Port test_popen.py to unittest.
Walter Dörwald <walter@livinglogic.de>
parents:
38961
diff
changeset
|
44 test_support.run_unittest(PopenTest) |
|
22875
e3de9d19faaa
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
45 |
|
40708
38d944efe600
Port test_popen.py to unittest.
Walter Dörwald <walter@livinglogic.de>
parents:
38961
diff
changeset
|
46 if __name__ == "__main__": |
|
38d944efe600
Port test_popen.py to unittest.
Walter Dörwald <walter@livinglogic.de>
parents:
38961
diff
changeset
|
47 test_main() |
