Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(85693)

Side by Side Diff: Lib/test/test_popen.py

Issue 23670: Modifications to support iOS as a development platform
Patch Set: Created 3 years, 8 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « Lib/test/test_poll.py ('k') | Lib/test/test_posix.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 """Basic tests for os.popen() 1 """Basic tests for os.popen()
2 2
3 Particularly useful for platforms that fake popen. 3 Particularly useful for platforms that fake popen.
4 """ 4 """
5 5
6 import unittest 6 import unittest
7 from test import support 7 from test import support
8 import os, sys 8 import os, sys
9 import subprocess
9 10
10 # Test that command-lines get down as we expect. 11 # Test that command-lines get down as we expect.
11 # To do this we execute: 12 # To do this we execute:
12 # python -c "import sys;print(sys.argv)" {rest_of_commandline} 13 # python -c "import sys;print(sys.argv)" {rest_of_commandline}
13 # This results in Python being spawned and printing the sys.argv list. 14 # This results in Python being spawned and printing the sys.argv list.
14 # We can then eval() the result of this, and see what each argv was. 15 # We can then eval() the result of this, and see what each argv was.
15 python = sys.executable 16 python = sys.executable
16 if ' ' in python: 17 if ' ' in python:
17 python = '"' + python + '"' # quote embedded space for cmdline 18 python = '"' + python + '"' # quote embedded space for cmdline
18 19
20 @unittest.skipUnless(hasattr(subprocess, 'Popen'), "test requires subprocess.Pop en()")
19 class PopenTest(unittest.TestCase): 21 class PopenTest(unittest.TestCase):
20 22
21 def _do_test_commandline(self, cmdline, expected): 23 def _do_test_commandline(self, cmdline, expected):
22 cmd = '%s -c "import sys; print(sys.argv)" %s' 24 cmd = '%s -c "import sys; print(sys.argv)" %s'
23 cmd = cmd % (python, cmdline) 25 cmd = cmd % (python, cmdline)
24 with os.popen(cmd) as p: 26 with os.popen(cmd) as p:
25 data = p.read() 27 data = p.read()
26 got = eval(data)[1:] # strip off argv[0] 28 got = eval(data)[1:] # strip off argv[0]
27 self.assertEqual(got, expected) 29 self.assertEqual(got, expected)
28 30
(...skipping 27 matching lines...) Expand all
56 def test_iterating(self): 58 def test_iterating(self):
57 with os.popen("echo hello") as f: 59 with os.popen("echo hello") as f:
58 self.assertEqual(list(f), ["hello\n"]) 60 self.assertEqual(list(f), ["hello\n"])
59 61
60 def test_keywords(self): 62 def test_keywords(self):
61 with os.popen(cmd="exit 0", mode="w", buffering=-1): 63 with os.popen(cmd="exit 0", mode="w", buffering=-1):
62 pass 64 pass
63 65
64 if __name__ == "__main__": 66 if __name__ == "__main__":
65 unittest.main() 67 unittest.main()
OLDNEW
« no previous file with comments | « Lib/test/test_poll.py ('k') | Lib/test/test_posix.py » ('j') | no next file with comments »

RSS Feeds Recent Issues | This issue
This is Rietveld 894c83f36cb7+