Mercurial > cpython-lru_cache-weakref
annotate Lib/test/test_commands.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 | 228cfb6e2900 |
| children | 6768b2350c57 |
| rev | line source |
|---|---|
|
18800
4a431952676b
Tests for the "commands" module, contributed by Nick Mathewson.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
1 ''' |
|
4a431952676b
Tests for the "commands" module, contributed by Nick Mathewson.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
2 Tests for commands module |
|
4a431952676b
Tests for the "commands" module, contributed by Nick Mathewson.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
3 Nick Mathewson |
|
4a431952676b
Tests for the "commands" module, contributed by Nick Mathewson.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
4 ''' |
|
4a431952676b
Tests for the "commands" module, contributed by Nick Mathewson.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
5 import unittest |
|
4a431952676b
Tests for the "commands" module, contributed by Nick Mathewson.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
6 import os, tempfile, re |
|
41241
6018194afbbd
Get rid of deprecation warning when testing commands.getstatus()
Neal Norwitz <nnorwitz@gmail.com>
parents:
38961
diff
changeset
|
7 import warnings |
|
6018194afbbd
Get rid of deprecation warning when testing commands.getstatus()
Neal Norwitz <nnorwitz@gmail.com>
parents:
38961
diff
changeset
|
8 |
|
6018194afbbd
Get rid of deprecation warning when testing commands.getstatus()
Neal Norwitz <nnorwitz@gmail.com>
parents:
38961
diff
changeset
|
9 warnings.filterwarnings('ignore', r".*commands.getstatus.. is deprecated", |
|
6018194afbbd
Get rid of deprecation warning when testing commands.getstatus()
Neal Norwitz <nnorwitz@gmail.com>
parents:
38961
diff
changeset
|
10 DeprecationWarning) |
|
18800
4a431952676b
Tests for the "commands" module, contributed by Nick Mathewson.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
11 |
|
52355
228cfb6e2900
fix incorrect auto-translation of TestSkipped -> unittest.SkipTest
Benjamin Peterson <benjamin@python.org>
parents:
52353
diff
changeset
|
12 from test.test_support import run_unittest, reap_children |
|
18800
4a431952676b
Tests for the "commands" module, contributed by Nick Mathewson.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
13 from commands import * |
|
4a431952676b
Tests for the "commands" module, contributed by Nick Mathewson.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
14 |
|
4a431952676b
Tests for the "commands" module, contributed by Nick Mathewson.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
15 # The module says: |
|
4a431952676b
Tests for the "commands" module, contributed by Nick Mathewson.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
16 # "NB This only works (and is only relevant) for UNIX." |
|
4a431952676b
Tests for the "commands" module, contributed by Nick Mathewson.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
17 # |
|
4a431952676b
Tests for the "commands" module, contributed by Nick Mathewson.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
18 # Actually, getoutput should work on any platform with an os.popen, but |
|
4a431952676b
Tests for the "commands" module, contributed by Nick Mathewson.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
19 # I'll take the comment as given, and skip this suite. |
|
4a431952676b
Tests for the "commands" module, contributed by Nick Mathewson.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
20 |
|
4a431952676b
Tests for the "commands" module, contributed by Nick Mathewson.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
21 if os.name != 'posix': |
|
52355
228cfb6e2900
fix incorrect auto-translation of TestSkipped -> unittest.SkipTest
Benjamin Peterson <benjamin@python.org>
parents:
52353
diff
changeset
|
22 raise unittest.SkipTest('Not posix; skipping test_commands') |
|
18800
4a431952676b
Tests for the "commands" module, contributed by Nick Mathewson.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
23 |
|
4a431952676b
Tests for the "commands" module, contributed by Nick Mathewson.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
24 |
|
4a431952676b
Tests for the "commands" module, contributed by Nick Mathewson.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
25 class CommandTests(unittest.TestCase): |
|
4a431952676b
Tests for the "commands" module, contributed by Nick Mathewson.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
26 |
|
4a431952676b
Tests for the "commands" module, contributed by Nick Mathewson.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
27 def test_getoutput(self): |
|
4a431952676b
Tests for the "commands" module, contributed by Nick Mathewson.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
28 self.assertEquals(getoutput('echo xyzzy'), 'xyzzy') |
|
4a431952676b
Tests for the "commands" module, contributed by Nick Mathewson.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
29 self.assertEquals(getstatusoutput('echo xyzzy'), (0, 'xyzzy')) |
|
4a431952676b
Tests for the "commands" module, contributed by Nick Mathewson.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
30 |
|
24710
11c701038805
Massive changes from SF 589982 (tempfile.py rewrite, by Zack
Guido van Rossum <guido@python.org>
parents:
24364
diff
changeset
|
31 # we use mkdtemp in the next line to create an empty directory |
|
11c701038805
Massive changes from SF 589982 (tempfile.py rewrite, by Zack
Guido van Rossum <guido@python.org>
parents:
24364
diff
changeset
|
32 # under our exclusive control; from that, we can invent a pathname |
|
11c701038805
Massive changes from SF 589982 (tempfile.py rewrite, by Zack
Guido van Rossum <guido@python.org>
parents:
24364
diff
changeset
|
33 # that we _know_ won't exist. This is guaranteed to fail. |
|
28405
b09db0b96a76
CommandTests.testgetoutput():
Thomas Wouters <thomas@python.org>
parents:
26540
diff
changeset
|
34 dir = None |
|
24710
11c701038805
Massive changes from SF 589982 (tempfile.py rewrite, by Zack
Guido van Rossum <guido@python.org>
parents:
24364
diff
changeset
|
35 try: |
|
11c701038805
Massive changes from SF 589982 (tempfile.py rewrite, by Zack
Guido van Rossum <guido@python.org>
parents:
24364
diff
changeset
|
36 dir = tempfile.mkdtemp() |
|
11c701038805
Massive changes from SF 589982 (tempfile.py rewrite, by Zack
Guido van Rossum <guido@python.org>
parents:
24364
diff
changeset
|
37 name = os.path.join(dir, "foo") |
|
11c701038805
Massive changes from SF 589982 (tempfile.py rewrite, by Zack
Guido van Rossum <guido@python.org>
parents:
24364
diff
changeset
|
38 |
|
11c701038805
Massive changes from SF 589982 (tempfile.py rewrite, by Zack
Guido van Rossum <guido@python.org>
parents:
24364
diff
changeset
|
39 status, output = getstatusoutput('cat ' + name) |
|
11c701038805
Massive changes from SF 589982 (tempfile.py rewrite, by Zack
Guido van Rossum <guido@python.org>
parents:
24364
diff
changeset
|
40 self.assertNotEquals(status, 0) |
|
11c701038805
Massive changes from SF 589982 (tempfile.py rewrite, by Zack
Guido van Rossum <guido@python.org>
parents:
24364
diff
changeset
|
41 finally: |
|
28405
b09db0b96a76
CommandTests.testgetoutput():
Thomas Wouters <thomas@python.org>
parents:
26540
diff
changeset
|
42 if dir is not None: |
|
b09db0b96a76
CommandTests.testgetoutput():
Thomas Wouters <thomas@python.org>
parents:
26540
diff
changeset
|
43 os.rmdir(dir) |
|
18800
4a431952676b
Tests for the "commands" module, contributed by Nick Mathewson.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
44 |
|
4a431952676b
Tests for the "commands" module, contributed by Nick Mathewson.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
45 def test_getstatus(self): |
|
22844
216dad7209bc
backport fdrake's checkin of
Michael W. Hudson <mwh@python.net>
parents:
20761
diff
changeset
|
46 # This pattern should match 'ls -ld /.' on any posix |
|
25493
4e05aab60bdf
Patch #544740: test_commands test fails under Cygwin
Jason Tishler <jason@tishler.net>
parents:
24710
diff
changeset
|
47 # system, however perversely configured. Even on systems |
|
4e05aab60bdf
Patch #544740: test_commands test fails under Cygwin
Jason Tishler <jason@tishler.net>
parents:
24710
diff
changeset
|
48 # (e.g., Cygwin) where user and group names can have spaces: |
|
4e05aab60bdf
Patch #544740: test_commands test fails under Cygwin
Jason Tishler <jason@tishler.net>
parents:
24710
diff
changeset
|
49 # drwxr-xr-x 15 Administ Domain U 4096 Aug 12 12:50 / |
|
4e05aab60bdf
Patch #544740: test_commands test fails under Cygwin
Jason Tishler <jason@tishler.net>
parents:
24710
diff
changeset
|
50 # drwxr-xr-x 15 Joe User My Group 4096 Aug 12 12:50 / |
|
4e05aab60bdf
Patch #544740: test_commands test fails under Cygwin
Jason Tishler <jason@tishler.net>
parents:
24710
diff
changeset
|
51 # Note that the first case above has a space in the group name |
|
4e05aab60bdf
Patch #544740: test_commands test fails under Cygwin
Jason Tishler <jason@tishler.net>
parents:
24710
diff
changeset
|
52 # while the second one has a space in both names. |
|
22844
216dad7209bc
backport fdrake's checkin of
Michael W. Hudson <mwh@python.net>
parents:
20761
diff
changeset
|
53 pat = r'''d......... # It is a directory. |
|
26540
910fb66c3b81
Patch #648998: test_commands ACL patch
Jason Tishler <jason@tishler.net>
parents:
25493
diff
changeset
|
54 \+? # It may have ACLs. |
|
18800
4a431952676b
Tests for the "commands" module, contributed by Nick Mathewson.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
55 \s+\d+ # It has some number of links. |
|
25493
4e05aab60bdf
Patch #544740: test_commands test fails under Cygwin
Jason Tishler <jason@tishler.net>
parents:
24710
diff
changeset
|
56 [^/]* # Skip user, group, size, and date. |
|
23698
7718b274ad8b
Patch #551911: Escape . properly.
Martin v. Löwis <martin@v.loewis.de>
parents:
22844
diff
changeset
|
57 /\. # and end with the name of the file. |
|
18800
4a431952676b
Tests for the "commands" module, contributed by Nick Mathewson.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
58 ''' |
|
4a431952676b
Tests for the "commands" module, contributed by Nick Mathewson.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
59 |
|
22844
216dad7209bc
backport fdrake's checkin of
Michael W. Hudson <mwh@python.net>
parents:
20761
diff
changeset
|
60 self.assert_(re.match(pat, getstatus("/."), re.VERBOSE)) |
|
18800
4a431952676b
Tests for the "commands" module, contributed by Nick Mathewson.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
61 |
|
20013
e3184e46303b
Change the PyUnit-based tests to use the test_main() approach. This
Fred Drake <fdrake@acm.org>
parents:
18800
diff
changeset
|
62 |
|
e3184e46303b
Change the PyUnit-based tests to use the test_main() approach. This
Fred Drake <fdrake@acm.org>
parents:
18800
diff
changeset
|
63 def test_main(): |
|
e3184e46303b
Change the PyUnit-based tests to use the test_main() approach. This
Fred Drake <fdrake@acm.org>
parents:
18800
diff
changeset
|
64 run_unittest(CommandTests) |
|
38961
0a83dc3529d1
Add new utility function, reap_children(), to test_support. This should
Neal Norwitz <nnorwitz@gmail.com>
parents:
28405
diff
changeset
|
65 reap_children() |
|
20013
e3184e46303b
Change the PyUnit-based tests to use the test_main() approach. This
Fred Drake <fdrake@acm.org>
parents:
18800
diff
changeset
|
66 |
|
e3184e46303b
Change the PyUnit-based tests to use the test_main() approach. This
Fred Drake <fdrake@acm.org>
parents:
18800
diff
changeset
|
67 |
|
e3184e46303b
Change the PyUnit-based tests to use the test_main() approach. This
Fred Drake <fdrake@acm.org>
parents:
18800
diff
changeset
|
68 if __name__ == "__main__": |
|
e3184e46303b
Change the PyUnit-based tests to use the test_main() approach. This
Fred Drake <fdrake@acm.org>
parents:
18800
diff
changeset
|
69 test_main() |
