Permalink
Browse files

Merge pull request #14 with edits

  • Loading branch information...
2 parents fc2862a + eb41a7e commit 16c6f127988e70e855a96bea56f786dc1776be43 @jaraco committed Jan 16, 2013
Showing with 20 additions and 1 deletion.
  1. +8 −1 path.py
  2. +12 −0 test_path.py
View
@@ -1141,7 +1141,14 @@ def startfile(self):
class tempdir(path):
"""
A temporary directory via tempfile.mkdtemp, and constructed with the
- same parameters.
+ same parameters that you can use as a context manager.
+
+ Example:
+
+ with tempdir() as d:
+ # do stuff with the path object "d"
+
+ # here the directory is deleted automatically
"""
def _next_class(cls):
View
@@ -648,6 +648,7 @@ def test_subclass_produces_same_class(self):
assert isinstance(subdir, self.PathSubclass)
class TempDirTestCase(unittest.TestCase):
+
def test_constructor(self):
"""
One should be able to readily construct a temporary directory
@@ -693,5 +694,16 @@ def test_context_manager_exception(self):
d.__exit__(TypeError, TypeError('foo'), None)
assert d.exists()
+ def test_context_manager_using_with(self):
+ """
+ The context manager will allow using the with keyword and
+ provide a temporry directory that will be deleted after that.
+ """
+
+ with tempdir() as d:
+ self.assertTrue(d.isdir())
+ self.assertFalse(d.isdir())
+
+
if __name__ == '__main__':
unittest.main()

0 comments on commit 16c6f12

Please sign in to comment.