Mercurial > cpython-lru_cache-weakref
annotate Lib/test/test_commands.py @ 79675:c0a2294de787 2.7
Issue #16199: Backport 2to3 typo fix from 3.2.
| author | Chris Jerdonek <chris.jerdonek@gmail.com> |
|---|---|
| date | Thu, 11 Oct 2012 16:15:46 -0700 |
| parents | 5616cbce0bee |
| children |
| 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 |
|
60116
3748bca4d869
Replace catch_warnings with check_warnings when it makes sense. Use assertRaises context manager to simplify some tests.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
58817
diff
changeset
|
8 from test.test_support import run_unittest, reap_children, import_module, \ |
|
3748bca4d869
Replace catch_warnings with check_warnings when it makes sense. Use assertRaises context manager to simplify some tests.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
58817
diff
changeset
|
9 check_warnings |
|
18800
4a431952676b
Tests for the "commands" module, contributed by Nick Mathewson.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
10 |
|
63531
30086aa33123
Merged revisions 77841 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
41241
diff
changeset
|
11 # Silence Py3k warning |
|
58817
70e115c34f97
Remove unused imports in test modules.
Georg Brandl <georg@python.org>
parents:
58580
diff
changeset
|
12 commands = import_module('commands', deprecated=True) |
|
18800
4a431952676b
Tests for the "commands" module, contributed by Nick Mathewson.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
13 |
|
4a431952676b
Tests for the "commands" module, contributed by Nick Mathewson.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
14 # The module says: |
|
4a431952676b
Tests for the "commands" module, contributed by Nick Mathewson.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
15 # "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
|
16 # |
|
4a431952676b
Tests for the "commands" module, contributed by Nick Mathewson.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
17 # 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
|
18 # 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
|
19 |
|
4a431952676b
Tests for the "commands" module, contributed by Nick Mathewson.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
20 if os.name != 'posix': |
|
52355
228cfb6e2900
fix incorrect auto-translation of TestSkipped -> unittest.SkipTest
Benjamin Peterson <benjamin@python.org>
parents:
52353
diff
changeset
|
21 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
|
22 |
|
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 class CommandTests(unittest.TestCase): |
|
4a431952676b
Tests for the "commands" module, contributed by Nick Mathewson.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
25 |
|
4a431952676b
Tests for the "commands" module, contributed by Nick Mathewson.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
26 def test_getoutput(self): |
|
66348
614c84670c63
Merged revisions 86596 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
60116
diff
changeset
|
27 self.assertEqual(commands.getoutput('echo xyzzy'), 'xyzzy') |
|
614c84670c63
Merged revisions 86596 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
60116
diff
changeset
|
28 self.assertEqual(commands.getstatusoutput('echo xyzzy'), (0, 'xyzzy')) |
|
18800
4a431952676b
Tests for the "commands" module, contributed by Nick Mathewson.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
29 |
|
24710
11c701038805
Massive changes from SF 589982 (tempfile.py rewrite, by Zack
Guido van Rossum <guido@python.org>
parents:
24364
diff
changeset
|
30 # 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
|
31 # 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
|
32 # that we _know_ won't exist. This is guaranteed to fail. |
|
28405
b09db0b96a76
CommandTests.testgetoutput():
Thomas Wouters <thomas@python.org>
parents:
26540
diff
changeset
|
33 dir = None |
|
24710
11c701038805
Massive changes from SF 589982 (tempfile.py rewrite, by Zack
Guido van Rossum <guido@python.org>
parents:
24364
diff
changeset
|
34 try: |
|
11c701038805
Massive changes from SF 589982 (tempfile.py rewrite, by Zack
Guido van Rossum <guido@python.org>
parents:
24364
diff
changeset
|
35 dir = tempfile.mkdtemp() |
|
11c701038805
Massive changes from SF 589982 (tempfile.py rewrite, by Zack
Guido van Rossum <guido@python.org>
parents:
24364
diff
changeset
|
36 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
|
37 |
|
58817
70e115c34f97
Remove unused imports in test modules.
Georg Brandl <georg@python.org>
parents:
58580
diff
changeset
|
38 status, output = commands.getstatusoutput('cat ' + name) |
|
66348
614c84670c63
Merged revisions 86596 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
60116
diff
changeset
|
39 self.assertNotEqual(status, 0) |
|
24710
11c701038805
Massive changes from SF 589982 (tempfile.py rewrite, by Zack
Guido van Rossum <guido@python.org>
parents:
24364
diff
changeset
|
40 finally: |
|
28405
b09db0b96a76
CommandTests.testgetoutput():
Thomas Wouters <thomas@python.org>
parents:
26540
diff
changeset
|
41 if dir is not None: |
|
b09db0b96a76
CommandTests.testgetoutput():
Thomas Wouters <thomas@python.org>
parents:
26540
diff
changeset
|
42 os.rmdir(dir) |
|
18800
4a431952676b
Tests for the "commands" module, contributed by Nick Mathewson.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
43 |
|
4a431952676b
Tests for the "commands" module, contributed by Nick Mathewson.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
44 def test_getstatus(self): |
|
22844
216dad7209bc
backport fdrake's checkin of
Michael W. Hudson <mwh@python.net>
parents:
20761
diff
changeset
|
45 # 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
|
46 # 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
|
47 # (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
|
48 # 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
|
49 # 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
|
50 # 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
|
51 # while the second one has a space in both names. |
|
69162
5616cbce0bee
Issue #7108: Fix test_commands to not fail when special attributes ('@'
Ned Deily <nad@acm.org>
parents:
68256
diff
changeset
|
52 # Special attributes supported: |
|
5616cbce0bee
Issue #7108: Fix test_commands to not fail when special attributes ('@'
Ned Deily <nad@acm.org>
parents:
68256
diff
changeset
|
53 # + = has ACLs |
|
5616cbce0bee
Issue #7108: Fix test_commands to not fail when special attributes ('@'
Ned Deily <nad@acm.org>
parents:
68256
diff
changeset
|
54 # @ = has Mac OS X extended attributes |
|
5616cbce0bee
Issue #7108: Fix test_commands to not fail when special attributes ('@'
Ned Deily <nad@acm.org>
parents:
68256
diff
changeset
|
55 # . = has a SELinux security context |
|
22844
216dad7209bc
backport fdrake's checkin of
Michael W. Hudson <mwh@python.net>
parents:
20761
diff
changeset
|
56 pat = r'''d......... # It is a directory. |
|
69162
5616cbce0bee
Issue #7108: Fix test_commands to not fail when special attributes ('@'
Ned Deily <nad@acm.org>
parents:
68256
diff
changeset
|
57 [.+@]? # It may have special attributes. |
|
18800
4a431952676b
Tests for the "commands" module, contributed by Nick Mathewson.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
58 \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
|
59 [^/]* # Skip user, group, size, and date. |
|
23698
7718b274ad8b
Patch #551911: Escape . properly.
Martin v. Löwis <martin@v.loewis.de>
parents:
22844
diff
changeset
|
60 /\. # 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
|
61 ''' |
|
4a431952676b
Tests for the "commands" module, contributed by Nick Mathewson.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
62 |
|
60116
3748bca4d869
Replace catch_warnings with check_warnings when it makes sense. Use assertRaises context manager to simplify some tests.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
58817
diff
changeset
|
63 with check_warnings((".*commands.getstatus.. is deprecated", |
|
3748bca4d869
Replace catch_warnings with check_warnings when it makes sense. Use assertRaises context manager to simplify some tests.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
58817
diff
changeset
|
64 DeprecationWarning)): |
|
3748bca4d869
Replace catch_warnings with check_warnings when it makes sense. Use assertRaises context manager to simplify some tests.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
58817
diff
changeset
|
65 self.assertTrue(re.match(pat, commands.getstatus("/."), re.VERBOSE)) |
|
18800
4a431952676b
Tests for the "commands" module, contributed by Nick Mathewson.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
66 |
|
20013
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 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
|
69 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
|
70 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
|
71 |
|
e3184e46303b
Change the PyUnit-based tests to use the test_main() approach. This
Fred Drake <fdrake@acm.org>
parents:
18800
diff
changeset
|
72 |
|
e3184e46303b
Change the PyUnit-based tests to use the test_main() approach. This
Fred Drake <fdrake@acm.org>
parents:
18800
diff
changeset
|
73 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
|
74 test_main() |
