summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_commands.py
diff options
context:
space:
mode:
authorFred Drake <fdrake@acm.org>2001-07-23 04:08:01 (GMT)
committerFred Drake <fdrake@acm.org>2001-07-23 04:08:01 (GMT)
commit4c81d60fcb15661450a3aab72de26d72e32fd4f0 (patch)
treec3654aa56635191d257b758fd543d207d0f8158b /Lib/test/test_commands.py
parent1586136193112c3b7571efb37974e2bad4bd0a57 (diff)
downloadcpython-4c81d60fcb15661450a3aab72de26d72e32fd4f0.zip
cpython-4c81d60fcb15661450a3aab72de26d72e32fd4f0.tar.gz
cpython-4c81d60fcb15661450a3aab72de26d72e32fd4f0.tar.bz2
Tests for the "commands" module, contributed by Nick Mathewson.
This closes SF patch #440291.
Diffstat (limited to 'Lib/test/test_commands.py')
-rw-r--r--Lib/test/test_commands.py45
1 files changed, 45 insertions, 0 deletions
diff --git a/Lib/test/test_commands.py b/Lib/test/test_commands.py
new file mode 100644
index 0000000..54ae676
--- /dev/null
+++ b/Lib/test/test_commands.py
@@ -0,0 +1,45 @@
+'''
+ Tests for commands module
+ Nick Mathewson
+'''
+import unittest
+import os, tempfile, re
+
+from test_support import TestSkipped, run_unittest
+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 mktemp in the next line to get a filename which we
+ # _know_ won't exist. This is guaranteed to fail.
+ status, output = getstatusoutput('cat ' + tempfile.mktemp())
+ self.assertNotEquals(status, 0)
+
+ def test_getstatus(self):
+ # This pattern should match 'ls -ld /bin/ls' on any posix
+ # system, however perversely configured.
+ pat = r'''-..x..x..x # It is executable.
+ \s+\d+ # It has some number of links.
+ \s+\w+\s+\w+ # It has a user and group, which may
+ # be named anything.
+ [^/]* # Skip the date.
+ /bin/ls # and end with the name of the file.
+ '''
+
+ self.assert_(re.match(pat, getstatus("/bin/ls"), re.VERBOSE))
+
+run_unittest(CommandTests)