The commands module has been removed. The getoutput() and getstatusoutput()

functions have been added to the subprocess module.

The fixer for this still needs to be written and proper Py3K deprecation
warnings for the functions that didn't make the transition need to be done in
2.6.

This is all part of trying to close issue #2872.
This commit is contained in:
Brett Cannon 2008-05-26 19:04:21 +00:00
parent 35af8d4218
commit a23810f86a
13 changed files with 140 additions and 196 deletions

View file

@ -868,7 +868,6 @@ _expectations = {
"""
test__locale
test_bsddb3
test_commands
test_crypt
test_curses
test_dbm
@ -910,7 +909,6 @@ _expectations = {
test_bsddb
test_bsddb3
test_bz2
test_commands
test_crypt
test_curses
test_dbm
@ -1060,7 +1058,6 @@ _expectations = {
"""
test_audioop
test_bsddb3
test_commands
test_curses
test_dl
test_epoll

View file

@ -50,7 +50,6 @@ class AllTest(unittest.TestCase):
self.check_all("codecs")
self.check_all("codeop")
self.check_all("colorsys")
self.check_all("commands")
self.check_all("compileall")
self.check_all("copy")
self.check_all("copyreg")

View file

@ -1,47 +0,0 @@
'''
Tests for commands module
Nick Mathewson
'''
import unittest
import os, tempfile, re
from test.support import TestSkipped, run_unittest, reap_children
from commands import *
# The module says:
# "NB This only works (and is only relevant) for UNIX."
#
# Actually, getoutput should work on any platform with an os.popen, but
# I'll take the comment as given, and skip this suite.
if os.name != 'posix':
raise TestSkipped('Not posix; skipping test_commands')
class CommandTests(unittest.TestCase):
def test_getoutput(self):
self.assertEquals(getoutput('echo xyzzy'), 'xyzzy')
self.assertEquals(getstatusoutput('echo xyzzy'), (0, 'xyzzy'))
# we use mkdtemp in the next line to create an empty directory
# under our exclusive control; from that, we can invent a pathname
# that we _know_ won't exist. This is guaranteed to fail.
dir = None
try:
dir = tempfile.mkdtemp()
name = os.path.join(dir, "foo")
status, output = getstatusoutput('cat ' + name)
self.assertNotEquals(status, 0)
finally:
if dir is not None:
os.rmdir(dir)
def test_main():
run_unittest(CommandTests)
reap_children()
if __name__ == "__main__":
test_main()

View file

@ -702,10 +702,36 @@ class ProcessTestCase(unittest.TestCase):
p.terminate()
self.assertNotEqual(p.wait(), 0)
class CommandTests(unittest.TestCase):
# The module says:
# "NB This only works (and is only relevant) for UNIX."
#
# Actually, getoutput should work on any platform with an os.popen, but
# I'll take the comment as given, and skip this suite.
if os.name == 'posix':
def test_getoutput(self):
self.assertEquals(subprocess.getoutput('echo xyzzy'), 'xyzzy')
self.assertEquals(subprocess.getstatusoutput('echo xyzzy'),
(0, 'xyzzy'))
# we use mkdtemp in the next line to create an empty directory
# under our exclusive control; from that, we can invent a pathname
# that we _know_ won't exist. This is guaranteed to fail.
dir = None
try:
dir = tempfile.mkdtemp()
name = os.path.join(dir, "foo")
status, output = subprocess.getstatusoutput('cat ' + name)
self.assertNotEquals(status, 0)
finally:
if dir is not None:
os.rmdir(dir)
def test_main():
support.run_unittest(ProcessTestCase)
if hasattr(support, "reap_children"):
support.reap_children()
support.run_unittest(ProcessTestCase, CommandTests)
support.reap_children()
if __name__ == "__main__":
unittest.main() # XXX test_main()
test_main()