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

Unified Diff: Lib/test/test_commands.py

Issue 5178: Add context manager for temporary directory
Patch Set: Created 8 years, 11 months ago
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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « Lib/test/test_bsddb3.py ('k') | Lib/test/test_shelve.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Lib/test/test_commands.py
===================================================================
--- Lib/test/test_commands.py (revision 69412)
+++ Lib/test/test_commands.py (working copy)
@@ -28,19 +28,13 @@
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")
-
+ # we make 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.
+ with tempfile.TemporaryDirectory() as tmpdir:
+ name = os.path.join(tmpdir, "foo")
status, output = getstatusoutput('cat ' + name)
self.assertNotEquals(status, 0)
- finally:
- if dir is not None:
- os.rmdir(dir)
def test_getstatus(self):
# This pattern should match 'ls -ld /.' on any posix
« no previous file with comments | « Lib/test/test_bsddb3.py ('k') | Lib/test/test_shelve.py » ('j') | no next file with comments »

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